initial commit
This commit is contained in:
commit
4b60ece582
327 changed files with 28286 additions and 0 deletions
12
lorgar/CMakeLists.txt
Normal file
12
lorgar/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
project(lorgar)
|
||||
|
||||
add_subdirectory(css)
|
||||
add_subdirectory(lib)
|
||||
add_subdirectory(test)
|
||||
add_subdirectory(core)
|
||||
add_subdirectory(views)
|
||||
|
||||
configure_file(index.html index.html)
|
||||
configure_file(favicon.ico favicon.ico COPYONLY)
|
||||
configure_file(main.js main.js)
|
3
lorgar/core/CMakeLists.txt
Normal file
3
lorgar/core/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(lorgar.js lorgar.js)
|
289
lorgar/core/lorgar.js
Normal file
289
lorgar/core/lorgar.js
Normal file
|
@ -0,0 +1,289 @@
|
|||
"use strict";
|
||||
(function lorgar_js() {
|
||||
var moduleName = "core/lorgar";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("lib/utils/class");
|
||||
defineArray.push("lib/wSocket/socket");
|
||||
defineArray.push("lib/wDispatcher/dispatcher");
|
||||
defineArray.push("lib/wDispatcher/handler");
|
||||
defineArray.push("lib/wDispatcher/logger");
|
||||
|
||||
defineArray.push("lib/wType/event");
|
||||
defineArray.push("lib/wType/address");
|
||||
defineArray.push("lib/wType/vocabulary");
|
||||
defineArray.push("lib/wType/string");
|
||||
|
||||
defineArray.push("lib/wController/globalControls");
|
||||
defineArray.push("lib/wController/pageStorage");
|
||||
defineArray.push("lib/wController/page");
|
||||
defineArray.push("lib/wController/localModel");
|
||||
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("views/layout");
|
||||
defineArray.push("views/gridLayout");
|
||||
defineArray.push("views/page");
|
||||
defineArray.push("views/mainLayout");
|
||||
|
||||
define(moduleName, defineArray, function lorgar_module() {
|
||||
var Class = require("lib/utils/class");
|
||||
var Socket = require("lib/wSocket/socket");
|
||||
var Dispatcher = require("lib/wDispatcher/dispatcher");
|
||||
var Handler = require("lib/wDispatcher/handler");
|
||||
var Logger = require("lib/wDispatcher/logger");
|
||||
|
||||
var Event = require("lib/wType/event");
|
||||
var Address = require("lib/wType/address");
|
||||
var Vocabulary = require("lib/wType/vocabulary");
|
||||
var String = require("lib/wType/string");
|
||||
|
||||
var GlobalControls = require("lib/wController/globalControls");
|
||||
var PageStorage = require("lib/wController/pageStorage");
|
||||
var PageController = require("lib/wController/page");
|
||||
var LocalModel = require("lib/wController/localModel");
|
||||
|
||||
var View = require("views/view");
|
||||
var Layout = require("views/layout");
|
||||
var GridLayout = require("views/gridLayout");
|
||||
var Page = require("views/page");
|
||||
var MainLayout = require("views/mainLayout");
|
||||
|
||||
var Lorgar = Class.inherit({
|
||||
"className": "Lorgar",
|
||||
"constructor": function() {
|
||||
Class.fn.constructor.call(this);
|
||||
|
||||
this._currentPageCtl = undefined;
|
||||
this._nodes = Object.create(null);
|
||||
|
||||
this._initDispatcher();
|
||||
|
||||
this._prepareNode("Magnus", "localhost", 8081);
|
||||
this._prepareNode("Corax", "localhost", 8080);
|
||||
|
||||
this._initModels();
|
||||
this._initViews();
|
||||
|
||||
this.connectNode("Magnus");
|
||||
this.connectNode("Corax");
|
||||
window.onpopstate = this._onHistoryPopState.bind(this)
|
||||
},
|
||||
"destructor": function() {
|
||||
window.onpopstate = undefined;
|
||||
if (this._currentPageCtl) {
|
||||
this._currentPage.destructor();
|
||||
this._currentPageCtl.destructor();
|
||||
}
|
||||
|
||||
this._gc.destructor();
|
||||
this._ps.destructor();
|
||||
this._mainColorHelper.destructor();
|
||||
this._emptyHelper.destructor();
|
||||
|
||||
this._body.destructor();
|
||||
|
||||
this.coraxSocket.close();
|
||||
this.dispatcher.unregisterDefaultHandler(this._logger);
|
||||
|
||||
this._logger.destructor();
|
||||
this.dispatcher.destructor();
|
||||
//this.magnusSocket.destructor();
|
||||
//this.coraxSocket.destructor();
|
||||
|
||||
Class.fn.destructor.call(this);
|
||||
},
|
||||
"changePage": function(addr) {
|
||||
if (this._currentPageCtl && this._currentPageCtl.getPairAddress()["=="](addr)) {
|
||||
return;
|
||||
}
|
||||
this._ps.getPageName(addr);
|
||||
this._initPageController(addr.clone());
|
||||
},
|
||||
"connectNode": function(name) {
|
||||
var node = this._nodes[name];
|
||||
if (node === undefined) {
|
||||
throw new Error("An attempt to connect not prepared node " + name);
|
||||
}
|
||||
|
||||
node.socket.open(node.address, node.port);
|
||||
},
|
||||
"_initCoraxSocket": function() {
|
||||
this.coraxSocket = new Socket("Lorgar");
|
||||
this.coraxSocket.on("connected", this._coraxSocketConnected, this);
|
||||
this.coraxSocket.on("disconnected", this._coraxSocketDisconnected, this);
|
||||
this.coraxSocket.on("error", this._coraxSocketError, this);
|
||||
this.coraxSocket.on("message", this.dispatcher.pass, this.dispatcher);
|
||||
},
|
||||
"_initDispatcher": function() {
|
||||
this.dispatcher = new Dispatcher();
|
||||
this._logger = new Logger();
|
||||
this.dispatcher.registerDefaultHandler(this._logger);
|
||||
},
|
||||
"_initModels": function() {
|
||||
this._gc = new GlobalControls(new Address(["magnus", "gc"]));
|
||||
this._ps = new PageStorage(new Address(["magnus", "ps"]));
|
||||
|
||||
this._mainColorHelper = new LocalModel({backgroundColor: "mainColor"});
|
||||
this._emptyHelper = new LocalModel();
|
||||
|
||||
this._gc.on("themeSelected", this.setTheme, this);
|
||||
|
||||
this._gc.register(this.dispatcher, this._nodes.Magnus.socket);
|
||||
this._ps.register(this.dispatcher, this._nodes.Magnus.socket);
|
||||
|
||||
this._ps.on("pageName", this._onPageName, this);
|
||||
},
|
||||
"_initPageController": function(addr) {
|
||||
if (this._currentPageCtl) {
|
||||
this._currentPage.destructor();
|
||||
this._currentPageCtl.destructor();
|
||||
}
|
||||
this._currentPageCtl = new PageController(addr);
|
||||
this._currentPageCtl.register(this.dispatcher, this._nodes.Magnus.socket);
|
||||
this._currentPage = new Page(this._currentPageCtl);
|
||||
this._currentPageCtl.subscribe();
|
||||
this._mainLayout.append(this._currentPage, 1, 1, 1, 1);
|
||||
},
|
||||
"_initViews": function() {
|
||||
this._body = new Layout(this._emptyHelper);
|
||||
this._mainLayout = new MainLayout(this._gc);
|
||||
|
||||
document.body.innerHTML = "";
|
||||
document.body.appendChild(this._body._e);
|
||||
window.addEventListener("resize",this._onWindowResize.bind(this) ,false);
|
||||
|
||||
this._body.setSize(document.body.offsetWidth, document.body.offsetHeight);
|
||||
this._body.append(this._mainLayout);
|
||||
var spacerL = new View(this._mainColorHelper, {
|
||||
maxWidth: 50
|
||||
});
|
||||
var spacerR = new View(this._mainColorHelper, {
|
||||
maxWidth: 50
|
||||
});
|
||||
this._mainLayout.append(spacerL, 1, 0, 1, 1);
|
||||
this._mainLayout.append(spacerR, 1, 2, 1, 1);
|
||||
},
|
||||
"_onHistoryPopState": function(e) {
|
||||
this._initPageController(new Address(e.state.address));
|
||||
},
|
||||
"_onPageName": function(name) {
|
||||
window.history.pushState({
|
||||
address: this._currentPageCtl.getPairAddress().toArray()
|
||||
}, "", name);
|
||||
},
|
||||
"_onSocketConnected": function(name) {
|
||||
console.log(name + " socket connected");
|
||||
var node = this._nodes[name];
|
||||
node.connected = true;
|
||||
|
||||
for (var id in node.foreigns) {
|
||||
if (node.foreigns[id].subscribed) {
|
||||
node.foreigns[id].controller.subscribe();
|
||||
}
|
||||
}
|
||||
|
||||
if (name === "Magnus") {
|
||||
this._gc.subscribe();
|
||||
|
||||
if (!this._currentPageCtl) {
|
||||
this._ps.getPageAddress(location.pathname);
|
||||
this._ps.one("pageAddress", this._initPageController, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
"_onSocketDisconnected": function(name) {
|
||||
console.log(name + " socket disconnected");
|
||||
var node = this._nodes[name];
|
||||
node.connected = false;
|
||||
|
||||
for (var id in node.foreigns) {
|
||||
if (node.foreigns[id].subscribed) {
|
||||
node.foreigns[id].controller._onSocketDisconnected;
|
||||
}
|
||||
}
|
||||
},
|
||||
"_onSocketError": function(name) {
|
||||
console.log(name + " socket error: ");
|
||||
console.log(e);
|
||||
},
|
||||
"_onWindowResize": function() {
|
||||
this._body.setSize(document.body.offsetWidth, document.body.offsetHeight);
|
||||
},
|
||||
"_prepareNode": function(name, address, port) {
|
||||
if (this._nodes[name]) {
|
||||
throw new Error("An attempt to prepeare node " + name + " for the second time");
|
||||
}
|
||||
var obj = Object.create(null);
|
||||
obj.name = name;
|
||||
obj.address = address;
|
||||
obj.port = port;
|
||||
obj.socket = new Socket("Lorgar");
|
||||
obj.connected = false;
|
||||
obj.foreigns = Object.create(null);
|
||||
|
||||
obj.socket.on("connected", this._onSocketConnected.bind(this, name));
|
||||
obj.socket.on("disconnected", this._onSocketDisconnected.bind(this, name));
|
||||
obj.socket.on("error", this._onSocketError.bind(this, name));
|
||||
obj.socket.on("message", this.dispatcher.pass, this.dispatcher);
|
||||
|
||||
this._nodes[name] = obj;
|
||||
},
|
||||
"registerForeignController": function(node, controller) {
|
||||
var node = this._nodes[node];
|
||||
if (node === undefined) {
|
||||
throw new Error("An attempt to register controller to an unknown node " + node);
|
||||
}
|
||||
|
||||
if (node.foreigns[controller.id] !== undefined) {
|
||||
throw new Error("An attempt to register a controller under node " + node + " for a second time");
|
||||
}
|
||||
var obj = Object.create(null);
|
||||
obj.controller = controller;
|
||||
obj.subscribed = false;
|
||||
node.foreigns[controller.id] = obj;
|
||||
controller.register(this.dispatcher, node.socket);
|
||||
},
|
||||
"setTheme": function(theme) {
|
||||
View.setTheme(theme);
|
||||
},
|
||||
"subscribeForeignController": function(node, controller) {
|
||||
var node = this._nodes[node];
|
||||
if (node === undefined) {
|
||||
throw new Error("An attempt to subscribe a controller to an unknown node " + node);
|
||||
}
|
||||
|
||||
if (node.foreigns[controller.id] === undefined) {
|
||||
throw new Error("An attempt to subscribe not registered controller to node " + node);
|
||||
}
|
||||
node.foreigns[controller.id].subscribed = true;
|
||||
controller.subscribe();
|
||||
},
|
||||
"unregisterForeignController": function(node, controller) {
|
||||
var node = this._nodes[node];
|
||||
if (node === undefined) {
|
||||
throw new Error("An attempt to unregister a controller from an unknown node " + node);
|
||||
}
|
||||
|
||||
if (node.foreigns[controller.id] === undefined) {
|
||||
throw new Error("An attempt to unregister not registered controller from node " + node);
|
||||
}
|
||||
delete node.foreigns[controller.id];
|
||||
controller.unregister();
|
||||
},
|
||||
"unsubscribeForeignController": function(node, controller) {
|
||||
var node = this._nodes[node];
|
||||
if (node === undefined) {
|
||||
throw new Error("An attempt to unsubscribe a controller from an unknown node " + node);
|
||||
}
|
||||
|
||||
if (node.foreigns[controller.id] === undefined) {
|
||||
throw new Error("An attempt to unsubscribe not registered controller from node " + node);
|
||||
}
|
||||
node.foreigns[controller.id].subscribed = false;
|
||||
controller.unsubscribe();
|
||||
}
|
||||
});
|
||||
|
||||
return Lorgar;
|
||||
});
|
||||
})();
|
4
lorgar/css/CMakeLists.txt
Normal file
4
lorgar/css/CMakeLists.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(main.css main.css)
|
||||
configure_file(Liberation.ttf Liberation.ttf COPYONLY)
|
BIN
lorgar/css/Liberation.ttf
Normal file
BIN
lorgar/css/Liberation.ttf
Normal file
Binary file not shown.
47
lorgar/css/main.css
Normal file
47
lorgar/css/main.css
Normal file
|
@ -0,0 +1,47 @@
|
|||
@font-face {
|
||||
font-family: Liberation;
|
||||
src: url(Liberation.ttf);
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.non-selectable,
|
||||
.non-selectable * {
|
||||
-webkit-user-select: none;
|
||||
-ms-user-select: none;
|
||||
-moz-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.hoverable {
|
||||
|
||||
}
|
||||
|
||||
.hoverable:hover {
|
||||
background-image: linear-gradient(to bottom, rgba(0, 0, 0, .2) 0%, rgba(0, 0, 0, .2) 100%);
|
||||
}
|
||||
|
||||
.draggable {
|
||||
cursor: -webkit-grab;
|
||||
cursor: -moz-grab;
|
||||
cursor: -grab;
|
||||
}
|
||||
|
||||
div.dragging ,
|
||||
div.dragging .draggable {
|
||||
cursor: -webkit-grabbing;
|
||||
cursor: -moz-grabbing;
|
||||
cursor: grabbing;
|
||||
}
|
BIN
lorgar/favicon.ico
Normal file
BIN
lorgar/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
13
lorgar/index.html
Normal file
13
lorgar/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>RadioW</title>
|
||||
|
||||
<link href="/css/main.css" rel="stylesheet"/>
|
||||
<script data-main="/main" src="/lib/requirejs/require.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>I am</p>
|
||||
</body>
|
||||
</html>
|
12
lorgar/lib/CMakeLists.txt
Normal file
12
lorgar/lib/CMakeLists.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_subdirectory(requirejs)
|
||||
add_subdirectory(wSocket)
|
||||
add_subdirectory(bintrees)
|
||||
add_subdirectory(wContainer)
|
||||
add_subdirectory(utils)
|
||||
add_subdirectory(wType)
|
||||
add_subdirectory(wDispatcher)
|
||||
add_subdirectory(wTest)
|
||||
add_subdirectory(wController)
|
||||
add_subdirectory(fonts)
|
3
lorgar/lib/bintrees/CMakeLists.txt
Normal file
3
lorgar/lib/bintrees/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(index.js index.js)
|
478
lorgar/lib/bintrees/index.js
Normal file
478
lorgar/lib/bintrees/index.js
Normal file
|
@ -0,0 +1,478 @@
|
|||
"use strict";
|
||||
(function rbtree_js() {
|
||||
|
||||
var moduleName = "lib/bintrees/index";
|
||||
|
||||
var defineArray = [];
|
||||
|
||||
define(moduleName, defineArray, function rbtree_module() {
|
||||
var require = function(name) {
|
||||
var fn = require.m[name];
|
||||
if (fn.mod) {
|
||||
return fn.mod.exports;
|
||||
}
|
||||
|
||||
var mod = fn.mod = { exports: {} };
|
||||
fn(mod, mod.exports);
|
||||
return mod.exports;
|
||||
};
|
||||
|
||||
require.m = {};
|
||||
require.m['./treebase'] = function(module, exports) {
|
||||
|
||||
function TreeBase() {}
|
||||
|
||||
// removes all nodes from the tree
|
||||
TreeBase.prototype.clear = function() {
|
||||
this._root = null;
|
||||
this.size = 0;
|
||||
};
|
||||
|
||||
// returns node data if found, null otherwise
|
||||
TreeBase.prototype.find = function(data) {
|
||||
var res = this._root;
|
||||
|
||||
while(res !== null) {
|
||||
var c = this._comparator(data, res.data);
|
||||
if(c === 0) {
|
||||
return res.data;
|
||||
}
|
||||
else {
|
||||
res = res.get_child(c > 0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
// returns iterator to node if found, null otherwise
|
||||
TreeBase.prototype.findIter = function(data) {
|
||||
var res = this._root;
|
||||
var iter = this.iterator();
|
||||
|
||||
while(res !== null) {
|
||||
var c = this._comparator(data, res.data);
|
||||
if(c === 0) {
|
||||
iter._cursor = res;
|
||||
return iter;
|
||||
}
|
||||
else {
|
||||
iter._ancestors.push(res);
|
||||
res = res.get_child(c > 0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
// Returns an iterator to the tree node at or immediately after the item
|
||||
TreeBase.prototype.lowerBound = function(item) {
|
||||
var cur = this._root;
|
||||
var iter = this.iterator();
|
||||
var cmp = this._comparator;
|
||||
|
||||
while(cur !== null) {
|
||||
var c = cmp(item, cur.data);
|
||||
if(c === 0) {
|
||||
iter._cursor = cur;
|
||||
return iter;
|
||||
}
|
||||
iter._ancestors.push(cur);
|
||||
cur = cur.get_child(c > 0);
|
||||
}
|
||||
|
||||
for(var i=iter._ancestors.length - 1; i >= 0; --i) {
|
||||
cur = iter._ancestors[i];
|
||||
if(cmp(item, cur.data) < 0) {
|
||||
iter._cursor = cur;
|
||||
iter._ancestors.length = i;
|
||||
return iter;
|
||||
}
|
||||
}
|
||||
|
||||
iter._ancestors.length = 0;
|
||||
return iter;
|
||||
};
|
||||
|
||||
// Returns an iterator to the tree node immediately after the item
|
||||
TreeBase.prototype.upperBound = function(item) {
|
||||
var iter = this.lowerBound(item);
|
||||
var cmp = this._comparator;
|
||||
|
||||
while(iter.data() !== null && cmp(iter.data(), item) === 0) {
|
||||
iter.next();
|
||||
}
|
||||
|
||||
return iter;
|
||||
};
|
||||
|
||||
// returns null if tree is empty
|
||||
TreeBase.prototype.min = function() {
|
||||
var res = this._root;
|
||||
if(res === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
while(res.left !== null) {
|
||||
res = res.left;
|
||||
}
|
||||
|
||||
return res.data;
|
||||
};
|
||||
|
||||
// returns null if tree is empty
|
||||
TreeBase.prototype.max = function() {
|
||||
var res = this._root;
|
||||
if(res === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
while(res.right !== null) {
|
||||
res = res.right;
|
||||
}
|
||||
|
||||
return res.data;
|
||||
};
|
||||
|
||||
// returns a null iterator
|
||||
// call next() or prev() to point to an element
|
||||
TreeBase.prototype.iterator = function() {
|
||||
return new Iterator(this);
|
||||
};
|
||||
|
||||
// calls cb on each node's data, in order
|
||||
TreeBase.prototype.each = function(cb) {
|
||||
var it=this.iterator(), data;
|
||||
while((data = it.next()) !== null) {
|
||||
cb(data);
|
||||
}
|
||||
};
|
||||
|
||||
// calls cb on each node's data, in reverse order
|
||||
TreeBase.prototype.reach = function(cb) {
|
||||
var it=this.iterator(), data;
|
||||
while((data = it.prev()) !== null) {
|
||||
cb(data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function Iterator(tree) {
|
||||
this._tree = tree;
|
||||
this._ancestors = [];
|
||||
this._cursor = null;
|
||||
}
|
||||
|
||||
Iterator.prototype.data = function() {
|
||||
return this._cursor !== null ? this._cursor.data : null;
|
||||
};
|
||||
|
||||
// if null-iterator, returns first node
|
||||
// otherwise, returns next node
|
||||
Iterator.prototype.next = function() {
|
||||
if(this._cursor === null) {
|
||||
var root = this._tree._root;
|
||||
if(root !== null) {
|
||||
this._minNode(root);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(this._cursor.right === null) {
|
||||
// no greater node in subtree, go up to parent
|
||||
// if coming from a right child, continue up the stack
|
||||
var save;
|
||||
do {
|
||||
save = this._cursor;
|
||||
if(this._ancestors.length) {
|
||||
this._cursor = this._ancestors.pop();
|
||||
}
|
||||
else {
|
||||
this._cursor = null;
|
||||
break;
|
||||
}
|
||||
} while(this._cursor.right === save);
|
||||
}
|
||||
else {
|
||||
// get the next node from the subtree
|
||||
this._ancestors.push(this._cursor);
|
||||
this._minNode(this._cursor.right);
|
||||
}
|
||||
}
|
||||
return this._cursor !== null ? this._cursor.data : null;
|
||||
};
|
||||
|
||||
// if null-iterator, returns last node
|
||||
// otherwise, returns previous node
|
||||
Iterator.prototype.prev = function() {
|
||||
if(this._cursor === null) {
|
||||
var root = this._tree._root;
|
||||
if(root !== null) {
|
||||
this._maxNode(root);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(this._cursor.left === null) {
|
||||
var save;
|
||||
do {
|
||||
save = this._cursor;
|
||||
if(this._ancestors.length) {
|
||||
this._cursor = this._ancestors.pop();
|
||||
}
|
||||
else {
|
||||
this._cursor = null;
|
||||
break;
|
||||
}
|
||||
} while(this._cursor.left === save);
|
||||
}
|
||||
else {
|
||||
this._ancestors.push(this._cursor);
|
||||
this._maxNode(this._cursor.left);
|
||||
}
|
||||
}
|
||||
return this._cursor !== null ? this._cursor.data : null;
|
||||
};
|
||||
|
||||
Iterator.prototype._minNode = function(start) {
|
||||
while(start.left !== null) {
|
||||
this._ancestors.push(start);
|
||||
start = start.left;
|
||||
}
|
||||
this._cursor = start;
|
||||
};
|
||||
|
||||
Iterator.prototype._maxNode = function(start) {
|
||||
while(start.right !== null) {
|
||||
this._ancestors.push(start);
|
||||
start = start.right;
|
||||
}
|
||||
this._cursor = start;
|
||||
};
|
||||
|
||||
module.exports = TreeBase;
|
||||
|
||||
};
|
||||
require.m['__main__'] = function(module, exports) {
|
||||
|
||||
var TreeBase = require('./treebase');
|
||||
|
||||
function Node(data) {
|
||||
this.data = data;
|
||||
this.left = null;
|
||||
this.right = null;
|
||||
this.red = true;
|
||||
}
|
||||
|
||||
Node.prototype.get_child = function(dir) {
|
||||
return dir ? this.right : this.left;
|
||||
};
|
||||
|
||||
Node.prototype.set_child = function(dir, val) {
|
||||
if(dir) {
|
||||
this.right = val;
|
||||
}
|
||||
else {
|
||||
this.left = val;
|
||||
}
|
||||
};
|
||||
|
||||
function RBTree(comparator) {
|
||||
this._root = null;
|
||||
this._comparator = comparator;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
RBTree.prototype = new TreeBase();
|
||||
|
||||
// returns true if inserted, false if duplicate
|
||||
RBTree.prototype.insert = function(data) {
|
||||
var ret = false;
|
||||
|
||||
if(this._root === null) {
|
||||
// empty tree
|
||||
this._root = new Node(data);
|
||||
ret = true;
|
||||
this.size++;
|
||||
}
|
||||
else {
|
||||
var head = new Node(undefined); // fake tree root
|
||||
|
||||
var dir = 0;
|
||||
var last = 0;
|
||||
|
||||
// setup
|
||||
var gp = null; // grandparent
|
||||
var ggp = head; // grand-grand-parent
|
||||
var p = null; // parent
|
||||
var node = this._root;
|
||||
ggp.right = this._root;
|
||||
|
||||
// search down
|
||||
while(true) {
|
||||
if(node === null) {
|
||||
// insert new node at the bottom
|
||||
node = new Node(data);
|
||||
p.set_child(dir, node);
|
||||
ret = true;
|
||||
this.size++;
|
||||
}
|
||||
else if(is_red(node.left) && is_red(node.right)) {
|
||||
// color flip
|
||||
node.red = true;
|
||||
node.left.red = false;
|
||||
node.right.red = false;
|
||||
}
|
||||
|
||||
// fix red violation
|
||||
if(is_red(node) && is_red(p)) {
|
||||
var dir2 = ggp.right === gp;
|
||||
|
||||
if(node === p.get_child(last)) {
|
||||
ggp.set_child(dir2, single_rotate(gp, !last));
|
||||
}
|
||||
else {
|
||||
ggp.set_child(dir2, double_rotate(gp, !last));
|
||||
}
|
||||
}
|
||||
|
||||
var cmp = this._comparator(node.data, data);
|
||||
|
||||
// stop if found
|
||||
if(cmp === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
last = dir;
|
||||
dir = cmp < 0;
|
||||
|
||||
// update helpers
|
||||
if(gp !== null) {
|
||||
ggp = gp;
|
||||
}
|
||||
gp = p;
|
||||
p = node;
|
||||
node = node.get_child(dir);
|
||||
}
|
||||
|
||||
// update root
|
||||
this._root = head.right;
|
||||
}
|
||||
|
||||
// make root black
|
||||
this._root.red = false;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
// returns true if removed, false if not found
|
||||
RBTree.prototype.remove = function(data) {
|
||||
if(this._root === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var head = new Node(undefined); // fake tree root
|
||||
var node = head;
|
||||
node.right = this._root;
|
||||
var p = null; // parent
|
||||
var gp = null; // grand parent
|
||||
var found = null; // found item
|
||||
var dir = 1;
|
||||
|
||||
while(node.get_child(dir) !== null) {
|
||||
var last = dir;
|
||||
|
||||
// update helpers
|
||||
gp = p;
|
||||
p = node;
|
||||
node = node.get_child(dir);
|
||||
|
||||
var cmp = this._comparator(data, node.data);
|
||||
|
||||
dir = cmp > 0;
|
||||
|
||||
// save found node
|
||||
if(cmp === 0) {
|
||||
found = node;
|
||||
}
|
||||
|
||||
// push the red node down
|
||||
if(!is_red(node) && !is_red(node.get_child(dir))) {
|
||||
if(is_red(node.get_child(!dir))) {
|
||||
var sr = single_rotate(node, dir);
|
||||
p.set_child(last, sr);
|
||||
p = sr;
|
||||
}
|
||||
else if(!is_red(node.get_child(!dir))) {
|
||||
var sibling = p.get_child(!last);
|
||||
if(sibling !== null) {
|
||||
if(!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {
|
||||
// color flip
|
||||
p.red = false;
|
||||
sibling.red = true;
|
||||
node.red = true;
|
||||
}
|
||||
else {
|
||||
var dir2 = gp.right === p;
|
||||
|
||||
if(is_red(sibling.get_child(last))) {
|
||||
gp.set_child(dir2, double_rotate(p, last));
|
||||
}
|
||||
else if(is_red(sibling.get_child(!last))) {
|
||||
gp.set_child(dir2, single_rotate(p, last));
|
||||
}
|
||||
|
||||
// ensure correct coloring
|
||||
var gpc = gp.get_child(dir2);
|
||||
gpc.red = true;
|
||||
node.red = true;
|
||||
gpc.left.red = false;
|
||||
gpc.right.red = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// replace and remove if found
|
||||
if(found !== null) {
|
||||
found.data = node.data;
|
||||
p.set_child(p.right === node, node.get_child(node.left === null));
|
||||
this.size--;
|
||||
}
|
||||
|
||||
// update root and make it black
|
||||
this._root = head.right;
|
||||
if(this._root !== null) {
|
||||
this._root.red = false;
|
||||
}
|
||||
|
||||
return found !== null;
|
||||
};
|
||||
|
||||
function is_red(node) {
|
||||
return node !== null && node.red;
|
||||
}
|
||||
|
||||
function single_rotate(root, dir) {
|
||||
var save = root.get_child(!dir);
|
||||
|
||||
root.set_child(!dir, save.get_child(dir));
|
||||
save.set_child(dir, root);
|
||||
|
||||
root.red = true;
|
||||
save.red = false;
|
||||
|
||||
return save;
|
||||
}
|
||||
|
||||
function double_rotate(root, dir) {
|
||||
root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));
|
||||
return single_rotate(root, dir);
|
||||
}
|
||||
|
||||
module.exports = RBTree;
|
||||
};
|
||||
return {
|
||||
RBTree: require('__main__')
|
||||
};
|
||||
});
|
||||
})();
|
3
lorgar/lib/fonts/CMakeLists.txt
Normal file
3
lorgar/lib/fonts/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(Liberation.js Liberation.js)
|
94
lorgar/lib/fonts/Liberation.js
Normal file
94
lorgar/lib/fonts/Liberation.js
Normal file
|
@ -0,0 +1,94 @@
|
|||
(function() {
|
||||
var moduleName = "lib/fonts/Liberation";
|
||||
|
||||
define(moduleName, [], function() {
|
||||
return {
|
||||
"ascent": 1854,
|
||||
"descent": -434,
|
||||
"lineGap": 67,
|
||||
"unitsPerEm": 2048,
|
||||
"advanceWidthArray": [
|
||||
1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
|
||||
1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
|
||||
569, 569, 727, 1139, 1139, 1821, 1366, 391, 682, 682, 797, 1196, 569, 682, 569, 569,
|
||||
1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 1139, 569, 569, 1196, 1196, 1196, 1139,
|
||||
2079, 1366, 1366, 1479, 1479, 1366, 1251, 1593, 1479, 569, 1024, 1366, 1139, 1706, 1479, 1593,
|
||||
1366, 1593, 1479, 1366, 1251, 1479, 1366, 1933, 1366, 1366, 1251, 569, 569, 569, 961, 1139,
|
||||
682, 1139, 1139, 1024, 1139, 1139, 569, 1139, 1139, 455, 455, 1024, 455, 1706, 1139, 1139,
|
||||
1139, 1139, 682, 1024, 569, 1139, 1024, 1479, 1024, 1024, 1024, 684, 532, 684, 1196, 1536,
|
||||
1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
|
||||
1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536, 1536,
|
||||
569, 682, 1139, 1139, 1139, 1139, 532, 1139, 682, 1509, 758, 1139, 1196, 682, 1509, 1131,
|
||||
819, 1124, 682, 682, 682, 1180, 1100, 682, 682, 682, 748, 1139, 1708, 1708, 1708, 1251,
|
||||
1366, 1366, 1366, 1366, 1366, 1366, 2048, 1479, 1366, 1366, 1366, 1366, 569, 569, 569, 569,
|
||||
1479, 1479, 1593, 1593, 1593, 1593, 1593, 1196, 1593, 1479, 1479, 1479, 1479, 1366, 1366, 1251,
|
||||
1139, 1139, 1139, 1139, 1139, 1139, 1821, 1024, 1139, 1139, 1139, 1139, 569, 569, 569, 569,
|
||||
1139, 1139, 1139, 1139, 1139, 1139, 1139, 1124, 1251, 1139, 1139, 1139, 1139, 1024, 1139, 1024,
|
||||
1366, 1139, 1366, 1139, 1366, 1139, 1479, 1024, 1479, 1024, 1479, 1024, 1479, 1024, 1479, 1259,
|
||||
1479, 1139, 1366, 1139, 1366, 1139, 1366, 1139, 1366, 1139, 1366, 1139, 1593, 1139, 1593, 1139,
|
||||
1593, 1139, 1593, 1139, 1479, 1139, 1479, 1139, 569, 569, 569, 569, 569, 569, 569, 455,
|
||||
569, 569, 1505, 909, 1024, 455, 1366, 1024, 1024, 1139, 455, 1139, 455, 1139, 597, 1139,
|
||||
684, 1139, 455, 1479, 1139, 1479, 1139, 1479, 1139, 1237, 1481, 1139, 1593, 1139, 1593, 1139,
|
||||
1593, 1139, 2048, 1933, 1479, 682, 1479, 682, 1479, 682, 1366, 1024, 1366, 1024, 1366, 1024,
|
||||
1366, 1024, 1251, 569, 1251, 768, 1251, 569, 1479, 1139, 1479, 1139, 1479, 1139, 1479, 1139,
|
||||
1479, 1139, 1479, 1139, 1933, 1479, 1366, 1024, 1366, 1251, 1024, 1251, 1024, 1251, 1024, 455,
|
||||
1139, 1553, 1344, 1139, 1344, 1139, 1479, 1479, 1024, 1479, 1658, 1344, 1139, 1140, 1366, 1541,
|
||||
1237, 1251, 1139, 1593, 1278, 1804, 455, 569, 1366, 1024, 455, 1024, 1824, 1479, 1139, 1593,
|
||||
1756, 1343, 1778, 1367, 1545, 1139, 1366, 1366, 1024, 1266, 779, 569, 1251, 569, 1251, 1749,
|
||||
1371, 1531, 1479, 1582, 1024, 1251, 1024, 1251, 1251, 1116, 1116, 1139, 1139, 939, 997, 1139,
|
||||
532, 846, 1196, 569, 2730, 2503, 2148, 2175, 1706, 924, 2503, 1934, 1579, 1366, 1139, 569,
|
||||
455, 1593, 1139, 1479, 1139, 1479, 1139, 1479, 1139, 1479, 1139, 1479, 1139, 1139, 1366, 1139,
|
||||
1366, 1139, 2048, 1821, 1593, 1139, 1593, 1139, 1366, 1024, 1593, 1139, 1593, 1139, 1251, 1116,
|
||||
455, 2730, 2503, 2148, 1593, 1139, 2118, 1266, 1479, 1139, 1366, 1139, 2048, 1821, 1593, 1251,
|
||||
1366, 1139, 1366, 1139, 1366, 1139, 1366, 1139, 569, 569, 569, 569, 1593, 1139, 1593, 1139,
|
||||
1479, 682, 1479, 682, 1479, 1139, 1479, 1139, 1366, 1024, 1251, 569, 1116, 894, 1479, 1139,
|
||||
1446, 1396, 1238, 1158, 1251, 1024, 1366, 1139, 1366, 1139, 1593, 1139, 1593, 1139, 1593, 1139,
|
||||
1593, 1139, 1366, 1024, 715, 1402, 752, 455, 1816, 1816, 1366, 1479, 1024, 1139, 1251, 1024,
|
||||
1024, 1189, 928, 1366, 1479, 1368, 1366, 1139, 1024, 455, 1510, 1139, 1479, 682, 1366, 1024,
|
||||
1139, 1139, 1139, 1139, 1024, 1024, 1139, 1139, 1139, 1139, 1513, 939, 939, 1293, 1039, 569,
|
||||
1139, 1139, 1144, 1026, 1263, 1139, 1139, 1139, 455, 455, 729, 670, 622, 455, 1171, 1706,
|
||||
1706, 1706, 1139, 1139, 1132, 1139, 1619, 1599, 1126, 682, 682, 682, 682, 682, 682, 682,
|
||||
1109, 1109, 1024, 455, 532, 455, 715, 569, 569, 1139, 1164, 1120, 1024, 1479, 1024, 1064,
|
||||
1024, 1108, 1116, 1116, 1024, 1024, 1024, 1024, 1593, 1088, 1039, 1144, 1131, 814, 1024, 827,
|
||||
1139, 1024, 1024, 1975, 1856, 2059, 1459, 879, 1472, 1564, 1354, 1295, 994, 1080, 1407, 1407,
|
||||
785, 785, 326, 491, 491, 491, 746, 985, 657, 391, 727, 455, 455, 455, 682, 682,
|
||||
714, 714, 1196, 1196, 1196, 1196, 682, 682, 682, 682, 682, 682, 682, 682, 682, 682,
|
||||
569, 569, 682, 682, 682, 682, 682, 682, 682, 682, 682, 682, 682, 682, 682, 682,
|
||||
660, 322, 696, 672, 714, 784, 784, 784, 784, 784, 682, 682, 682, 682, 682, 682,
|
||||
682, 682, 682, 682, 682, 682, 682, 682, 569, 682, 682, 682, 682, 814, 814, 682,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1536, 1536, 1536, 1536, 682, 682, 1536, 1536, 1536, 1536, 682, 1024, 1024, 1024, 569, 1536,
|
||||
1536, 1536, 1536, 1536, 682, 682, 1367, 569, 1606, 1716, 786, 1536, 1586, 1536, 1752, 1541,
|
||||
455, 1366, 1366, 1128, 1368, 1366, 1251, 1479, 1593, 569, 1366, 1368, 1706, 1479, 1331, 1593,
|
||||
1479, 1366, 1536, 1266, 1251, 1366, 1634, 1366, 1711, 1531, 569, 1366, 1184, 913, 1139, 455,
|
||||
1120, 1184, 1178, 1024, 1140, 913, 903, 1139, 1139, 455, 1024, 1024, 1180, 1024, 917, 1139,
|
||||
1413, 1165, 987, 1264, 809, 1120, 1328, 1075, 1460, 1599, 455, 1120, 1139, 1120, 1599, 1536,
|
||||
1178, 1120, 1582, 1962, 1582, 1147, 1599, 1231, 1593, 1139, 1479, 1024, 1251, 827, 1279, 1084,
|
||||
1549, 1181, 1824, 1706, 1381, 1139, 1380, 1024, 1366, 1366, 1248, 1221, 1509, 1134, 950, 839,
|
||||
1231, 1173, 1024, 455, 1593, 905, 905, 1366, 1139, 1479, 1706, 1408, 1165, 1479, 1479, 1479,
|
||||
1366, 1367, 1771, 1109, 1472, 1366, 569, 569, 1024, 2165, 2069, 1749, 1193, 1472, 1301, 1472,
|
||||
1366, 1344, 1366, 1109, 1387, 1366, 1891, 1237, 1472, 1472, 1193, 1344, 1706, 1479, 1593, 1472,
|
||||
1366, 1479, 1251, 1301, 1557, 1366, 1515, 1365, 1877, 1920, 1621, 1813, 1344, 1472, 2069, 1479,
|
||||
1139, 1173, 1088, 747, 1195, 1139, 1370, 939, 1144, 1144, 896, 1195, 1408, 1131, 1139, 1109,
|
||||
1139, 1024, 938, 1024, 1685, 1024, 1173, 1067, 1643, 1685, 1280, 1472, 1067, 1045, 1536, 1109,
|
||||
1139, 1139, 1139, 747, 1045, 1024, 455, 569, 455, 1856, 1664, 1139, 896, 1144, 1024, 1131,
|
||||
2740, 1278, 1593, 1255, 1945, 1461, 1368, 1024, 1838, 1424, 1697, 1403, 2157, 1776, 1237, 939,
|
||||
1631, 1410, 1593, 1139, 1645, 1292, 1645, 1292, 2200, 1836, 1706, 1254, 2439, 1744, 2740, 1278,
|
||||
1479, 1024, 1031, 0, 0, 0, 0, 0, 0, 0, 1472, 1144, 1344, 1067, 1366, 1139,
|
||||
1001, 842, 1109, 747, 1373, 1124, 1891, 1370, 1237, 939, 1193, 896, 1193, 896, 1193, 896,
|
||||
1519, 1097, 1479, 1131, 1801, 1327, 2328, 1782, 1542, 1067, 1479, 1024, 1251, 938, 1139, 1024,
|
||||
1139, 1024, 1366, 1024, 1895, 1415, 1365, 1067, 1365, 1067, 1365, 1139, 1764, 1364, 1764, 1364,
|
||||
569, 1891, 1370, 1367, 1128, 1344, 1195, 1479, 1131, 1479, 1131, 1365, 1067, 1706, 1408, 455,
|
||||
1366, 1139, 1366, 1139, 2048, 1821, 1366, 1139, 1541, 1139, 1541, 1139, 1891, 1370, 1237, 939,
|
||||
1237, 1116, 1472, 1144, 1472, 1144, 1593, 1139, 1593, 1139, 1593, 1139, 1472, 1045, 1301, 1024,
|
||||
1301, 1024, 1301, 1024, 1365, 1067, 1109, 747, 1813, 1472, 1109, 747, 1366, 1024, 1366, 1024
|
||||
]
|
||||
}
|
||||
});
|
||||
})();
|
3
lorgar/lib/requirejs/CMakeLists.txt
Normal file
3
lorgar/lib/requirejs/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(require.js require.js)
|
37
lorgar/lib/requirejs/require.js
Normal file
37
lorgar/lib/requirejs/require.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
RequireJS 2.1.22 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
|
||||
Available via the MIT or new BSD license.
|
||||
see: http://github.com/jrburke/requirejs for details
|
||||
*/
|
||||
var requirejs,require,define;
|
||||
(function(ha){function L(b){return"[object Function]"===R.call(b)}function M(b){return"[object Array]"===R.call(b)}function x(b,c){if(b){var d;for(d=0;d<b.length&&(!b[d]||!c(b[d],d,b));d+=1);}}function Y(b,c){if(b){var d;for(d=b.length-1;-1<d&&(!b[d]||!c(b[d],d,b));--d);}}function w(b,c){return la.call(b,c)}function g(b,c){return w(b,c)&&b[c]}function E(b,c){for(var d in b)if(w(b,d)&&c(b[d],d))break}function Z(b,c,d,k){c&&E(c,function(c,g){if(d||!w(b,g))!k||"object"!==typeof c||!c||M(c)||L(c)||c instanceof
|
||||
RegExp?b[g]=c:(b[g]||(b[g]={}),Z(b[g],c,d,k))});return b}function y(b,c){return function(){return c.apply(b,arguments)}}function ia(b){throw b;}function ja(b){if(!b)return b;var c=ha;x(b.split("."),function(b){c=c[b]});return c}function G(b,c,d,g){c=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);c.requireType=b;c.requireModules=g;d&&(c.originalError=d);return c}function ma(b){function c(a,n,b){var f,l,c,d,h,k,e,A;n=n&&n.split("/");var q=m.map,p=q&&q["*"];if(a){a=a.split("/");l=a.length-1;m.nodeIdCompat&&
|
||||
V.test(a[l])&&(a[l]=a[l].replace(V,""));"."===a[0].charAt(0)&&n&&(l=n.slice(0,n.length-1),a=l.concat(a));l=a;for(c=0;c<l.length;c++)d=l[c],"."===d?(l.splice(c,1),--c):".."===d&&0!==c&&(1!==c||".."!==l[2])&&".."!==l[c-1]&&0<c&&(l.splice(c-1,2),c-=2);a=a.join("/")}if(b&&q&&(n||p)){l=a.split("/");c=l.length;a:for(;0<c;--c){h=l.slice(0,c).join("/");if(n)for(d=n.length;0<d;--d)if(b=g(q,n.slice(0,d).join("/")))if(b=g(b,h)){f=b;k=c;break a}!e&&p&&g(p,h)&&(e=g(p,h),A=c)}!f&&e&&(f=e,k=A);f&&(l.splice(0,k,
|
||||
f),a=l.join("/"))}return(f=g(m.pkgs,a))?f:a}function d(a){F&&x(document.getElementsByTagName("script"),function(n){if(n.getAttribute("data-requiremodule")===a&&n.getAttribute("data-requirecontext")===h.contextName)return n.parentNode.removeChild(n),!0})}function p(a){var n=g(m.paths,a);if(n&&M(n)&&1<n.length)return n.shift(),h.require.undef(a),h.makeRequire(null,{skipMap:!0})([a]),!0}function e(a){var n,b=a?a.indexOf("!"):-1;-1<b&&(n=a.substring(0,b),a=a.substring(b+1,a.length));return[n,a]}function q(a,
|
||||
n,b,f){var l,d,z=null,k=n?n.name:null,m=a,q=!0,A="";a||(q=!1,a="_@r"+(R+=1));a=e(a);z=a[0];a=a[1];z&&(z=c(z,k,f),d=g(r,z));a&&(z?A=d&&d.normalize?d.normalize(a,function(a){return c(a,k,f)}):-1===a.indexOf("!")?c(a,k,f):a:(A=c(a,k,f),a=e(A),z=a[0],A=a[1],b=!0,l=h.nameToUrl(A)));b=!z||d||b?"":"_unnormalized"+(U+=1);return{prefix:z,name:A,parentMap:n,unnormalized:!!b,url:l,originalName:m,isDefine:q,id:(z?z+"!"+A:A)+b}}function u(a){var b=a.id,c=g(t,b);c||(c=t[b]=new h.Module(a));return c}function v(a,
|
||||
b,c){var f=a.id,l=g(t,f);if(!w(r,f)||l&&!l.defineEmitComplete)if(l=u(a),l.error&&"error"===b)c(l.error);else l.on(b,c);else"defined"===b&&c(r[f])}function B(a,b){var c=a.requireModules,f=!1;if(b)b(a);else if(x(c,function(b){if(b=g(t,b))b.error=a,b.events.error&&(f=!0,b.emit("error",a))}),!f)k.onError(a)}function C(){W.length&&(x(W,function(a){var b=a[0];"string"===typeof b&&(h.defQueueMap[b]=!0);H.push(a)}),W=[])}function D(a){delete t[a];delete aa[a]}function K(a,b,c){var f=a.map.id;a.error?a.emit("error",
|
||||
a.error):(b[f]=!0,x(a.depMaps,function(f,d){var h=f.id,k=g(t,h);!k||a.depMatched[d]||c[h]||(g(b,h)?(a.defineDep(d,r[h]),a.check()):K(k,b,c))}),c[f]=!0)}function I(){var a,b,c=(a=1E3*m.waitSeconds)&&h.startTime+a<(new Date).getTime(),f=[],l=[],k=!1,g=!0;if(!ba){ba=!0;E(aa,function(a){var h=a.map,e=h.id;if(a.enabled&&(h.isDefine||l.push(a),!a.error))if(!a.inited&&c)p(e)?k=b=!0:(f.push(e),d(e));else if(!a.inited&&a.fetched&&h.isDefine&&(k=!0,!h.prefix))return g=!1});if(c&&f.length)return a=G("timeout",
|
||||
"Load timeout for modules: "+f,null,f),a.contextName=h.contextName,B(a);g&&x(l,function(a){K(a,{},{})});c&&!b||!k||!F&&!ka||ca||(ca=setTimeout(function(){ca=0;I()},50));ba=!1}}function J(a){w(r,a[0])||u(q(a[0],null,!0)).init(a[1],a[2])}function P(a){a=a.currentTarget||a.srcElement;var b=h.onScriptLoad;a.detachEvent&&!da?a.detachEvent("onreadystatechange",b):a.removeEventListener("load",b,!1);b=h.onScriptError;a.detachEvent&&!da||a.removeEventListener("error",b,!1);return{node:a,id:a&&a.getAttribute("data-requiremodule")}}
|
||||
function Q(){var a;for(C();H.length;){a=H.shift();if(null===a[0])return B(G("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));J(a)}h.defQueueMap={}}var ba,ea,h,S,ca,m={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},t={},aa={},fa={},H=[],r={},X={},ga={},R=1,U=1;S={require:function(a){return a.require?a.require:a.require=h.makeRequire(a.map)},exports:function(a){a.usingExports=!0;if(a.map.isDefine)return a.exports?r[a.map.id]=a.exports:a.exports=r[a.map.id]=
|
||||
{}},module:function(a){return a.module?a.module:a.module={id:a.map.id,uri:a.map.url,config:function(){return g(m.config,a.map.id)||{}},exports:a.exports||(a.exports={})}}};ea=function(a){this.events=g(fa,a.id)||{};this.map=a;this.shim=g(m.shim,a.id);this.depExports=[];this.depMaps=[];this.depMatched=[];this.pluginMaps={};this.depCount=0};ea.prototype={init:function(a,b,c,f){f=f||{};if(!this.inited){this.factory=b;if(c)this.on("error",c);else this.events.error&&(c=y(this,function(a){this.emit("error",
|
||||
a)}));this.depMaps=a&&a.slice(0);this.errback=c;this.inited=!0;this.ignore=f.ignore;f.enabled||this.enabled?this.enable():this.check()}},defineDep:function(a,b){this.depMatched[a]||(this.depMatched[a]=!0,--this.depCount,this.depExports[a]=b)},fetch:function(){if(!this.fetched){this.fetched=!0;h.startTime=(new Date).getTime();var a=this.map;if(this.shim)h.makeRequire(this.map,{enableBuildCallback:!0})(this.shim.deps||[],y(this,function(){return a.prefix?this.callPlugin():this.load()}));else return a.prefix?
|
||||
this.callPlugin():this.load()}},load:function(){var a=this.map.url;X[a]||(X[a]=!0,h.load(this.map.id,a))},check:function(){if(this.enabled&&!this.enabling){var a,b,c=this.map.id;b=this.depExports;var f=this.exports,l=this.factory;if(!this.inited)w(h.defQueueMap,c)||this.fetch();else if(this.error)this.emit("error",this.error);else if(!this.defining){this.defining=!0;if(1>this.depCount&&!this.defined){if(L(l)){try{f=h.execCb(c,l,b,f)}catch(d){a=d}this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:
|
||||
this.usingExports&&(f=this.exports));if(a){if(this.events.error&&this.map.isDefine||k.onError!==ia)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",B(this.error=a);if("undefined"!==typeof console&&console.error)console.error(a);else k.onError(a)}}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(r[c]=f,k.onResourceLoad)){var e=[];x(this.depMaps,function(a){e.push(a.normalizedMap||a)});k.onResourceLoad(h,
|
||||
this.map,e)}D(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}},callPlugin:function(){var a=this.map,b=a.id,d=q(a.prefix);this.depMaps.push(d);v(d,"defined",y(this,function(f){var l,d,e=g(ga,this.map.id),N=this.map.name,p=this.map.parentMap?this.map.parentMap.name:null,r=h.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(N=f.normalize(N,function(a){return c(a,
|
||||
p,!0)})||""),d=q(a.prefix+"!"+N,this.map.parentMap),v(d,"defined",y(this,function(a){this.map.normalizedMap=d;this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),f=g(t,d.id)){this.depMaps.push(d);if(this.events.error)f.on("error",y(this,function(a){this.emit("error",a)}));f.enable()}}else e?(this.map.url=h.nameToUrl(e),this.load()):(l=y(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=y(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];
|
||||
E(t,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&D(a.map.id)});B(a)}),l.fromText=y(this,function(f,c){var d=a.name,e=q(d),N=T;c&&(f=c);N&&(T=!1);u(e);w(m.config,b)&&(m.config[d]=m.config[b]);try{k.exec(f)}catch(g){return B(G("fromtexteval","fromText eval for "+b+" failed: "+g,g,[b]))}N&&(T=!0);this.depMaps.push(e);h.completeLoad(d);r([d],l)}),f.load(a.name,r,l,m))}));h.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){aa[this.map.id]=this;this.enabling=this.enabled=!0;x(this.depMaps,
|
||||
y(this,function(a,b){var c,f;if("string"===typeof a){a=q(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=g(S,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;v(a,"defined",y(this,function(a){this.undefed||(this.defineDep(b,a),this.check())}));this.errback?v(a,"error",y(this,this.errback)):this.events.error&&v(a,"error",y(this,function(a){this.emit("error",a)}))}c=a.id;f=t[c];w(S,c)||!f||f.enabled||h.enable(a,this)}));E(this.pluginMaps,y(this,function(a){var b=
|
||||
g(t,a.id);b&&!b.enabled&&h.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){x(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}};h={config:m,contextName:b,registry:t,defined:r,urlFetched:X,defQueue:H,defQueueMap:{},Module:ea,makeModuleMap:q,nextTick:k.nextTick,onError:B,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=m.shim,c={paths:!0,
|
||||
bundles:!0,config:!0,map:!0};E(a,function(a,b){c[b]?(m[b]||(m[b]={}),Z(m[b],a,!0,!0)):m[b]=a});a.bundles&&E(a.bundles,function(a,b){x(a,function(a){a!==b&&(ga[a]=b)})});a.shim&&(E(a.shim,function(a,c){M(a)&&(a={deps:a});!a.exports&&!a.init||a.exportsFn||(a.exportsFn=h.makeShimExports(a));b[c]=a}),m.shim=b);a.packages&&x(a.packages,function(a){var b;a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(m.paths[b]=a.location);m.pkgs[b]=a.name+"/"+(a.main||"main").replace(na,"").replace(V,"")});E(t,
|
||||
function(a,b){a.inited||a.map.unnormalized||(a.map=q(b,null,!0))});(a.deps||a.callback)&&h.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ha,arguments));return b||a.exports&&ja(a.exports)}},makeRequire:function(a,n){function e(c,d,g){var m,p;n.enableBuildCallback&&d&&L(d)&&(d.__requireJsBuild=!0);if("string"===typeof c){if(L(d))return B(G("requireargs","Invalid require call"),g);if(a&&w(S,c))return S[c](t[a.id]);if(k.get)return k.get(h,
|
||||
c,a,e);m=q(c,a,!1,!0);m=m.id;return w(r,m)?r[m]:B(G("notloaded",'Module name "'+m+'" has not been loaded yet for context: '+b+(a?"":". Use require([])")))}Q();h.nextTick(function(){Q();p=u(q(null,a));p.skipMap=n.skipMap;p.init(c,d,g,{enabled:!0});I()});return e}n=n||{};Z(e,{isBrowser:F,toUrl:function(b){var d,e=b.lastIndexOf("."),n=b.split("/")[0];-1!==e&&("."!==n&&".."!==n||1<e)&&(d=b.substring(e,b.length),b=b.substring(0,e));return h.nameToUrl(c(b,a&&a.id,!0),d,!0)},defined:function(b){return w(r,
|
||||
q(b,a,!1,!0).id)},specified:function(b){b=q(b,a,!1,!0).id;return w(r,b)||w(t,b)}});a||(e.undef=function(b){C();var c=q(b,a,!0),e=g(t,b);e.undefed=!0;d(b);delete r[b];delete X[c.url];delete fa[b];Y(H,function(a,c){a[0]===b&&H.splice(c,1)});delete h.defQueueMap[b];e&&(e.events.defined&&(fa[b]=e.events),D(b))});return e},enable:function(a){g(t,a.id)&&u(a).enable()},completeLoad:function(a){var b,c,d=g(m.shim,a)||{},e=d.exports;for(C();H.length;){c=H.shift();if(null===c[0]){c[0]=a;if(b)break;b=!0}else c[0]===
|
||||
a&&(b=!0);J(c)}h.defQueueMap={};c=g(t,a);if(!b&&!w(r,a)&&c&&!c.inited)if(!m.enforceDefine||e&&ja(e))J([a,d.deps||[],d.exportsFn]);else return p(a)?void 0:B(G("nodefine","No define call for "+a,null,[a]));I()},nameToUrl:function(a,b,c){var d,e,p;(d=g(m.pkgs,a))&&(a=d);if(d=g(ga,a))return h.nameToUrl(d,b,c);if(k.jsExtRegExp.test(a))d=a+(b||"");else{d=m.paths;a=a.split("/");for(e=a.length;0<e;--e)if(p=a.slice(0,e).join("/"),p=g(d,p)){M(p)&&(p=p[0]);a.splice(0,e,p);break}d=a.join("/");d+=b||(/^data\:|\?/.test(d)||
|
||||
c?"":".js");d=("/"===d.charAt(0)||d.match(/^[\w\+\.\-]+:/)?"":m.baseUrl)+d}return m.urlArgs?d+((-1===d.indexOf("?")?"?":"&")+m.urlArgs):d},load:function(a,b){k.load(h,a,b)},execCb:function(a,b,c,d){return b.apply(d,c)},onScriptLoad:function(a){if("load"===a.type||oa.test((a.currentTarget||a.srcElement).readyState))O=null,a=P(a),h.completeLoad(a.id)},onScriptError:function(a){var b=P(a);if(!p(b.id)){var c=[];E(t,function(a,d){0!==d.indexOf("_@r")&&x(a.depMaps,function(a){a.id===b.id&&c.push(d);return!0})});
|
||||
return B(G("scripterror",'Script error for "'+b.id+(c.length?'", needed by: '+c.join(", "):'"'),a,[b.id]))}}};h.require=h.makeRequire();return h}function pa(){if(O&&"interactive"===O.readyState)return O;Y(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return O=b});return O}var k,C,D,I,P,J,O,Q,u,U,qa=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,ra=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,V=/\.js$/,na=/^\.\//;C=Object.prototype;var R=C.toString,la=C.hasOwnProperty,
|
||||
F=!("undefined"===typeof window||"undefined"===typeof navigator||!window.document),ka=!F&&"undefined"!==typeof importScripts,oa=F&&"PLAYSTATION 3"===navigator.platform?/^complete$/:/^(complete|loaded)$/,da="undefined"!==typeof opera&&"[object Opera]"===opera.toString(),K={},v={},W=[],T=!1;if("undefined"===typeof define){if("undefined"!==typeof requirejs){if(L(requirejs))return;v=requirejs;requirejs=void 0}"undefined"===typeof require||L(require)||(v=require,require=void 0);k=requirejs=function(b,
|
||||
c,d,p){var e,q="_";M(b)||"string"===typeof b||(e=b,M(c)?(b=c,c=d,d=p):b=[]);e&&e.context&&(q=e.context);(p=g(K,q))||(p=K[q]=k.s.newContext(q));e&&p.configure(e);return p.require(b,c,d)};k.config=function(b){return k(b)};k.nextTick="undefined"!==typeof setTimeout?function(b){setTimeout(b,4)}:function(b){b()};require||(require=k);k.version="2.1.22";k.jsExtRegExp=/^\/|:|\?|\.js$/;k.isBrowser=F;C=k.s={contexts:K,newContext:ma};k({});x(["toUrl","undef","defined","specified"],function(b){k[b]=function(){var c=
|
||||
K._;return c.require[b].apply(c,arguments)}});F&&(D=C.head=document.getElementsByTagName("head")[0],I=document.getElementsByTagName("base")[0])&&(D=C.head=I.parentNode);k.onError=ia;k.createNode=function(b,c,d){c=b.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");c.type=b.scriptType||"text/javascript";c.charset="utf-8";c.async=!0;return c};k.load=function(b,c,d){var g=b&&b.config||{},e;if(F){e=k.createNode(g,c,d);if(g.onNodeCreated)g.onNodeCreated(e,
|
||||
g,c,d);e.setAttribute("data-requirecontext",b.contextName);e.setAttribute("data-requiremodule",c);!e.attachEvent||e.attachEvent.toString&&0>e.attachEvent.toString().indexOf("[native code")||da?(e.addEventListener("load",b.onScriptLoad,!1),e.addEventListener("error",b.onScriptError,!1)):(T=!0,e.attachEvent("onreadystatechange",b.onScriptLoad));e.src=d;Q=e;I?D.insertBefore(e,I):D.appendChild(e);Q=null;return e}if(ka)try{importScripts(d),b.completeLoad(c)}catch(q){b.onError(G("importscripts","importScripts failed for "+
|
||||
c+" at "+d,q,[c]))}};F&&!v.skipDataMain&&Y(document.getElementsByTagName("script"),function(b){D||(D=b.parentNode);if(P=b.getAttribute("data-main"))return u=P,v.baseUrl||(J=u.split("/"),u=J.pop(),U=J.length?J.join("/")+"/":"./",v.baseUrl=U),u=u.replace(V,""),k.jsExtRegExp.test(u)&&(u=P),v.deps=v.deps?v.deps.concat(u):[u],!0});define=function(b,c,d){var g,e;"string"!==typeof b&&(d=c,c=b,b=null);M(c)||(d=c,c=null);!c&&L(d)&&(c=[],d.length&&(d.toString().replace(qa,"").replace(ra,function(b,d){c.push(d)}),
|
||||
c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));T&&(g=Q||pa())&&(b||(b=g.getAttribute("data-requiremodule")),e=K[g.getAttribute("data-requirecontext")]);e?(e.defQueue.push([b,c,d]),e.defQueueMap[b]=!0):W.push([b,c,d])};define.amd={jQuery:!0};k.exec=function(b){return eval(b)};k(v)}})(this);
|
5
lorgar/lib/utils/CMakeLists.txt
Normal file
5
lorgar/lib/utils/CMakeLists.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_jslib(utils/class.js lib/utils/class ${LORGAR_DIR} browser)
|
||||
add_jslib(utils/subscribable.js lib/utils/subscribable ${LORGAR_DIR} browser)
|
||||
add_jslib(utils/globalMethods.js lib/utils/globalMethods ${LORGAR_DIR} browser)
|
6
lorgar/lib/wContainer/CMakeLists.txt
Normal file
6
lorgar/lib/wContainer/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_jslib(wContainer/abstractmap.js lib/wContainer/abstractmap ${LORGAR_DIR} browser)
|
||||
add_jslib(wContainer/abstractlist.js lib/wContainer/abstractlist ${LORGAR_DIR} browser)
|
||||
add_jslib(wContainer/abstractorder.js lib/wContainer/abstractorder ${LORGAR_DIR} browser)
|
||||
add_jslib(wContainer/abstractpair.js lib/wContainer/abstractpair ${LORGAR_DIR} browser)
|
19
lorgar/lib/wController/CMakeLists.txt
Normal file
19
lorgar/lib/wController/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_jslib(wController/controller.js lib/wController/controller ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/globalControls.js lib/wController/globalControls ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/link.js lib/wController/link ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/list.js lib/wController/list ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/navigationPanel.js lib/wController/navigationPanel ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/page.js lib/wController/page ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/pageStorage.js lib/wController/pageStorage ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/panesList.js lib/wController/panesList ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/string.js lib/wController/string ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/theme.js lib/wController/theme ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/themeSelecter.js lib/wController/themeSelecter ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/vocabulary.js lib/wController/vocabulary ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/attributes.js lib/wController/attributes ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/localModel.js lib/wController/localModel ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/imagePane.js lib/wController/imagePane ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/file/file.js lib/wController/file/file ${LORGAR_DIR} browser)
|
||||
add_jslib(wController/image.js lib/wController/image ${LORGAR_DIR} browser)
|
6
lorgar/lib/wDispatcher/CMakeLists.txt
Normal file
6
lorgar/lib/wDispatcher/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_jslib(wDispatcher/dispatcher.js lib/wDispatcher/dispatcher ${LORGAR_DIR} browser)
|
||||
add_jslib(wDispatcher/defaulthandler.js lib/wDispatcher/defaulthandler ${LORGAR_DIR} browser)
|
||||
add_jslib(wDispatcher/handler.js lib/wDispatcher/handler ${LORGAR_DIR} browser)
|
||||
add_jslib(wDispatcher/logger.js lib/wDispatcher/logger ${LORGAR_DIR} browser)
|
3
lorgar/lib/wSocket/CMakeLists.txt
Normal file
3
lorgar/lib/wSocket/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(socket.js socket.js)
|
203
lorgar/lib/wSocket/socket.js
Normal file
203
lorgar/lib/wSocket/socket.js
Normal file
|
@ -0,0 +1,203 @@
|
|||
"use strict";
|
||||
(function socket_js() {
|
||||
var moduleName = "lib/wSocket/socket"
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("lib/utils/subscribable");
|
||||
defineArray.push("lib/wType/event");
|
||||
defineArray.push("lib/wType/bytearray");
|
||||
defineArray.push("lib/wType/string");
|
||||
defineArray.push("lib/wType/vocabulary");
|
||||
defineArray.push("lib/wType/uint64");
|
||||
defineArray.push("lib/wType/address");
|
||||
defineArray.push("lib/wType/factory");
|
||||
|
||||
define(moduleName, defineArray, function socket_module() {
|
||||
var Subscribable = require("lib/utils/subscribable");
|
||||
var Event = require("lib/wType/event");
|
||||
var ByteArray = require("lib/wType/bytearray");
|
||||
var String = require("lib/wType/string");
|
||||
var Vocabulary = require("lib/wType/vocabulary");
|
||||
var Uint64 = require("lib/wType/uint64");
|
||||
var Address = require("lib/wType/address");
|
||||
var factory = require("lib/wType/factory");
|
||||
|
||||
var Socket = Subscribable.inherit({
|
||||
"className": "Socket",
|
||||
"constructor": function(name) {
|
||||
if (!name) {
|
||||
throw new Error("Can't construct a socket without a name");
|
||||
}
|
||||
Subscribable.fn.constructor.call(this);
|
||||
|
||||
this._state = DISCONNECTED;
|
||||
this._dState = SIZE;
|
||||
this._name = name instanceof String ? name : new String(name);
|
||||
this._remoteName = new String();
|
||||
this._id = new Uint64(0);
|
||||
this._socket = undefined;
|
||||
this._helperBuffer = new ByteArray(4);
|
||||
|
||||
this._initProxy();
|
||||
},
|
||||
"destructor": function() {
|
||||
this.close();
|
||||
if (this._state === DISCONNECTING) {
|
||||
this.on("disconnected", function() {
|
||||
Subscribable.fn.destructor.call(this);
|
||||
})
|
||||
} else {
|
||||
Subscribable.fn.destructor.call(this);
|
||||
}
|
||||
},
|
||||
"close": function() {
|
||||
if ((this._state !== DISCONNECTED) && (this._state !== DISCONNECTING)) {
|
||||
this._state = DISCONNECTING;
|
||||
this._socket.close();
|
||||
}
|
||||
},
|
||||
"_emitEvent": function(ev) {
|
||||
this.trigger("message", ev);
|
||||
ev.destructor();
|
||||
},
|
||||
"getId": function() {
|
||||
return this._id;
|
||||
},
|
||||
"isOpened": function() {
|
||||
return this._state === CONNECTED;
|
||||
},
|
||||
"open": function(addr, port) {
|
||||
if (this._state === DISCONNECTED) {
|
||||
this._state = CONNECTING;
|
||||
this._socket = new WebSocket("ws://"+ addr + ":" + port);
|
||||
this._socket.binaryType = "arraybuffer";
|
||||
|
||||
this._socket.onclose = this._proxy.onSocketClose;
|
||||
this._socket.onerror = this._proxy.onSocketError;
|
||||
this._socket.onmessage = this._proxy.onSocketMessage
|
||||
}
|
||||
},
|
||||
"send": function(ev) {
|
||||
var size = ev.size();
|
||||
var ba = new ByteArray(size + 5);
|
||||
ba.push32(size);
|
||||
ba.push8(ev.getType());
|
||||
ev.serialize(ba);
|
||||
|
||||
this._socket.send(ba.data().buffer);
|
||||
},
|
||||
"_initProxy": function() {
|
||||
this._proxy = {
|
||||
onSocketClose: this._onSocketClose.bind(this),
|
||||
onSocketError: this._onSocketError.bind(this),
|
||||
onSocketMessage: this._onSocketMessage.bind(this)
|
||||
}
|
||||
},
|
||||
"_onEvent": function(ev) {
|
||||
if (ev.isSystem()) {
|
||||
var cmd = ev._data.at("command").toString();
|
||||
|
||||
switch(cmd) {
|
||||
case "setId":
|
||||
this._setId(ev._data.at("id"));
|
||||
this._setRemoteName();
|
||||
break;
|
||||
case "setName":
|
||||
this._setName(ev._data.at("name"));
|
||||
this._state = CONNECTED;
|
||||
this.trigger("connected");
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unknown system command: " + cmd);
|
||||
}
|
||||
ev.destructor();
|
||||
} else {
|
||||
setTimeout(this._emitEvent.bind(this, ev), 5); //TODO event queue
|
||||
}
|
||||
},
|
||||
"_onSocketClose": function(ev) {
|
||||
this._state = DISCONNECTED;
|
||||
|
||||
this._id.destructor();
|
||||
this._id = new Uint64(0);
|
||||
|
||||
this._remoteName.destructor();
|
||||
this._remoteName = new String();
|
||||
|
||||
console.log(ev);
|
||||
this.trigger("disconnected", ev);
|
||||
},
|
||||
"_onSocketError": function(err) {
|
||||
this.trigger("error", err);
|
||||
},
|
||||
"_onSocketMessage": function(mes) {
|
||||
var raw = new Uint8Array(mes.data);
|
||||
var i = 0;
|
||||
|
||||
while (i < raw.length) {
|
||||
switch (this._dState) {
|
||||
case SIZE:
|
||||
i = this._helperBuffer.fill(raw, raw.length, i);
|
||||
|
||||
if (this._helperBuffer.filled()) {
|
||||
var size = this._helperBuffer.pop32();
|
||||
this._helperBuffer.destructor();
|
||||
this._helperBuffer = new ByteArray(size + 1);
|
||||
this._dState = BODY;
|
||||
}
|
||||
break;
|
||||
case BODY:
|
||||
i = this._helperBuffer.fill(raw, raw.length, i);
|
||||
|
||||
if (this._helperBuffer.filled()) {
|
||||
var ev = factory(this._helperBuffer);
|
||||
this._onEvent(ev);
|
||||
this._helperBuffer.destructor();
|
||||
this._helperBuffer = new ByteArray(4);
|
||||
this._dState = SIZE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
"_setId": function(id) {
|
||||
if (this._state === CONNECTING) {
|
||||
this._id.destructor();
|
||||
this._id = id.clone();
|
||||
} else {
|
||||
throw new Error("An attempt to set id in unexpected time");
|
||||
}
|
||||
},
|
||||
"_setName": function(name) {
|
||||
if ((this._state === CONNECTING) && (this._id.valueOf() !== 0)) {
|
||||
this._remoteName.destructor();
|
||||
this._remoteName = name.clone();
|
||||
} else {
|
||||
throw new Error("An attempt to set name in unexpected time");
|
||||
}
|
||||
},
|
||||
"_setRemoteName": function() {
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("command", new String("setName"));
|
||||
vc.insert("name", this._name.clone());
|
||||
vc.insert("yourName", this._remoteName.clone());
|
||||
|
||||
var ev = new Event(new Address(), vc, true);
|
||||
ev.setSenderId(this._id.clone());
|
||||
this.send(ev);
|
||||
|
||||
ev.destructor();
|
||||
}
|
||||
});
|
||||
|
||||
return Socket;
|
||||
});
|
||||
|
||||
var DISCONNECTED = 111;
|
||||
var DISCONNECTING = 110;
|
||||
var CONNECTING = 101;
|
||||
var CONNECTED = 100;
|
||||
|
||||
var SIZE = 11;
|
||||
var BODY = 10;
|
||||
})();
|
6
lorgar/lib/wTest/CMakeLists.txt
Normal file
6
lorgar/lib/wTest/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_jslib(wTest/test.js lib/wTest/test ${LORGAR_DIR} browser)
|
||||
add_jslib(wTest/abstractmap.js lib/wTest/abstractmap ${LORGAR_DIR} browser)
|
||||
add_jslib(wTest/abstractlist.js lib/wTest/abstractlist ${LORGAR_DIR} browser)
|
||||
add_jslib(wTest/abstractorder.js lib/wTest/abstractorder ${LORGAR_DIR} browser)
|
13
lorgar/lib/wType/CMakeLists.txt
Normal file
13
lorgar/lib/wType/CMakeLists.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
add_jslib(wType/address.js lib/wType/address ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/boolean.js lib/wType/boolean ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/bytearray.js lib/wType/bytearray ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/event.js lib/wType/event ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/object.js lib/wType/object ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/string.js lib/wType/string ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/uint64.js lib/wType/uint64 ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/vector.js lib/wType/vector ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/vocabulary.js lib/wType/vocabulary ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/blob.js lib/wType/blob ${LORGAR_DIR} browser)
|
||||
add_jslib(wType/factory.js lib/wType/factory ${LORGAR_DIR} browser)
|
47
lorgar/main.js
Normal file
47
lorgar/main.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
"use strict";
|
||||
(function main_js() {
|
||||
requirejs.onError = function(e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("test/test");
|
||||
defineArray.push("core/lorgar");
|
||||
defineArray.push("lib/utils/globalMethods");
|
||||
|
||||
require(defineArray, function main_module() {
|
||||
require("lib/utils/globalMethods");
|
||||
|
||||
var Test = require("test/test");
|
||||
var Lorgar = require("core/lorgar");
|
||||
var Controller = require("lib/wController/controller");
|
||||
var View = require("views/view");
|
||||
|
||||
var waiter = {
|
||||
views: false,
|
||||
controllers: false,
|
||||
check: function(key) {
|
||||
this[key] = true;
|
||||
this.launch()
|
||||
},
|
||||
launch: function() {
|
||||
if (this.views && this.controllers) {
|
||||
window.lorgar = new Lorgar();
|
||||
|
||||
window.registerForeignController = window.lorgar.registerForeignController.bind(window.lorgar);
|
||||
window.unregisterForeignController = window.lorgar.unregisterForeignController.bind(window.lorgar);
|
||||
window.subscribeForeignController = window.lorgar.subscribeForeignController.bind(window.lorgar);
|
||||
window.unsubscribeForeignController = window.lorgar.unsubscribeForeignController.bind(window.lorgar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controller.initialize(["String", "List", "Vocabulary", "Page", "PanesList", "Link", "Image"], waiter.check.bind(waiter, "controllers"));
|
||||
View.initialize(["Label", "Page", "PanesList", "Nav", "Image"], waiter.check.bind(waiter, "views"));
|
||||
|
||||
var test = new Test();
|
||||
test.run();
|
||||
|
||||
});
|
||||
|
||||
})();
|
3
lorgar/test/CMakeLists.txt
Normal file
3
lorgar/test/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(test.js test.js)
|
73
lorgar/test/test.js
Normal file
73
lorgar/test/test.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
"use strict";
|
||||
(function test_js() {
|
||||
var moduleName = "test/test";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("lib/utils/class");
|
||||
defineArray.push("lib/wTest/abstractmap");
|
||||
defineArray.push("lib/wTest/abstractlist");
|
||||
defineArray.push("lib/wTest/abstractorder");
|
||||
|
||||
define(moduleName, defineArray, function test_module() {
|
||||
var Class = require("lib/utils/class");
|
||||
var TAbstractMap = require("lib/wTest/abstractmap");
|
||||
var TAbstractList = require("lib/wTest/abstractlist");
|
||||
var TAbstractOrder = require("lib/wTest/abstractorder");
|
||||
|
||||
var Test = Class.inherit({
|
||||
"className": "Test",
|
||||
"constructor": function() {
|
||||
Class.fn.constructor.call(this);
|
||||
|
||||
this._s = 0;
|
||||
this._t = 0;
|
||||
this._tests = [];
|
||||
|
||||
this.addTest(new TAbstractList());
|
||||
this.addTest(new TAbstractMap());
|
||||
this.addTest(new TAbstractOrder());
|
||||
},
|
||||
"destructor": function() {
|
||||
for (var i = 0; i < this._tests.length; ++i) {
|
||||
this._tests[i].destructor();
|
||||
}
|
||||
|
||||
Class.fn.destructor.call(this);
|
||||
},
|
||||
"addTest": function(test) {
|
||||
test.on("start", this._onStart, this);
|
||||
test.on("end", this._onEnd, this);
|
||||
test.on("progress", this._onProgress, this);
|
||||
test.on("fail", this._onFail, this);
|
||||
|
||||
this._tests.push(test);
|
||||
},
|
||||
"run": function() {
|
||||
console.info("Starting tests");
|
||||
for (var i = 0; i < this._tests.length; ++i) {
|
||||
this._tests[i].run();
|
||||
}
|
||||
console.info("Testing complete. " + this._s + "/" + this._t);
|
||||
},
|
||||
"_onStart": function(name) {
|
||||
console.info("Testing " + name);
|
||||
},
|
||||
"_onEnd": function(name, s, t) {
|
||||
console.info("Finished " + name + ". " + s + "/" + t);
|
||||
|
||||
this._s += s;
|
||||
this._t += t;
|
||||
},
|
||||
"_onProgress": function(name, current, total) {
|
||||
|
||||
},
|
||||
"_onFail": function(name, current, error) {
|
||||
console.warn("Test failed! Action " + current + ".");
|
||||
console.warn("Error message:" + error.message);
|
||||
console.warn("Error stack: \n" + error.stack);
|
||||
}
|
||||
});
|
||||
|
||||
return Test;
|
||||
});
|
||||
})();
|
15
lorgar/views/CMakeLists.txt
Normal file
15
lorgar/views/CMakeLists.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(label.js label.js)
|
||||
configure_file(view.js view.js)
|
||||
configure_file(layout.js layout.js)
|
||||
configure_file(gridLayout.js gridLayout.js)
|
||||
configure_file(navigationPanel.js navigationPanel.js)
|
||||
configure_file(nav.js nav.js)
|
||||
configure_file(panesList.js panesList.js)
|
||||
configure_file(mainLayout.js mainLayout.js)
|
||||
configure_file(page.js page.js)
|
||||
configure_file(pane.js pane.js)
|
||||
configure_file(image.js image.js)
|
||||
|
||||
add_subdirectory(helpers)
|
436
lorgar/views/gridLayout.js
Normal file
436
lorgar/views/gridLayout.js
Normal file
|
@ -0,0 +1,436 @@
|
|||
"use strict";
|
||||
(function gridLayout_js() {
|
||||
var moduleName = "views/gridLayout";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("views/layout");
|
||||
|
||||
define(moduleName, defineArray, function gridLayout_module() {
|
||||
var View = require("views/view");
|
||||
var Layout = require("views/layout");
|
||||
|
||||
var GridLayout = Layout.inherit({
|
||||
"className": "GridLayout",
|
||||
"constructor": function(controller, options) {
|
||||
var base = {
|
||||
|
||||
};
|
||||
W.extend(base, options);
|
||||
Layout.fn.constructor.call(this, controller, base);
|
||||
|
||||
this._lay = [[[]]];
|
||||
this._cols = [{}];
|
||||
this._rows = [{}];
|
||||
},
|
||||
"append": function(child, row, col, rowSpan, colSpan, aligment) {
|
||||
aligment = aligment || 5;
|
||||
this._addChild(child, aligment);
|
||||
|
||||
rowSpan = rowSpan || 1;
|
||||
colSpan = colSpan || 1;
|
||||
|
||||
var tRow = row + rowSpan;
|
||||
var tCol = col + colSpan;
|
||||
|
||||
while (this._lay.length < tRow) {
|
||||
this._lay.push([]);
|
||||
|
||||
}
|
||||
for (var i = 0; i < this._lay.length; ++i) {
|
||||
while (this._lay[i].length < tCol) {
|
||||
this._lay[i].push([]);
|
||||
}
|
||||
}
|
||||
var obj = {
|
||||
child: child,
|
||||
colspan: colSpan,
|
||||
rowspan: rowSpan,
|
||||
a: aligment
|
||||
}
|
||||
|
||||
for (i = row; i < tRow; ++i) {
|
||||
for (var j = col; j < tCol; ++j) {
|
||||
this._lay[i][j].push(obj);
|
||||
}
|
||||
}
|
||||
|
||||
this._recountLimits();
|
||||
if (this._w !== undefined && this._h !== undefined) {
|
||||
this.refreshLay();
|
||||
}
|
||||
},
|
||||
"_cleanupLay": function() {
|
||||
var i;
|
||||
var rowsC = false;
|
||||
var colsC = false;
|
||||
while (!rowsC) {
|
||||
for (i = 0; i < this._lay[this._lay.length - 1].length; ++i) {
|
||||
if (this._lay[this._lay.length - 1][i].length) {
|
||||
rowsC = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!rowsC) {
|
||||
this._lay.pop()
|
||||
rowsC = !this._lay.length;
|
||||
colsC = !this._lay.length;
|
||||
}
|
||||
}
|
||||
while (!colsC) {
|
||||
for (i = 0; i < this._lay.length; ++i) {
|
||||
if (this._lay[i][this._lay[i].length - 1].length) {
|
||||
colsC = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!colsC) {
|
||||
for (i = 0; i < this._lay.length; ++i) {
|
||||
this._lay[i].pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"clear": function() {
|
||||
Layout.fn.clear.call(this);
|
||||
|
||||
this._lay = [[[]]];
|
||||
this._cols = [{}];
|
||||
this._rows = [{}];
|
||||
},
|
||||
"_onChildChangeLimits": function() {
|
||||
var notification = this._recountLimits();
|
||||
if (!notification) {
|
||||
this.refreshLay();
|
||||
}
|
||||
},
|
||||
"_positionElements": function() {
|
||||
var shiftW = 0;
|
||||
var shiftH = 0;
|
||||
|
||||
var positioned = [];
|
||||
|
||||
for (var i = 0; i < this._lay.length; ++i) {
|
||||
shiftW = 0;
|
||||
for (var j = 0; j < this._lay[i].length; ++j) {
|
||||
for (var k = 0; k < this._lay[i][j].length; ++k) {
|
||||
var e = this._lay[i][j][k];
|
||||
var child = e.child;
|
||||
if (positioned.indexOf(child) === -1) {
|
||||
var tWidth = 0;
|
||||
var tHeight = 0;
|
||||
var s;
|
||||
for (s = 0; s < e.colspan; ++s) {
|
||||
tWidth += this._cols[j + s].cur;
|
||||
}
|
||||
for (s = 0; s < e.rowspan; ++s) {
|
||||
tHeight += this._rows[i + s].cur;
|
||||
}
|
||||
child.setSize(tWidth, tHeight);
|
||||
|
||||
switch (e.a) {
|
||||
case Layout.Aligment.LeftTop:
|
||||
child.setTop(shiftH);
|
||||
child.setLeft(shiftW);
|
||||
break;
|
||||
case Layout.Aligment.LeftCenter:
|
||||
child.setTop(shiftH + (tHeight - child._h) / 2);
|
||||
child.setLeft(shiftW);
|
||||
break;
|
||||
case Layout.Aligment.LeftBottom:
|
||||
child.setTop(shiftH + (tHeight - child._h));
|
||||
child.setLeft(shiftW);
|
||||
break;
|
||||
case Layout.Aligment.CenterTop:
|
||||
child.setTop(shiftH);
|
||||
child.setLeft(shiftW + (tWidth - child._w) / 2);
|
||||
break;
|
||||
case Layout.Aligment.CenterCenter:
|
||||
child.setTop(shiftH + (tHeight - child._h) / 2);
|
||||
child.setLeft(shiftW + (tWidth - child._w) / 2);
|
||||
break;
|
||||
case Layout.Aligment.CenterBottom:
|
||||
child.setTop(shiftH + (tHeight - child._h));
|
||||
child.setLeft((tWidth - child._w) / 2);
|
||||
break;
|
||||
case Layout.Aligment.RightTop:
|
||||
child.setTop(shiftH);
|
||||
child.setLeft(shiftW + (tWidth - child._h));
|
||||
break;
|
||||
case Layout.Aligment.RightCenter:
|
||||
child.setTop((tHeight - child._h) / 2);
|
||||
child.setLeft(shiftW + (tWidth - child._h));
|
||||
break;
|
||||
case Layout.Aligment.RightBottom:
|
||||
child.setTop(shiftH + (tHeight - child._h));
|
||||
child.setLeft(shiftW + (tWidth - child._h));
|
||||
break;
|
||||
|
||||
}
|
||||
positioned.push(child);
|
||||
}
|
||||
}
|
||||
shiftW += this._cols[j].cur;
|
||||
}
|
||||
shiftH += this._rows[i].cur;
|
||||
}
|
||||
},
|
||||
"_recountLimits": function() {
|
||||
this._cols = [];
|
||||
this._rows = [];
|
||||
var i, j;
|
||||
var multiCols = [];
|
||||
var multiRows = [];
|
||||
var proccessed = Object.create(null);
|
||||
|
||||
for (i = 0; i < this._lay.length; ++i) {
|
||||
while (!this._rows[i]) {
|
||||
this._rows.push({});
|
||||
}
|
||||
for (j = 0; j < this._lay[i].length; ++j) {
|
||||
while (!this._cols[j]) {
|
||||
this._cols.push({});
|
||||
}
|
||||
for (var k = 0; k < this._lay[i][j].length; ++k) {
|
||||
var e = this._lay[i][j][k];
|
||||
|
||||
if (proccessed[e.child._id]) {
|
||||
this._cols[j].min = this._cols[j].min || 0;
|
||||
this._rows[i].min = this._rows[i].min || 0;
|
||||
this._cols[j].max = this._cols[j].max || 0;
|
||||
this._rows[i].max = this._rows[i].max || 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
var colMinW = this._cols[j].min || 0;
|
||||
var rowMinH = this._rows[i].min || 0;
|
||||
var colMaxW = this._cols[j].max || Infinity;
|
||||
var rowMaxH = this._rows[i].max || Infinity;
|
||||
|
||||
if (e.colspan === 1) {
|
||||
this._cols[j].min = Math.max(colMinW, e.child._o.minWidth);
|
||||
this._cols[j].max = Math.min(colMaxW, e.child._o.maxWidth);
|
||||
} else {
|
||||
this._cols[j].min = colMinW;
|
||||
this._cols[j].max = colMaxW;
|
||||
|
||||
multiCols.push({
|
||||
p: j,
|
||||
e: e
|
||||
});
|
||||
}
|
||||
if (e.rowspan === 1) {
|
||||
this._rows[i].min = Math.max(rowMinH, e.child._o.minHeight);
|
||||
this._rows[i].max = Math.min(rowMaxH, e.child._o.maxHeight);
|
||||
} else {
|
||||
this._rows[i].min = rowMinH;
|
||||
this._rows[i].max = rowMaxH;
|
||||
|
||||
multiRows.push({
|
||||
p: i,
|
||||
e: e
|
||||
});
|
||||
}
|
||||
|
||||
proccessed[e.child._id] = true;
|
||||
}
|
||||
if (!this._lay[i][j].length) {
|
||||
this._cols[j].min = this._cols[j].min || 0;
|
||||
this._rows[i].min = this._rows[i].min || 0;
|
||||
this._cols[j].max = this._cols[j].max || 0;
|
||||
this._rows[i].max = this._rows[i].max || 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < multiCols.length; ++i) {
|
||||
var e = multiCols[i].e;
|
||||
var pos = multiCols[i].p;
|
||||
var span = e.colspan;
|
||||
var target = pos + span;
|
||||
var minSize = 0;
|
||||
var maxSize = 0;
|
||||
for (j = pos; j < target; ++j) {
|
||||
minSize += this._cols[j].min;
|
||||
maxSize += this._cols[j].max;
|
||||
}
|
||||
if (e.child._o.minWidth > minSize) {
|
||||
var portion = (e.child._o.minWidth - minSize) / span;
|
||||
for (j = pos; j < target; ++j) {
|
||||
this._cols[j].min += portion;
|
||||
}
|
||||
}
|
||||
if (e.child._o.maxWidth < maxSize) {
|
||||
var portion = (maxSize - e.child._o.maxWidth) / span;
|
||||
for (j = pos; j < target; ++j) {
|
||||
this._cols[j].max -= portion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < multiRows.length; ++i) {
|
||||
var e = multiRows[i].e;
|
||||
var pos = multiRows[i].p;
|
||||
var span = e.rowspan;
|
||||
var target = pos + span;
|
||||
var minSize = 0;
|
||||
var maxSize = 0;
|
||||
for (j = pos; j < target; ++j) {
|
||||
minSize += this._rows[j].min;
|
||||
maxSize += this._rows[j].max;
|
||||
}
|
||||
if (e.child._o.minHeight > minSize) {
|
||||
var portion = (e.child._o.minHeight - minSize) / span;
|
||||
for (j = pos; j < target; ++j) {
|
||||
this._rows[j].min += portion;
|
||||
}
|
||||
}
|
||||
if (e.child._o.maxHeight < maxSize) {
|
||||
var portion = (maxSize - e.child._o.maxHeight) / span;
|
||||
for (j = pos; j < target; ++j) {
|
||||
this._rows[j].max -= portion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var minWidth = 0;
|
||||
var minHeight = 0;
|
||||
var maxWidth = 0;
|
||||
var maxHeight = 0;
|
||||
|
||||
for (i = 0; i < this._rows.length; ++i) {
|
||||
minHeight += this._rows[i].min;
|
||||
this._rows[i].max = Math.max(this._rows[i].max, this._rows[i].min);
|
||||
maxHeight += this._rows[i].max;
|
||||
}
|
||||
for (i = 0; i < this._cols.length; ++i) {
|
||||
minWidth += this._cols[i].min;
|
||||
this._cols[i].max = Math.max(this._cols[i].max, this._cols[i].min);
|
||||
maxWidth += this._cols[i].max;
|
||||
}
|
||||
|
||||
return this._setLimits(minWidth, minHeight, maxWidth, maxHeight);
|
||||
},
|
||||
"refreshLay": function() {
|
||||
var totalMaxW = 0;
|
||||
var totalMaxH = 0;
|
||||
var totalMinW = 0;
|
||||
var totalMinH = 0;
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this._cols.length; ++i) {
|
||||
totalMaxW += this._cols[i].max;
|
||||
totalMinW += this._cols[i].min
|
||||
}
|
||||
for (i = 0; i < this._rows.length; ++i) {
|
||||
totalMaxH += this._rows[i].max;
|
||||
totalMinH += this._rows[i].min;
|
||||
}
|
||||
|
||||
if (this._w <= totalMinW || this._w >= totalMaxW) {
|
||||
var kW;
|
||||
var keyW;
|
||||
if (this._w <= totalMinW) {
|
||||
kW = this._w / totalMinW;
|
||||
keyW = "min";
|
||||
} else {
|
||||
kW = this._w / totalMaxW;
|
||||
keyW = "max";
|
||||
}
|
||||
|
||||
for (i = 0; i < this._cols.length; ++i) {
|
||||
this._cols[i].cur = this._cols[i][keyW] * kW;
|
||||
}
|
||||
} else {
|
||||
distribute(this._w, this._cols);
|
||||
}
|
||||
|
||||
if (this._h <= totalMinH || this._h >= totalMaxH) {
|
||||
var kH;
|
||||
var keyH;
|
||||
if (this._h <= totalMinH) {
|
||||
kH = this._h / totalMinH;
|
||||
keyH = "min";
|
||||
} else {
|
||||
kH = this._h / totalMaxH;
|
||||
keyH = "max";
|
||||
}
|
||||
|
||||
for (i = 0; i < this._rows.length; ++i) {
|
||||
this._rows[i].cur = this._rows[i][keyH] * kH;
|
||||
}
|
||||
} else {
|
||||
distribute(this._h, this._rows);
|
||||
}
|
||||
this._positionElements();
|
||||
},
|
||||
"removeChild": function(child) {
|
||||
Layout.fn.removeChild.call(this, child);
|
||||
|
||||
for (var i = 0; i < this._lay.length; ++i) {
|
||||
for (var j = 0; j < this._lay[i].length; ++j) {
|
||||
for (var k = 0; k < this._lay[i][j].length; ++k) {
|
||||
if (child === this._lay[i][j][k].child) {
|
||||
this._lay[i][j].splice(k, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._cleanupLay();
|
||||
this._recountLimits();
|
||||
this.refreshLay();
|
||||
},
|
||||
"setSize": function(w, h) {
|
||||
View.fn.setSize.call(this, w, h);
|
||||
|
||||
if (this._c.length) {
|
||||
this.refreshLay();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function distribute (size, array) {
|
||||
var i, portion;
|
||||
var cMax = [];
|
||||
for (i = 0; i < array.length; ++i) {
|
||||
array[i].cur = array[i].min;
|
||||
size -= array[i].min;
|
||||
|
||||
if (array[i].cur < array[i].max) {
|
||||
cMax.push(array[i]);
|
||||
}
|
||||
}
|
||||
cMax.sort(GridLayout._candidatesSortMax);
|
||||
|
||||
while (cMax.length && size) {
|
||||
portion = size / cMax.length;
|
||||
var last = cMax[cMax.length -1];
|
||||
|
||||
if (portion >= last.max) {
|
||||
size -= last.max - last.cur;
|
||||
last.cur = last.max;
|
||||
cMax.pop();
|
||||
} else {
|
||||
for (i = 0; i < cMax.length; ++i) {
|
||||
cMax[i].cur += portion;
|
||||
}
|
||||
size = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (size) {
|
||||
portion = size / array.length;
|
||||
for (i = 0; i < array.length; ++i) {
|
||||
array.cur += portion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GridLayout._candidatesSortMax = function(a, b) {
|
||||
return b.max - a.max;
|
||||
}
|
||||
|
||||
return GridLayout;
|
||||
});
|
||||
})();
|
4
lorgar/views/helpers/CMakeLists.txt
Normal file
4
lorgar/views/helpers/CMakeLists.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
cmake_minimum_required(VERSION 2.8.12)
|
||||
|
||||
configure_file(scrollable.js scrollable.js)
|
||||
configure_file(draggable.js draggable.js)
|
148
lorgar/views/helpers/draggable.js
Normal file
148
lorgar/views/helpers/draggable.js
Normal file
|
@ -0,0 +1,148 @@
|
|||
"use strict";
|
||||
(function draggable_js() {
|
||||
var moduleName = "views/helpers/draggable";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("lib/utils/subscribable");
|
||||
|
||||
define(moduleName, defineArray, function draggable_module() {
|
||||
var Subscribable = require("lib/utils/subscribable");
|
||||
|
||||
var Draggable = Subscribable.inherit({
|
||||
"className": "Draggable",
|
||||
"constructor": function Draggable (view, options) {
|
||||
var base = {
|
||||
snapDistance: 0
|
||||
};
|
||||
W.extend(base, options);
|
||||
Subscribable.fn.constructor.call(this, base);
|
||||
|
||||
this._o = base;
|
||||
this._e = view._e;
|
||||
this._v = view;
|
||||
this._v.addClass("draggable");
|
||||
|
||||
this._initProxy();
|
||||
this._dragging = false;
|
||||
this._toFlush = false;
|
||||
|
||||
this._x = 0;
|
||||
this._y = 0;
|
||||
|
||||
this._e.addEventListener("mousedown", this._proxy.onMouseDown, false);
|
||||
this._e.addEventListener("touchstart", this._touch, false);
|
||||
this._e.addEventListener("touchmove", this._touch, false);
|
||||
this._e.addEventListener("touchend", this._touch, false);
|
||||
},
|
||||
"destructor": function () {
|
||||
if (this._dragging) {
|
||||
window.removeEventListener("mouseup", this._proxy.onMouseUp);
|
||||
window.removeEventListener("mousemove", this._proxy.onMouseMove);
|
||||
}
|
||||
|
||||
if (!this._v.destroying) {
|
||||
this._v.removeClass("draggable");
|
||||
}
|
||||
|
||||
this._e.removeEventListener("mousedown", this._proxy.onMouseDown);
|
||||
this._e.removeEventListener("touchstart", this._touch);
|
||||
this._e.removeEventListener("touchmove", this._touch);
|
||||
this._e.removeEventListener("touchend", this._touch);
|
||||
|
||||
Subscribable.fn.destructor.call(this);
|
||||
},
|
||||
"_initProxy": function () {
|
||||
this._proxy = {
|
||||
"onMouseDown": this._onMouseDown.bind(this),
|
||||
"onMouseUp": this._onMouseUp.bind(this),
|
||||
"onMouseMove": this._onMouseMove.bind(this)
|
||||
}
|
||||
},
|
||||
"_onMouseDown": function (e) {
|
||||
if (e.which === 1) {
|
||||
window.addEventListener("mouseup", this._proxy.onMouseUp);
|
||||
window.addEventListener("mousemove", this._proxy.onMouseMove);
|
||||
lorgar._body.addClass("non-selectable");
|
||||
this._x = e.pageX;
|
||||
this._y = e.pageY;
|
||||
}
|
||||
},
|
||||
"_onMouseMove": function (e) {
|
||||
var x = e.pageX - this._x;
|
||||
var y = e.pageY - this._y;
|
||||
|
||||
if (this._dragging) {
|
||||
this._v.trigger("drag", {
|
||||
x: x,
|
||||
y: y
|
||||
});
|
||||
} else {
|
||||
var absX = Math.abs(x);
|
||||
var absY = Math.abs(y);
|
||||
|
||||
if (absX > this._o.snapDistance || absY > this._o.snapDistance) {
|
||||
this._dragging = true;
|
||||
lorgar._body.addClass("dragging");
|
||||
this._v.trigger("dragStart", {
|
||||
x: x,
|
||||
y: y
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
"_onMouseUp": function (e) {
|
||||
window.removeEventListener("mouseup", this._proxy.onMouseUp);
|
||||
window.removeEventListener("mousemove", this._proxy.onMouseMove);
|
||||
|
||||
this._x = 0;
|
||||
this._y = 0;
|
||||
lorgar._body.removeClass("non-selectable");
|
||||
if (this._dragging) {
|
||||
e.preventDefault();
|
||||
this._dragging = false;
|
||||
lorgar._body.removeClass("dragging");
|
||||
this._v.trigger("dragEnd");
|
||||
return false;
|
||||
}
|
||||
},
|
||||
"_touch": function (e) {
|
||||
e.preventDefault();
|
||||
if (e.touches.length > 1 || (e.type == "touchend" && e.touches.length > 0))
|
||||
return;
|
||||
|
||||
var type = null;
|
||||
var touch = null;
|
||||
var src = e.currentTarget;
|
||||
switch (e.type) {
|
||||
case "touchstart":
|
||||
type = "mousedown";
|
||||
touch = e.changedTouches[0];
|
||||
|
||||
break;
|
||||
case "touchmove":
|
||||
type = "mousemove";
|
||||
touch = e.changedTouches[0];
|
||||
src = window;
|
||||
break;
|
||||
case "touchend":
|
||||
type = "mouseup";
|
||||
touch = e.changedTouches[0];
|
||||
src = window;
|
||||
break;
|
||||
}
|
||||
|
||||
var event = new MouseEvent(type, {
|
||||
button: 0,
|
||||
screenX: touch.screenX,
|
||||
screenY: touch.screenY,
|
||||
clientX: touch.clientX,
|
||||
clientY: touch.clientY
|
||||
});
|
||||
src.dispatchEvent(event);
|
||||
}
|
||||
});
|
||||
|
||||
return Draggable;
|
||||
});
|
||||
})();
|
222
lorgar/views/helpers/scrollable.js
Normal file
222
lorgar/views/helpers/scrollable.js
Normal file
|
@ -0,0 +1,222 @@
|
|||
"use strict";
|
||||
(function scrollable_js() {
|
||||
var moduleName = "views/helpers/scrollable";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("lib/wController/localModel");
|
||||
|
||||
define(moduleName, defineArray, function scrollable_module() {
|
||||
var View = require("views/view");
|
||||
var LocalModel = require("lib/wController/localModel");
|
||||
|
||||
var Scrollable = View.inherit({
|
||||
"className": "Scrollable",
|
||||
"constructor": function Scrollable(options, layout) {
|
||||
var base = {
|
||||
draggable: true,
|
||||
snapDistance: 5,
|
||||
vertical: false,
|
||||
horizontal: false,
|
||||
virtual: false
|
||||
};
|
||||
var lm = new LocalModel();
|
||||
W.extend(base, options);
|
||||
View.fn.constructor.call(this, lm, base);
|
||||
|
||||
this._l = layout;
|
||||
this._l._e.appendChild(this._e);
|
||||
this._horizontalBar = document.createElement("div");
|
||||
this._verticalBar = document.createElement("div");
|
||||
this._horizontalBarShown = false;
|
||||
this._verticalBarShown = false;
|
||||
|
||||
this._initProxy();
|
||||
this._initBars();
|
||||
|
||||
this._e.addEventListener("mousewheel", this._proxy.onMouseWheel, false);
|
||||
|
||||
if (this._o.draggable) {
|
||||
this.on("dragStart", this._onDragStart, this);
|
||||
this.on("drag", this._onDrag, this);
|
||||
this.on("dragEnd", this._onDragEnd, this);
|
||||
}
|
||||
|
||||
this._uncyclic.push(function() {
|
||||
lm.destructor();
|
||||
})
|
||||
},
|
||||
"destructor": function() {
|
||||
this._e.removeEventListener("mousewheel", this._proxy.onMouseWheel, false);
|
||||
this._l._e.removeChild(this._e);
|
||||
if (this._horizontalBarShown) {
|
||||
this._l._e.removeChild(this._horizontalBar);
|
||||
}
|
||||
if (this._verticalBarShown) {
|
||||
this._l._e.removeChild(this._verticalBar);
|
||||
}
|
||||
|
||||
View.fn.destructor.call(this);
|
||||
},
|
||||
"appendChild": function(e) {
|
||||
this._e.appendChild(e);
|
||||
},
|
||||
"_initBars": function() {
|
||||
this._horizontalBar.style.position = "absolute";
|
||||
this._horizontalBar.style.left = "0";
|
||||
this._horizontalBar.style.bottom = "0";
|
||||
this._horizontalBar.style.height = "10px";
|
||||
this._horizontalBar.style.width = "0";
|
||||
this._horizontalBar.style.zIndex = "2";
|
||||
this._horizontalBar.style.backgroundColor = Scrollable.theme.primaryColor || "#ff0000";
|
||||
|
||||
this._verticalBar.style.position = "absolute";
|
||||
this._verticalBar.style.right = "0";
|
||||
this._verticalBar.style.top = "0";
|
||||
this._verticalBar.style.height = "0";
|
||||
this._verticalBar.style.width = "10px";
|
||||
this._verticalBar.style.zIndex = "2";
|
||||
this._verticalBar.style.backgroundColor = Scrollable.theme.primaryColor || "#ff0000";
|
||||
},
|
||||
"_initProxy": function() {
|
||||
this._proxy = {
|
||||
onMouseWheel: this._onMouseWheel.bind(this)
|
||||
};
|
||||
},
|
||||
"insertBefore": function(e, other) {
|
||||
this._e.insertBefore(e, other);
|
||||
},
|
||||
"maximizeMinSize": function(child) {
|
||||
var width = Math.max(this._o.minWidth, child._o.minWidth);
|
||||
var height = Math.max(this._o.minHeight, child._o.minHeight);
|
||||
|
||||
this.setMinSize(width, height);
|
||||
},
|
||||
"_onDrag": function(pos) {
|
||||
var oX = this._o.horizontal ? pos.x : 0;
|
||||
var oY = this._o.vertical ? pos.y : 0;
|
||||
|
||||
var aX = this._sX + oX;
|
||||
var aY = this._sY + oY;
|
||||
|
||||
var cX = Math.max(Math.min(0, aX), this._l._w - this._w);
|
||||
var cY = Math.max(Math.min(0, aY), this._l._h - this._h);
|
||||
|
||||
this.setTop(cY);
|
||||
this.setLeft(cX);
|
||||
},
|
||||
"_onDragEnd": function(pos) {
|
||||
//console.log("end")
|
||||
},
|
||||
"_onDragStart": function(pos) {
|
||||
this._sX = this._x;
|
||||
this._sY = this._y;
|
||||
//console.log("start");
|
||||
},
|
||||
"_onMouseWheel": function(e) {
|
||||
var dX = this._o.horizontal ? e.deltaX : 0;
|
||||
var dY = this._o.vertical ? e.deltaY : 0;
|
||||
|
||||
var aX = this._x + dX;
|
||||
var aY = this._y - dY;
|
||||
|
||||
var cX = Math.max(Math.min(0, aX), this._l._w - this._w);
|
||||
var cY = Math.max(Math.min(0, aY), this._l._h - this._h);
|
||||
|
||||
this.setTop(cY);
|
||||
this.setLeft(cX);
|
||||
},
|
||||
"removeChild": function(e) {
|
||||
this._e.removeChild(e);
|
||||
},
|
||||
"_resetTheme": function() {
|
||||
View.fn._resetTheme.call(this);
|
||||
|
||||
this._horizontalBar.style.backgroundColor = Scrollable.theme.primaryColor || "#ff0000";
|
||||
this._verticalBar.style.backgroundColor = Scrollable.theme.primaryColor || "#ff0000";
|
||||
},
|
||||
"setLeft": function(x) {
|
||||
if (this._x !== x) {
|
||||
if (this._o.virtual) {
|
||||
this._x = x;
|
||||
this._e.style.left = "0px";
|
||||
} else {
|
||||
View.fn.setLeft.call(this, x);
|
||||
}
|
||||
if (x === 0) {
|
||||
this.trigger("scrollLeft", 0);
|
||||
} else {
|
||||
this.trigger("scrollLeft", -x);
|
||||
}
|
||||
|
||||
this._horizontalBar.style.top = this._x / this._w * this._l._w + "px";
|
||||
}
|
||||
},
|
||||
"setSize": function(w, h) {
|
||||
if (this._o.virtual) {
|
||||
this._w = this.constrainWidth(w);
|
||||
this._h = this.constrainHeight(h);
|
||||
|
||||
this._e.style.width = w + "px";
|
||||
this._e.style.height = h + "px";
|
||||
|
||||
this.trigger("resize", this._w, this._h);
|
||||
} else {
|
||||
View.fn.setSize.call(this, w, h);
|
||||
}
|
||||
|
||||
if (this._w > this._l._w) {
|
||||
var width = this._l._w / this._w * this._l._w;
|
||||
var wOffset = this._x / this._w * this._l._w;
|
||||
|
||||
this._horizontalBar.style.width = width + "px";
|
||||
this._horizontalBar.style.left = wOffset + "px";
|
||||
|
||||
if (!this._horizontalBarShown) {
|
||||
this._l._e.appendChild(this._horizontalBar);
|
||||
this._horizontalBarShown = true;
|
||||
}
|
||||
} else if (this._horizontalBarShown) {
|
||||
this._l._e.removeChild(this._horizontalBar);
|
||||
this._horizontalBarShown = false;
|
||||
}
|
||||
|
||||
if (this._h > this._l._h) {
|
||||
var height = this._l._h / this._h * this._l._h;
|
||||
var hOffset = -this._y / this._h * this._l._h;
|
||||
|
||||
this._verticalBar.style.height = height + "px";
|
||||
this._verticalBar.style.top = hOffset + "px";
|
||||
|
||||
if (!this._verticalBarShown) {
|
||||
this._l._e.appendChild(this._verticalBar);
|
||||
this._verticalBarShown = true;
|
||||
}
|
||||
} else if (this._verticalBarShown) {
|
||||
this._l._e.removeChild(this._verticalBar);
|
||||
this._verticalBarShown = false;
|
||||
}
|
||||
},
|
||||
"setTop": function(y) {
|
||||
if (this._y !== y) {
|
||||
if (this._o.virtual) {
|
||||
this._y = y;
|
||||
this._e.style.top = "0px";
|
||||
} else {
|
||||
View.fn.setTop.call(this, y);
|
||||
}
|
||||
if (y === 0) {
|
||||
this.trigger("scrollTop", 0);
|
||||
} else {
|
||||
this.trigger("scrollTop", -y);
|
||||
}
|
||||
|
||||
|
||||
this._verticalBar.style.top = -this._y / this._h * this._l._h + "px";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Scrollable;
|
||||
});
|
||||
})();
|
35
lorgar/views/image.js
Normal file
35
lorgar/views/image.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
"use strict";
|
||||
(function() {
|
||||
var moduleName = "views/image";
|
||||
|
||||
var deps = [];
|
||||
deps.push("views/view");
|
||||
|
||||
define(moduleName, deps, function() {
|
||||
var View = require("views/view");
|
||||
|
||||
var Image = View.inherit({
|
||||
"className": "Image",
|
||||
"constructor": function(controller, options) {
|
||||
var base = {};
|
||||
W.extend(base, options)
|
||||
var el = document.createElement("img");
|
||||
View.fn.constructor.call(this, controller, base, el);
|
||||
|
||||
controller.needData();
|
||||
},
|
||||
"destructor": function() {
|
||||
this._f.dontNeedData();
|
||||
|
||||
View.fn.destructor.call(this);
|
||||
},
|
||||
"_onData": function() {
|
||||
if (this._f.hasData()) {
|
||||
this._e.src = "data:" + this._f.getMimeType() + ";base64," + this._f.data.base64();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Image;
|
||||
})
|
||||
})();
|
88
lorgar/views/label.js
Normal file
88
lorgar/views/label.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
"use strict";
|
||||
(function view_label_js() {
|
||||
var moduleName = "views/label";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("lib/fonts/Liberation");
|
||||
|
||||
define(moduleName, defineArray, function view_label_module() {
|
||||
var View = require("views/view");
|
||||
|
||||
var Label = View.inherit({
|
||||
"className": "Label",
|
||||
"constructor": function(controller, options) {
|
||||
var base = {};
|
||||
W.extend(base, options)
|
||||
View.fn.constructor.call(this, controller, base);
|
||||
|
||||
this._timeout = undefined;
|
||||
this._recalculationScheduled = false;
|
||||
|
||||
this._e.innerText = this._f.data || "";
|
||||
if (this._f.data !== "") {
|
||||
this._scheduleRecalculation();
|
||||
}
|
||||
},
|
||||
"destructor": function() {
|
||||
if (this._recalculationScheduled) {
|
||||
clearTimeout(this._timeout);
|
||||
}
|
||||
|
||||
View.fn.destructor.call(this);
|
||||
},
|
||||
"_onAddProperty": function(key, propertyName) {
|
||||
View.fn._onAddProperty.call(this, key, propertyName);
|
||||
|
||||
if (sizeChangingProperties.indexOf(propertyName) !== -1) {
|
||||
this._scheduleRecalculation();
|
||||
}
|
||||
},
|
||||
"_onData": function() {
|
||||
if (this._e.innerText !== this._f.data) {
|
||||
this._e.innerText = this._f.data || "";
|
||||
this._scheduleRecalculation();
|
||||
}
|
||||
},
|
||||
"_recalculateSize": function() {
|
||||
var fs = parseFloat(this._e.style.fontSize) || 16;
|
||||
var fontFamily = this._e.style.fontFamily || "Liberation";
|
||||
|
||||
var h = fs + 2;
|
||||
var w = Label.calculateSingleString(fontFamily, fs, this._f.data || "");
|
||||
this.setConstSize(w, h);
|
||||
this._recalculationScheduled = false;
|
||||
},
|
||||
"_scheduleRecalculation": function() {
|
||||
if (!this._recalculationScheduled) {
|
||||
this._timeout = setTimeout(this._recalculateSize.bind(this), 10);
|
||||
this._recalculationScheduled = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var sizeChangingProperties = ["fontSize", "fontFamily", "whiteSpace"];
|
||||
|
||||
Label.calculateSingleString = function(family, size, string) {
|
||||
var fontStorage = Label.fonts[family] || Label.fonts["Liberation"];
|
||||
|
||||
var width = 0;
|
||||
var mul = size / fontStorage.unitsPerEm;
|
||||
var aw = fontStorage.advanceWidthArray;
|
||||
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
var letter = string.charCodeAt(i);
|
||||
var l = aw[letter] || 1536;
|
||||
width += (l * mul);
|
||||
}
|
||||
|
||||
return Math.ceil(width);
|
||||
};
|
||||
|
||||
Label.fonts = {
|
||||
Liberation: require("lib/fonts/Liberation")
|
||||
};
|
||||
|
||||
return Label;
|
||||
});
|
||||
})();
|
242
lorgar/views/layout.js
Normal file
242
lorgar/views/layout.js
Normal file
|
@ -0,0 +1,242 @@
|
|||
"use strict";
|
||||
(function layout_js() {
|
||||
var moduleName = "views/layout";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("views/helpers/scrollable");
|
||||
|
||||
define(moduleName, defineArray, function layout_module() {
|
||||
var View = require("views/view");
|
||||
var Scrollable = require("views/helpers/scrollable");
|
||||
|
||||
var Layout = View.inherit({
|
||||
"className": "Layout",
|
||||
"constructor": function(controller, options) {
|
||||
var base = {
|
||||
scrollable: Layout.Scroll.None
|
||||
};
|
||||
W.extend(base, options);
|
||||
var element = document.createElement("div");
|
||||
View.fn.constructor.call(this, controller, base, element);
|
||||
|
||||
this._c = [];
|
||||
|
||||
if (this._o.scrollable) {
|
||||
this._scr = new Scrollable({
|
||||
vertical: !!(this._o.scrollable & 1),
|
||||
horizontal: !!(this._o.scrollable & 2),
|
||||
virtual: !!(this._o.scrollable & 4)
|
||||
}, this);
|
||||
}
|
||||
},
|
||||
"destructor": function() {
|
||||
this._destroying = true;
|
||||
this.clear();
|
||||
if (this._o.scrollable) {
|
||||
this._scr.destructor();
|
||||
}
|
||||
|
||||
View.fn.destructor.call(this);
|
||||
},
|
||||
"_addChild": function(child, aligment, index) {
|
||||
aligment = aligment || 1;
|
||||
var item = {
|
||||
c: child,
|
||||
a: aligment
|
||||
}
|
||||
if (index !== undefined) {
|
||||
this._c.splice(index, 0, item);
|
||||
} else {
|
||||
this._c.push(item);
|
||||
}
|
||||
child.remove();
|
||||
if (this._o.scrollable) {
|
||||
if (index === undefined || this._c[index + 1] === undefined) {
|
||||
this._scr.appendChild(child._e);
|
||||
} else {
|
||||
this._scr.insertBefore(child._e, this._c[index + 1].c._e);
|
||||
}
|
||||
} else {
|
||||
if (index === undefined || this._c[index + 1] === undefined) {
|
||||
this._e.appendChild(child._e);
|
||||
} else {
|
||||
this._e.insertBefore(child._e, this._c[index + 1].c._e);
|
||||
}
|
||||
}
|
||||
child._p = this;
|
||||
child.on("changeLimits", this._onChildChangeLimits, this);
|
||||
},
|
||||
"append": function(child, aligment, index) {
|
||||
this._addChild(child, aligment, index)
|
||||
if (this._o.scrollable) {
|
||||
this._scr.maximizeMinSize(child);
|
||||
if (this._w !== undefined && this._h !== undefined) {
|
||||
this._scr.setSize(this._w, this._h);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._w !== undefined && this._h !== undefined) {
|
||||
child.setSize(this._w, this._h);
|
||||
}
|
||||
},
|
||||
"clear": function() {
|
||||
while (this._c.length) {
|
||||
var c = this._c[this._c.length - 1];
|
||||
c.c.destructor();
|
||||
}
|
||||
if (!this._destroying) {
|
||||
if (this._o.scrollable) {
|
||||
this._scr.setMinSize(0, 0);
|
||||
this._scr.setSize(this._w, this._h);
|
||||
}
|
||||
}
|
||||
},
|
||||
"_onChildChangeLimits": function(child) {
|
||||
var i;
|
||||
if (this._o.scrollable) {
|
||||
var w = 0;
|
||||
var h = 0;
|
||||
for (i = 0; i < this._c.length; ++i) {
|
||||
w = Math.max(this._c[i].c._o.minWidth, w);
|
||||
h = Math.max(this._c[i].c._o.minHeight, h);
|
||||
}
|
||||
this._scr.setMinSize(w, h);
|
||||
this._scr.setSize(this._w, this._h);
|
||||
for (i = 0; i < this._c.length; ++i) {
|
||||
this._positionElement(this._c[i]);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < this._c.length; ++i) {
|
||||
if (this._c[i].c === child) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i < this._c.length) {
|
||||
this._positionElement(this._c[i]);
|
||||
}
|
||||
}
|
||||
},
|
||||
"_positionElement": function(e) {
|
||||
var el = e.c;
|
||||
var a = e.a;
|
||||
var h = this._h;
|
||||
var w = this._w;
|
||||
if (this._o.scrollable) {
|
||||
h = this._scr._h;
|
||||
w = this._scr._w;
|
||||
}
|
||||
el.setSize(this._w, this._h);
|
||||
|
||||
switch (a) {
|
||||
case Layout.Aligment.LeftTop:
|
||||
el.setTop(0);
|
||||
el.setLeft(0);
|
||||
break;
|
||||
case Layout.Aligment.LeftCenter:
|
||||
el.setTop((h - el._h) / 2);
|
||||
el.setLeft(0);
|
||||
break;
|
||||
case Layout.Aligment.LeftBottom:
|
||||
el.setTop(h - el._h);
|
||||
el.setLeft(0);
|
||||
break;
|
||||
case Layout.Aligment.CenterTop:
|
||||
el.setTop(0);
|
||||
el.setLeft((w - el._w) / 2)
|
||||
break;
|
||||
case Layout.Aligment.CenterCenter:
|
||||
el.setTop((h - el._h) / 2);
|
||||
el.setLeft((w - el._w) / 2)
|
||||
break;
|
||||
case Layout.Aligment.CenterBottom:
|
||||
el.setTop(h - el._h);
|
||||
el.setLeft((w - el._w) / 2)
|
||||
break;
|
||||
case Layout.Aligment.RightTop:
|
||||
el.setTop(0);
|
||||
el.setLeft(w - el._w)
|
||||
break;
|
||||
case Layout.Aligment.RightCenter:
|
||||
el.setTop((h - el._h) / 2);
|
||||
el.setLeft(w - el._w)
|
||||
break;
|
||||
case Layout.Aligment.RightBottom:
|
||||
el.setTop(h - el._h);
|
||||
el.setLeft(w - el._w)
|
||||
break;
|
||||
}
|
||||
},
|
||||
"removeChild": function(child) {
|
||||
var i;
|
||||
for (i = 0; i < this._c.length; ++i) {
|
||||
if (this._c[i].c === child) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i !== this._c.length) {
|
||||
this._removeChildByIndex(i);
|
||||
}
|
||||
},
|
||||
"_removeChildByIndex": function(i) {
|
||||
var child = this._c[i].c;
|
||||
this._c.splice(i, 1);
|
||||
child._p = undefined;
|
||||
|
||||
if (this._o.scrollable) {
|
||||
this._scr.removeChild(child._e);
|
||||
if (!this._destroying) {
|
||||
var w = 0;
|
||||
var h = 0;
|
||||
for (var i = 0; i < this._c.length; ++i) {
|
||||
w = Math.max(this._c[i].c._o.minWidth, w);
|
||||
h = Math.max(this._c[i].c._o.minHeight, h);
|
||||
}
|
||||
this._scr.setMinSize(w, h);
|
||||
this._scr.setSize(this._w, this._h);
|
||||
}
|
||||
} else {
|
||||
this._e.removeChild(child._e);
|
||||
}
|
||||
|
||||
child.off("changeLimits", this._onChildChangeLimits, this);
|
||||
},
|
||||
"setSize": function(w, h) {
|
||||
View.fn.setSize.call(this, w, h);
|
||||
|
||||
if (this._o.scrollable) {
|
||||
this._scr.setSize(this._w, this._h);
|
||||
}
|
||||
|
||||
for (var i = 0; i < this._c.length; ++i) {
|
||||
this._positionElement(this._c[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Layout.Aligment = {
|
||||
"LeftTop": 1,
|
||||
"LeftCenter": 4,
|
||||
"LeftBottom": 7,
|
||||
"CenterTop": 2,
|
||||
"CenterCenter": 5,
|
||||
"CenterBottom": 8,
|
||||
"RightTop": 3,
|
||||
"RightCenter": 6,
|
||||
"RightBottom": 9
|
||||
};
|
||||
|
||||
Layout.Scroll = {
|
||||
"None": 0,
|
||||
"Vertical": 1,
|
||||
"Horizontal": 2,
|
||||
"Both": 3,
|
||||
"Virtual": 4,
|
||||
"VirtualVertical": 5,
|
||||
"VirtualHorizontal": 6,
|
||||
"VirtualBoth": 7
|
||||
}
|
||||
|
||||
return Layout;
|
||||
});
|
||||
})();
|
51
lorgar/views/mainLayout.js
Normal file
51
lorgar/views/mainLayout.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
(function mainLayout_js() {
|
||||
var moduleName = "views/mainLayout";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/gridLayout");
|
||||
defineArray.push("views/label");
|
||||
defineArray.push("views/navigationPanel");
|
||||
defineArray.push("views/layout");
|
||||
defineArray.push("lib/wController/localModel");
|
||||
|
||||
define(moduleName, defineArray, function mainLayout_module() {
|
||||
var GridLayout = require("views/gridLayout");
|
||||
var ViewLabel = require("views/label");
|
||||
var ViewNavigationPanel = require("views/navigationPanel");
|
||||
var Layout = require("views/layout");
|
||||
var LocalModel = require("lib/wController/localModel");
|
||||
|
||||
var MainLayout = GridLayout.inherit({
|
||||
"className": "MainLayout",
|
||||
"_onNewController": function(controller) {
|
||||
GridLayout.fn._onNewController.call(this, controller);
|
||||
|
||||
var view;
|
||||
|
||||
switch (controller.name) {
|
||||
case "version":
|
||||
var lm = new LocalModel({
|
||||
backgroundColor: "secondaryColor"
|
||||
});
|
||||
var lay = new Layout(lm, {maxHeight: 15})
|
||||
view = new ViewLabel(controller);
|
||||
lay.append(view, Layout.Aligment.RightCenter);
|
||||
this.append(lay, 2, 0, 1, 3);
|
||||
break;
|
||||
case "navigationPanel":
|
||||
view = new ViewNavigationPanel(controller);
|
||||
this.append(view, 0, 0, 1, 3);
|
||||
break;
|
||||
case "themes":
|
||||
break;
|
||||
default:
|
||||
//this.trigger("serviceMessage", "Unsupported view: " + name + " (" + type + ")", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return MainLayout;
|
||||
});
|
||||
})();
|
58
lorgar/views/nav.js
Normal file
58
lorgar/views/nav.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
"use strict";
|
||||
(function nav_js() {
|
||||
var moduleName = "views/nav";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/layout");
|
||||
defineArray.push("views/label");
|
||||
|
||||
define(moduleName, defineArray, function nav_module() {
|
||||
var Layout = require("views/layout");
|
||||
var Label = require("views/label");
|
||||
|
||||
var Nav = Layout.inherit({
|
||||
"className": "Nav",
|
||||
"constructor": function(controller, options) {
|
||||
var base = {
|
||||
"padding": 5
|
||||
};
|
||||
W.extend(base, options);
|
||||
Layout.fn.constructor.call(this, controller, base);
|
||||
|
||||
this._initProxy();
|
||||
|
||||
this._label = new Label(this._f.label);
|
||||
this._label.on("changeLimits", this._onChangeLimits, this);
|
||||
this._onChangeLimits();
|
||||
|
||||
this.append(this._label, Layout.Aligment.CenterCenter);
|
||||
this.addClass("hoverable");
|
||||
|
||||
this._e.addEventListener("click", this._proxy.onClick, false);
|
||||
},
|
||||
"destructor": function() {
|
||||
this._e.removeEventListener("click", this._proxy.onClick, false);
|
||||
|
||||
Layout.fn.destructor.call(this);
|
||||
},
|
||||
"_initProxy": function() {
|
||||
this._proxy = {
|
||||
onClick: this._onClick.bind(this)
|
||||
}
|
||||
},
|
||||
"_onChangeLimits": function() {
|
||||
this._o.minWidth = this._label._o.minWidth + this._o.padding * 2;
|
||||
this._o.maxWidth = this._label._o.maxWidth + this._o.padding * 2;
|
||||
this._o.minHeight = this._label._o.minHeight + this._o.padding * 2;
|
||||
this._o.maxHeight = this._label._o.maxHeight + this._o.padding * 2;
|
||||
|
||||
this.trigger("changeLimits", this);
|
||||
},
|
||||
"_onClick": function(e) {
|
||||
lorgar.changePage(this._f.targetAddress);
|
||||
}
|
||||
});
|
||||
|
||||
return Nav;
|
||||
});
|
||||
})();
|
50
lorgar/views/navigationPanel.js
Normal file
50
lorgar/views/navigationPanel.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
"use strict";
|
||||
(function navigationPanel_js() {
|
||||
var moduleName = "views/navigationPanel";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/gridLayout");
|
||||
defineArray.push("views/nav");
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("lib/wController/localModel");
|
||||
|
||||
define(moduleName, defineArray, function navigationPanel_module() {
|
||||
var GridLayout = require("views/gridLayout");
|
||||
var Nav = require("views/nav");
|
||||
var View = require("views/view");
|
||||
var LocalModel = require("lib/wController/localModel");
|
||||
|
||||
var NavigationPanel = GridLayout.inherit({
|
||||
"className": "NavigationPanel",
|
||||
"constructor": function(controller, options) {
|
||||
var base = {
|
||||
minHeight: 50,
|
||||
maxHeight: 50
|
||||
};
|
||||
W.extend(base, options)
|
||||
GridLayout.fn.constructor.call(this, controller, base);
|
||||
|
||||
this._spacerHelper = new LocalModel();
|
||||
this._spacer = new View(this._spacerHelper);
|
||||
},
|
||||
"destructor": function() {
|
||||
this._spacer.destructor();
|
||||
this._spacerHelper.destructor();
|
||||
|
||||
GridLayout.fn.destructor.call(this);
|
||||
},
|
||||
"clear": function() {
|
||||
this._spacer.remove();
|
||||
GridLayout.fn.clear.call(this);
|
||||
},
|
||||
"_onNewController": function(controller) {
|
||||
this._spacer.remove();
|
||||
var nav = new Nav(controller);
|
||||
this.append(nav, 0, this._c.length, 1, 1);
|
||||
this.append(this._spacer, 0, this._c.length, 1, 1);
|
||||
}
|
||||
});
|
||||
|
||||
return NavigationPanel;
|
||||
});
|
||||
})();
|
90
lorgar/views/page.js
Normal file
90
lorgar/views/page.js
Normal file
|
@ -0,0 +1,90 @@
|
|||
"use strict";
|
||||
(function() {
|
||||
var moduleName = "views/page";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/gridLayout");
|
||||
defineArray.push("lib/wType/address");
|
||||
defineArray.push("lib/wContainer/abstractmap");
|
||||
|
||||
define(moduleName, defineArray, function() {
|
||||
var GridLayout = require("views/gridLayout");
|
||||
var Address = require("lib/wType/address");
|
||||
var AbstractMap = require("lib/wContainer/abstractmap");
|
||||
|
||||
var ContentMap = AbstractMap.template(Address, Object);
|
||||
|
||||
var Page = GridLayout.inherit({
|
||||
"className": "Page",
|
||||
"constructor": function(f, options) {
|
||||
var base = {};
|
||||
|
||||
W.extend(base, options);
|
||||
GridLayout.fn.constructor.call(this, f, base);
|
||||
|
||||
this._map = new ContentMap(false);
|
||||
|
||||
this._f.on("addItem", this._onAddItem, this);
|
||||
this._f.on("removeItem", this._onRemoveItem, this);
|
||||
this._f.on("clear", this.clear, this);
|
||||
|
||||
var end = this._f.data.end();
|
||||
for (var itr = this._f.data.begin(); !itr["=="](end); itr["++"]()) {
|
||||
var pair = itr["*"]();
|
||||
this._onAddItem(pair.first, pair.second);
|
||||
}
|
||||
},
|
||||
"destructor": function() {
|
||||
this._f.off("addItem", this._onAddItem, this);
|
||||
this._f.off("removeItem", this._onRemoveItem, this);
|
||||
this._f.off("clear", this.clear, this);
|
||||
|
||||
this._map.destructor();
|
||||
delete this._map;
|
||||
|
||||
GridLayout.fn.destructor.call(this);
|
||||
},
|
||||
"clear": function() {
|
||||
GridLayout.fn.clear.call(this);
|
||||
|
||||
if (this._map) {
|
||||
this._map.clear();
|
||||
}
|
||||
},
|
||||
"_onAddItem": function(address, element) {
|
||||
var view = Page.createByType(element.viewType, element.controller, element.viewOptions);
|
||||
|
||||
this._map.insert(address, view);
|
||||
|
||||
this.append(view, element.row, element.col, element.rowspan, element.colspan, element.aligment);
|
||||
},
|
||||
"_onRemoveItem": function(address) {
|
||||
var itr = this._map.find(address);
|
||||
var pair = itr["*"]();
|
||||
|
||||
this.removeChild(pair.second);
|
||||
pair.second.destructor();
|
||||
|
||||
this._map.erase(itr);
|
||||
},
|
||||
"_setLimits": function(minWidth, minHeight, maxWidth, maxHeight) {
|
||||
var needToTell = false;
|
||||
if (this._o.minWidth !== minWidth) {
|
||||
needToTell = true;
|
||||
this._o.minWidth = minWidth;
|
||||
}
|
||||
if (this._o.minHeight !== minHeight) {
|
||||
needToTell = true;
|
||||
this._o.minHeight = minHeight;
|
||||
}
|
||||
if (needToTell) {
|
||||
this.trigger("changeLimits", this);
|
||||
}
|
||||
|
||||
return needToTell && this._events.changeLimits && this._events.changeLimits.length; //to see if someone actually going to listen that event
|
||||
}
|
||||
});
|
||||
|
||||
return Page;
|
||||
});
|
||||
})()
|
109
lorgar/views/pane.js
Normal file
109
lorgar/views/pane.js
Normal file
|
@ -0,0 +1,109 @@
|
|||
"use strict";
|
||||
|
||||
(function() {
|
||||
var moduleName = "views/pane";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("views/layout");
|
||||
defineArray.push("views/label");
|
||||
defineArray.push("views/image");
|
||||
defineArray.push("lib/wController/localModel");
|
||||
|
||||
define(moduleName, defineArray, function() {
|
||||
var View = require("views/view");
|
||||
var Layout = require("views/layout");
|
||||
var Label = require("views/label");
|
||||
var Image = require("views/image");
|
||||
var LM = require("lib/wController/localModel");
|
||||
|
||||
var Pane = Layout.inherit({
|
||||
"constructor": function PaneView (controller, options) {
|
||||
var base = {
|
||||
|
||||
};
|
||||
W.extend(base, options);
|
||||
Layout.fn.constructor.call(this, controller, options);
|
||||
|
||||
this._initProxy();
|
||||
this.addClass("hoverable");
|
||||
this._e.addEventListener("click", this._proxy.onClick, false);
|
||||
|
||||
var lm = this._labelModel = new LM({
|
||||
fontFamily: "casualFont"
|
||||
});
|
||||
|
||||
if (this._f.hasImage()) {
|
||||
this._image = new Image(this._f.image);
|
||||
this.append(this._image, Layout.Aligment.CenterCenter);
|
||||
}
|
||||
|
||||
var name = this._f.data.at("name");
|
||||
this._labelModel.setData(name || "");
|
||||
this._labelView = new Label(this._labelModel);
|
||||
this._labelView.on("changeLimits", this._onLabelChangeLimits, this);
|
||||
this.append(this._labelView, Layout.Aligment.CenterCenter);
|
||||
|
||||
this._f.on("newElement", this._onNewElement, this);
|
||||
this._f.on("removeElement", this._onRemoveElement, this);
|
||||
|
||||
this._uncyclic.push(function() {
|
||||
lm.destructor();
|
||||
});
|
||||
},
|
||||
"destructor": function() {
|
||||
this._e.removeEventListener("click", this._proxy.onClick, false);
|
||||
|
||||
Layout.fn.destructor.call(this);
|
||||
},
|
||||
"_applyProperties": function() {
|
||||
this._onAddProperty("secondaryColor", "background");
|
||||
|
||||
Layout.fn._applyProperties.call(this);
|
||||
},
|
||||
"_initProxy": function() {
|
||||
this._proxy = {
|
||||
onClick: this._onClick.bind(this)
|
||||
};
|
||||
},
|
||||
"_onClick": function() {
|
||||
if (this._f.data.at("hasPageLink").valueOf() === true) {
|
||||
this.trigger("activate", this._f.data.at("pageLink").clone());
|
||||
}
|
||||
},
|
||||
"_onLabelChangeLimits": function(label) {
|
||||
this.setMinSize(label._o.minWidth, this._h);
|
||||
},
|
||||
"_onNewElement": function(key, value) {
|
||||
switch (key) {
|
||||
case "name":
|
||||
this._labelModel.setData(value.toString());
|
||||
break;
|
||||
case "image":
|
||||
this._image = new Image(this._f.image);
|
||||
this.append(this._image, Layout.Aligment.LeftTop, 0);
|
||||
break;
|
||||
}
|
||||
},
|
||||
"_onRemoveElement": function(key) {
|
||||
switch (key) {
|
||||
case "name":
|
||||
this._labelModel.setData("");
|
||||
break;
|
||||
case "image":
|
||||
this._image.destructor();
|
||||
break;
|
||||
}
|
||||
},
|
||||
"setSize": function(w, h) {
|
||||
Layout.fn.setSize.call(this, w, h);
|
||||
|
||||
if (this._f.hasImage()) {
|
||||
this._image.setSize(w, h);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Pane;
|
||||
});
|
||||
})();
|
189
lorgar/views/panesList.js
Normal file
189
lorgar/views/panesList.js
Normal file
|
@ -0,0 +1,189 @@
|
|||
"use strict";
|
||||
(function panesList_js() {
|
||||
var moduleName = "views/panesList";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("views/view");
|
||||
defineArray.push("views/layout");
|
||||
defineArray.push("views/label");
|
||||
defineArray.push("lib/wController/localModel");
|
||||
defineArray.push("views/pane");
|
||||
|
||||
define(moduleName, defineArray, function panesList_module() {
|
||||
var View = require("views/view");
|
||||
var Layout = require("views/layout");
|
||||
var Label = require("views/label");
|
||||
var LM = require("lib/wController/localModel");
|
||||
var Pane = require("views/pane");
|
||||
|
||||
var PanesList = Layout.inherit({
|
||||
"className": "PanesList",
|
||||
"constructor": function PanesListView(controller, options) {
|
||||
var base = {
|
||||
nestWidth: 100,
|
||||
nestHeight: 100,
|
||||
verticalSpace: 10,
|
||||
scrollable: Layout.Scroll.VirtualVertical
|
||||
};
|
||||
W.extend(base, options);
|
||||
this._ctrlInitialized = false;
|
||||
Layout.fn.constructor.call(this, controller, base);
|
||||
|
||||
this._scr.on("scrollTop", this._onScrollTop, this);
|
||||
this._scr.on("dragStart", this._onScrollDragStart, this);
|
||||
this._scr.on("dragEnd", this._onScrollDragEnd, this);
|
||||
|
||||
this._hbi = Object.create(null);
|
||||
this._overflown = false;
|
||||
this._rows = 0;
|
||||
this._cachedMinH = 0;
|
||||
this._cols = 0;
|
||||
this._scrolled = 0;
|
||||
this._scrollShift = 0;
|
||||
this._rangeUpdate = false;
|
||||
this._skipPaneActivate = false;
|
||||
this._proxyClearSkippingPaneActivate = this._clearSkippingPaneActivate.bind(this);
|
||||
|
||||
this._f.on("removedController", this._onRemovedController, this);
|
||||
this._f.on("rangeStart", this._onRangeStart, this);
|
||||
this._f.on("rangeEnd", this._onRangeEnd, this);
|
||||
this._f.setSubscriptionRange(0, 0);
|
||||
},
|
||||
"append": function(child, index) {
|
||||
var model = new LM();
|
||||
var nest = new Layout(model, {
|
||||
minHeight: this._o.nestHeight,
|
||||
maxHeight: this._o.nestHeight,
|
||||
minWidth: this._o.nestWidth,
|
||||
minWidth: this._o.nestWidth,
|
||||
scrollable: Layout.Scroll.None
|
||||
});
|
||||
nest._uncyclic.push(function() {model.destructor()});
|
||||
nest.append(child);
|
||||
child.on("activate", this._onChildActivate, this); //todo need to remove handler on deletion
|
||||
this._addChild(nest, 0, index);
|
||||
|
||||
nest.setSize(this._o.nestWidth, this._o.nestHeight);
|
||||
|
||||
if (this._cols && !this._rangeUpdate) {
|
||||
this._positionElement(index);
|
||||
if (index !== this._c.length - 1) {
|
||||
this._refreshPositions(index + 1);
|
||||
}
|
||||
}
|
||||
},
|
||||
"_clearSkippingPaneActivate": function() {
|
||||
this._skipPaneActivate = false;
|
||||
},
|
||||
"_onAddElement": function() {
|
||||
this._recalculateRows();
|
||||
},
|
||||
"_onChildActivate": function(address) {
|
||||
if (!this._skipPaneActivate) {
|
||||
lorgar.changePage(address);
|
||||
}
|
||||
},
|
||||
"_onData": function() {
|
||||
if (this._f.initialized) {
|
||||
if (!this._ctrlInitialized) {
|
||||
this._f.on("addElement", this._onAddElement, this);
|
||||
this._ctrlInitialized = true;
|
||||
}
|
||||
this._recalculateRows();
|
||||
}
|
||||
},
|
||||
"_onNewController": function(ctrl, index) {
|
||||
var label = new Pane(ctrl);
|
||||
this.append(label, index);
|
||||
},
|
||||
"_onRangeEnd": function() {
|
||||
this._rangeUpdate = false;
|
||||
this._refreshPositions(0);
|
||||
},
|
||||
"_onRangeStart": function() {
|
||||
this._rangeUpdate = true;
|
||||
},
|
||||
"_onRemovedController": function(ctrl, index) {
|
||||
var obj = this._c[index];
|
||||
this._removeChildByIndex(index);
|
||||
obj.c.destructor();
|
||||
|
||||
if (!this._rangeUpdate) {
|
||||
this._refreshPositions(index);
|
||||
}
|
||||
},
|
||||
"_onScrollDragStart": function() {
|
||||
this._skipPaneActivate = true;
|
||||
},
|
||||
"_onScrollDragEnd": function() {
|
||||
setTimeout(this._proxyClearSkippingPaneActivate, 1);
|
||||
},
|
||||
"_onScrollTop": function(y) {
|
||||
this._scrolled = y;
|
||||
this._recalculateShown();
|
||||
},
|
||||
"_positionElement": function(index) {
|
||||
var row = Math.floor(index / this._cols);
|
||||
var col = index % this._cols;
|
||||
var e = this._c[index];
|
||||
|
||||
e.c.setLeft(col * this._o.nestWidth + col * this._hSpace);
|
||||
e.c.setTop(row * this._o.nestHeight + row * this._o.verticalSpace - this._scrollShift);
|
||||
},
|
||||
"_recalculateRows": function() {
|
||||
var rows = Math.ceil(this._f.data.length() / this._cols);
|
||||
if (rows !== this._rows) {
|
||||
this._rows = rows;
|
||||
this._cachedMinH = (rows * this._o.nestHeight) + (rows - 1) * this._o.verticalSpace;
|
||||
}
|
||||
this._scr.setMinSize(this._w, Math.max(this._cachedMinH, this._h));
|
||||
},
|
||||
"_recalculateShown": function() {
|
||||
var ch = this._o.nestHeight + this._o.verticalSpace;
|
||||
this._scrollShift = this._scrolled % (ch);
|
||||
var pr = (this._h + this._scrollShift + this._o.verticalSpace) / (ch);
|
||||
var possibleRows = Math.ceil(pr);
|
||||
var amount = this._cols * (possibleRows);
|
||||
|
||||
var start = Math.floor(this._scrolled / (ch)) * this._cols;
|
||||
var end = start + amount;
|
||||
|
||||
this._f.setSubscriptionRange(start, end);
|
||||
this._refreshPositions(0);
|
||||
},
|
||||
"_refreshPositions": function(start) {
|
||||
for (var i = start; i < this._c.length; ++i) {
|
||||
this._positionElement(i);
|
||||
}
|
||||
},
|
||||
"_removeChildByIndex": function(i) {
|
||||
var child = this._c[i].c;
|
||||
this._c.splice(i, 1);
|
||||
child._p = undefined;
|
||||
|
||||
if (this._o.scrollable) {
|
||||
this._scr.removeChild(child._e);
|
||||
} else {
|
||||
this._e.removeChild(child._e);
|
||||
}
|
||||
|
||||
child.off("changeLimits", this._onChildChangeLimits, this);
|
||||
},
|
||||
"setSize": function(w, h) {
|
||||
View.fn.setSize.call(this, w, h);
|
||||
|
||||
this._cols = Math.floor(this._w / this._o.nestWidth);
|
||||
this._hSpace = (this._w - (this._cols * this._o.nestWidth)) / (this._cols - 1);
|
||||
|
||||
if (this._o.scrollable) {
|
||||
this._recalculateRows();
|
||||
this._scr.setSize(this._w, this._h);
|
||||
}
|
||||
this._recalculateShown();
|
||||
this._refreshPositions(0);
|
||||
}
|
||||
});
|
||||
|
||||
return PanesList;
|
||||
});
|
||||
})();
|
320
lorgar/views/view.js
Normal file
320
lorgar/views/view.js
Normal file
|
@ -0,0 +1,320 @@
|
|||
"use strict";
|
||||
(function view_js() {
|
||||
var moduleName = "views/view";
|
||||
|
||||
var defineArray = [];
|
||||
defineArray.push("lib/utils/subscribable");
|
||||
defineArray.push("views/helpers/draggable");
|
||||
|
||||
define(moduleName, defineArray, function view_module() {
|
||||
var counter = 0;
|
||||
var Subscribable = require("lib/utils/subscribable");
|
||||
var Draggable = require("views/helpers/draggable");
|
||||
|
||||
var View = Subscribable.inherit({
|
||||
"className": "View",
|
||||
"constructor": function View (controller, options, element) {
|
||||
Subscribable.fn.constructor.call(this);
|
||||
this._destroying = false;
|
||||
|
||||
var base = {
|
||||
minWidth: 0,
|
||||
minHeight: 0,
|
||||
maxWidth: Infinity,
|
||||
maxHeight: Infinity,
|
||||
draggable: false
|
||||
};
|
||||
W.extend(base, options);
|
||||
|
||||
this._id = ++counter;
|
||||
this._o = base;
|
||||
this._f = controller;
|
||||
if (element) {
|
||||
this._e = element;
|
||||
} else {
|
||||
this._e = document.createElement("div");
|
||||
}
|
||||
this._p = undefined;
|
||||
this._w = undefined;
|
||||
this._h = undefined;
|
||||
this._x = 0;
|
||||
this._y = 0;
|
||||
|
||||
this._initElement();
|
||||
|
||||
if (this._o.draggable) {
|
||||
this._initDraggable();
|
||||
}
|
||||
|
||||
this._f.on("data", this._onData, this);
|
||||
this._f.on("clearProperties", this._onClearProperties, this);
|
||||
this._f.on("addProperty", this._onAddProperty, this);
|
||||
this._f.on("newController", this._onNewController, this);
|
||||
|
||||
for (var i = 0; i < this._f._controllers.length; ++i) {
|
||||
this._onNewController(this._f._controllers[i]);
|
||||
}
|
||||
this._onData(this._f);
|
||||
|
||||
View.collection[this._id] = this;
|
||||
this._applyProperties();
|
||||
},
|
||||
"destructor": function() {
|
||||
this._destroying = true;
|
||||
this._f.off("data", this._onData, this);
|
||||
this._f.off("clearProperties", this._onClearProperties, this);
|
||||
this._f.off("addProperty", this._onAddProperty, this);
|
||||
this._f.off("newController", this._onNewController, this);
|
||||
|
||||
this.remove()
|
||||
if (this._o.draggable) {
|
||||
this._dg.destructor();
|
||||
}
|
||||
|
||||
delete View.collection[this._id];
|
||||
|
||||
Subscribable.fn.destructor.call(this);
|
||||
},
|
||||
"addClass": function(className) {
|
||||
var arr = this._e.className.split(" ");
|
||||
if (arr.indexOf(className) === -1) {
|
||||
arr.push(className);
|
||||
this._e.className = arr.join(" ");
|
||||
}
|
||||
},
|
||||
"_applyProperties": function() {
|
||||
for (var i = 0; i < this._f.properties.length; ++i) {
|
||||
var prop = this._f.properties[i];
|
||||
this._onAddProperty(prop.k, prop.p);
|
||||
}
|
||||
},
|
||||
"constrainHeight": function(h) {
|
||||
h = Math.max(h, this._o.minHeight);
|
||||
h = Math.min(h, this._o.maxHeight);
|
||||
|
||||
return h;
|
||||
},
|
||||
"constrainWidth": function(w) {
|
||||
w = Math.max(w, this._o.minWidth);
|
||||
w = Math.min(w, this._o.maxWidth);
|
||||
|
||||
return w;
|
||||
},
|
||||
"_initDraggable": function() {
|
||||
this._dg = new Draggable(this, {
|
||||
snapDistance: this._o.snapDistance
|
||||
});
|
||||
},
|
||||
"_initElement": function() {
|
||||
this._e.style.position = "absolute";
|
||||
this._e.style.top = "0";
|
||||
this._e.style.left = "0";
|
||||
this._e.style.boxSizing = "border-box";
|
||||
this._e.style.overflow = "hidden";
|
||||
this._e.id = this._id;
|
||||
},
|
||||
"_onAddProperty": function(key, propertyName) {
|
||||
var value = View.theme[key];
|
||||
if (value) {
|
||||
this._e.style[propertyName] = value;
|
||||
}
|
||||
},
|
||||
"_onClearProperties": function() {
|
||||
// for (var key in this._e.style) {
|
||||
// if (this._e.style.hasOwnProperty(key)) {
|
||||
// delete this._e.style[key];
|
||||
// }
|
||||
// }
|
||||
this._initElement();
|
||||
this._e.style.left = this._x + "px";
|
||||
this._e.style.top = this._y + "px";
|
||||
this._e.style.width = this._w + "px";
|
||||
this._e.style.height = this._h + "px";
|
||||
},
|
||||
"_onData": function() {},
|
||||
"_onNewController": function() {},
|
||||
"remove": function() {
|
||||
if (this._p) {
|
||||
this._p.removeChild(this);
|
||||
}
|
||||
},
|
||||
"removeClass": function(className) {
|
||||
var arr = this._e.className.split(" ");
|
||||
var index = arr.indexOf(className)
|
||||
var toJoin = false;
|
||||
while (index !== -1) {
|
||||
arr.splice(index, 1);
|
||||
index = arr.indexOf(className)
|
||||
toJoin = true;
|
||||
}
|
||||
if (toJoin) {
|
||||
this._e.className = arr.join(" ");
|
||||
}
|
||||
},
|
||||
"_resetTheme": function() {
|
||||
this._onClearProperties();
|
||||
this._applyProperties();
|
||||
},
|
||||
"setConstSize": function(w, h) {
|
||||
this._o.maxWidth = w;
|
||||
this._o.maxHeight = h;
|
||||
this._o.minWidth = w;
|
||||
this._o.minHeight = h;
|
||||
|
||||
if (this._w !== undefined && this._h !== undefined) {
|
||||
this.setSize(this._w, this._h);
|
||||
}
|
||||
|
||||
this.trigger("changeLimits", this);
|
||||
},
|
||||
"setLeft": function(l) {
|
||||
this._x = l;
|
||||
this._e.style.left = this._x + "px";
|
||||
},
|
||||
"_setLimits": function(minWidth, minHeight, maxWidth, maxHeight) {
|
||||
var needToTell = false;
|
||||
if (this._o.minWidth !== minWidth) {
|
||||
needToTell = true;
|
||||
this._o.minWidth = minWidth;
|
||||
}
|
||||
if (this._o.maxWidth !== maxWidth) {
|
||||
needToTell = true;
|
||||
this._o.maxWidth = maxWidth;
|
||||
}
|
||||
if (this._o.minHeight !== minHeight) {
|
||||
needToTell = true;
|
||||
this._o.minHeight = minHeight;
|
||||
}
|
||||
if (this._o.maxHeight !== maxHeight) {
|
||||
needToTell = true;
|
||||
this._o.maxHeight = maxHeight;
|
||||
}
|
||||
if (needToTell) {
|
||||
this.trigger("changeLimits", this);
|
||||
}
|
||||
|
||||
return needToTell && this._events.changeLimits && this._events.changeLimits.length; //to see if someone actually going to listen that event
|
||||
},
|
||||
"setMaxSize": function(w, h) {
|
||||
this._o.maxWidth = w;
|
||||
this._o.maxHeight = h;
|
||||
|
||||
if (this._w !== undefined && this._h !== undefined) {
|
||||
this.setSize(this._w, this._h);
|
||||
}
|
||||
|
||||
this.trigger("changeLimits", this);
|
||||
},
|
||||
"setMinSize": function(w, h) {
|
||||
this._o.minWidth = w;
|
||||
this._o.minHeight = h;
|
||||
|
||||
if (this._w !== undefined && this._h !== undefined) {
|
||||
this.setSize(this._w, this._h);
|
||||
}
|
||||
|
||||
this.trigger("changeLimits", this);
|
||||
},
|
||||
"setSize": function(w, h) {
|
||||
this._w = this.constrainWidth(w);
|
||||
this._h = this.constrainHeight(h);
|
||||
|
||||
this._e.style.width = this._w + "px";
|
||||
this._e.style.height = this._h + "px";
|
||||
|
||||
this.trigger("resize", this._w, this._h);
|
||||
},
|
||||
"setTop": function(t) {
|
||||
this._y = t;
|
||||
this._e.style.top = this._y + "px";
|
||||
},
|
||||
"trySize": function(w, h) {
|
||||
return !(w < this._o.minWidth || h < this._o.minHeight || w > this._o.maxWidth || h > this._o.maxHeight)
|
||||
}
|
||||
});
|
||||
|
||||
View.theme = Object.create(null);
|
||||
View.collection = Object.create(null);
|
||||
View.setTheme = function(theme) {
|
||||
for (var key in this.theme) {
|
||||
delete this.theme[key];
|
||||
}
|
||||
for (var key in theme) {
|
||||
if (theme.hasOwnProperty(key)) {
|
||||
this.theme[key] = theme[key];
|
||||
}
|
||||
}
|
||||
|
||||
for (var id in this.collection) {
|
||||
this.collection[id]._resetTheme();
|
||||
}
|
||||
}
|
||||
|
||||
View.createByType = function(type, ctrl, opts) {
|
||||
var typeName = this.ReversedViewType[type];
|
||||
if (typeName === undefined) {
|
||||
throw new Error("Unknown ViewType: " + type);
|
||||
}
|
||||
var Type = this.constructors[typeName];
|
||||
if (Type === undefined) {
|
||||
throw new Error("Constructor is not loaded yet, something is wrong");
|
||||
}
|
||||
return new Type(ctrl, opts);
|
||||
}
|
||||
|
||||
View.initialize = function(rc, cb) {
|
||||
var deps = [];
|
||||
var types = [];
|
||||
for (var key in this.ViewTypesPaths) {
|
||||
if (this.ViewTypesPaths.hasOwnProperty(key)) {
|
||||
if (!rc || rc.indexOf(key) !== -1) {
|
||||
deps.push(this.ViewTypesPaths[key]);
|
||||
types.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
require(deps, function() {
|
||||
for (var i = 0; i < types.length; ++i) {
|
||||
View.constructors[types[i]] = arguments[i];
|
||||
}
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
View.ViewType = {
|
||||
Label: 0,
|
||||
|
||||
Image: 3,
|
||||
View: 4,
|
||||
|
||||
Page: 102,
|
||||
PanesList: 104
|
||||
};
|
||||
|
||||
View.ReversedViewType = {
|
||||
"0": "Label",
|
||||
|
||||
"3": "Image",
|
||||
"4": "View",
|
||||
|
||||
"101": "Nav",
|
||||
"102": "Page",
|
||||
"104": "PanesList"
|
||||
};
|
||||
|
||||
View.ViewTypesPaths = {
|
||||
Label: "views/label",
|
||||
Nav: "views/nav",
|
||||
Page: "views/page",
|
||||
PanesList: "views/panesList",
|
||||
Image: "views/image"
|
||||
};
|
||||
|
||||
View.constructors = {
|
||||
View: View
|
||||
};
|
||||
|
||||
|
||||
return View;
|
||||
});
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue