diff --git a/config.js b/config.js
index be415b7..8f6d720 100644
--- a/config.js
+++ b/config.js
@@ -145,4 +145,4 @@ displaySystem.config({
},
//path to the modules, can even be a full url
modulePath: "modules"
-});
+});
\ No newline at end of file
diff --git a/css/style.css b/css/style.css
index 848127c..5f45a55 100644
--- a/css/style.css
+++ b/css/style.css
@@ -4,12 +4,18 @@ html, body {
margin: 0;
padding: 0;
}
+
+
+
/* hides screen during initialization, overridden in themes */
+
body {
visibility: hidden;
}
+
/* hides elements that are supposed to be hidden at least until theme is loaded and overrides the behavior */
+
.hidden {
visibility: hidden;
}
@@ -22,7 +28,9 @@ body {
bottom: 0;
}
+
/* control window */
+
@media screen {
body.controls {
font-family: verdana, helvetica, sans-serif;
@@ -41,8 +49,7 @@ body {
display: inline-block;
white-space: nowrap;
}
- body.controls input,
- body.controls textarea {
+ body.controls input, body.controls textarea {
width: 75px;
border: 1px solid silver;
border-right: none;
@@ -56,4 +63,4 @@ body {
body.controls button {
margin-right: 4px;
}
-}
+}
\ No newline at end of file
diff --git a/js/main.js b/js/main.js
index 49a7622..8a18648 100644
--- a/js/main.js
+++ b/js/main.js
@@ -1,5 +1,5 @@
// display system main
-var displaySystem = (function() {
+var displaySystem = (function () {
var system = {};
var config;
var modules = {};
@@ -9,12 +9,12 @@ var displaySystem = (function() {
function setConfig(_config) {
config = _config;
- setTimeout(init,0);
+ setTimeout(init, 0);
}
function prependToHead(el) {
var h = document.getElementsByTagName('head')[0];
- h.insertBefore(el,h.firstChild);
+ h.insertBefore(el, h.firstChild);
}
function appendToHead(el) {
@@ -22,14 +22,14 @@ var displaySystem = (function() {
h.appendChild(el);
}
- function loadScript(src,onload) {
+ function loadScript(src, onload) {
var el = document.createElement('script');
el.src = src;
el.onload = onload;
appendToHead(el);
}
- function loadCss(src,onLoad) {
+ function loadCss(src, onLoad) {
var el = document.createElement('link');
el.rel = 'stylesheet';
el.href = src;
@@ -48,13 +48,13 @@ var displaySystem = (function() {
clearTimeout(pendingConnection);
}
if (window.location.protocol === 'https:') {
- host = 'wss://'+config.wssHost;
+ host = 'wss://' + config.wssHost;
} else {
- host = 'ws://'+config.wsHost;
+ host = 'ws://' + config.wsHost;
}
ws = new WebSocket(host);
- ws.onopen = function() {
+ ws.onopen = function () {
if (config.mserverNode) {
ws.send(JSON.stringify({
type: "subscribe",
@@ -64,20 +64,20 @@ var displaySystem = (function() {
backoff = 100;
}
};
- ws.onerror = function(e){
+ ws.onerror = function (e) {
console.log("error");
ws.close();
};
- ws.onclose = function() {
- console.log("close reconnecting in",backoff,'ms');
+ ws.onclose = function () {
+ console.log("close reconnecting in", backoff, 'ms');
connected = false;
delete system.ws;
- pendingConnection = setTimeout(function() {
+ pendingConnection = setTimeout(function () {
connect();
- },backoff);
- backoff = Math.min(maxBackoff,backoff * 2);
+ }, backoff);
+ backoff = Math.min(maxBackoff, backoff * 2);
};
- ws.onmessage = function(msg) {
+ ws.onmessage = function (msg) {
var data = JSON.parse(msg.data);
if (data.topic) {
handleMessage(data);
@@ -99,7 +99,7 @@ var displaySystem = (function() {
function getArguments(f) {
var deps = f.toString().match(/^function\s*\w*\((.*?)\)/)[1];
- return deps?deps.split(/\s*,\s*/):[];
+ return deps ? deps.split(/\s*,\s*/) : [];
}
var handlers = {};
@@ -113,37 +113,37 @@ var displaySystem = (function() {
var module = modules[moduleName];
var api = module[action];
var args = getArguments(api);
- var data = args.map(function(arg) {
- return (msg.data||{})[arg];
+ var data = args.map(function (arg) {
+ return (msg.data || {})[arg];
});
- api.apply(module,data);
+ api.apply(module, data);
}
//handle individual handlers
if (handlers[topic]) {
- handlers[topic].forEach(function(handler) {
+ handlers[topic].forEach(function (handler) {
handler(msg);
});
}
}
}
- function sendMessage(def,action,data) {
+ function sendMessage(def, action, data) {
if (config.wsHost || config.wssHost) {
ws.send(JSON.stringify({
type: "publish",
node: config.mserverNode,
- topic: def.name+':'+action,
+ topic: def.name + ':' + action,
data: data
}));
}
}
- function onMessage(def,action,handler) {
+ function onMessage(def, action, handler) {
if (!def.name) {
return;
}
- var topic = (def.name+':'+action);
+ var topic = (def.name + ':' + action);
if (!handlers[topic]) {
handlers[topic] = [];
}
@@ -153,14 +153,14 @@ var displaySystem = (function() {
function init() {
// initWebsocket();
connect();
- var modulePath = config.modulePath||'modules';
+ var modulePath = config.modulePath || 'modules';
var pending = [];
- Object.keys(config.modules).forEach(function(name,i) {
- var src = modulePath+'/'+name+'.js';
+ Object.keys(config.modules).forEach(function (name, i) {
+ var src = modulePath + '/' + name + '.js';
pending[i] = {
name: name
};
- loadScript(src,function() {
+ loadScript(src, function () {
pending[i].def = lastModule;
checkLoaded(pending);
});
@@ -168,10 +168,10 @@ var displaySystem = (function() {
}
function checkLoaded(pending) {
- if (pending.every(function(module) {
+ if (pending.every(function (module) {
return module.def;
})) {
- pending.forEach(function(module) {
+ pending.forEach(function (module) {
initializeModule(module.def);
});
}
@@ -185,7 +185,7 @@ var displaySystem = (function() {
// add html
if (def.template) {
var d = document.createElement('div');
- d.className = 'moduleContainer '+def.name;
+ d.className = 'moduleContainer ' + def.name;
d.innerHTML = def.template;
document.getElementById('mainContainer').appendChild(d);
}
@@ -196,14 +196,14 @@ var displaySystem = (function() {
prependToHead(s);
}
// register api
- var m,cfg;
+ var m, cfg;
if (def.factory) {
if (def.name) {
//TODO: this is a bit of a tight coupling between names in config and module names
cfg = config.modules[def.name];
}
- m = def.factory(cfg,function(action, handler) {
- return onMessage(def,action,handler);
+ m = def.factory(cfg, function (action, handler) {
+ return onMessage(def, action, handler);
});
}
if (def.name) {
diff --git a/modules/sprite.js b/modules/sprite.js
index 4245b0a..a64138e 100644
--- a/modules/sprite.js
+++ b/modules/sprite.js
@@ -8,8 +8,12 @@ displaySystem.registerModule({
position: absolute;
}
`,
- factory: function(config,onMessage) {
+ factory: function (config, onMessage) {
var sprites = [];
+ var texts = [];
+
+
+ var hostAddress;
function getElement() {
return document.getElementById('sprite');
@@ -40,19 +44,48 @@ displaySystem.registerModule({
function addSprite(config) {
let sprite = document.createElement('div');
sprite.className = 'sprite';
- sprite.innerHTML = config.html || '';
+ var imgSrc = config.html || `http://${window.location.hostname}:1395/${config.alias}`||'';
+ var img = document.createElement('img');
+ img.setAttribute("src", imgSrc);
+ img.setAttribute("class", config.imgClass);
+ sprite.appendChild(img);
Object.keys(config).forEach((key) => {
- sprite.style[key] = config[key];
+ if (key === "id") {
+ sprite.id = config[key];
+ }
+ else {
+ sprite.style[key] = config[key];
+ }
});
getElement().appendChild(sprite);
return sprite;
}
+ function addText(config) {
+ let text = document.createElement('span');
+ text.setAttribute("class", "eventName");
+
+ text.innerHTML = config.data;
+ getElement().appendChild(text);
+ }
+ function addTextsToArray(config) {
+ texts.push.apply(texts, config);
+ }
+ function setText(configText) {
+ texts.forEach(removeSprite);
+ addTextsToArray(configText);
+ configText.forEach(addText);
+ }
function set(configSprites) {
sprites.forEach(removeSprite);
sprites = configSprites.map(addSprite);
}
-
+ if (config.data) {
+ sprites = config.data;
+ }
+ if (config.texts) {
+ setText(config.texts);
+ }
if (config.sprites) {
set(config.sprites);
}
diff --git a/modules/table.js b/modules/table.js
index ce07525..8bc91f0 100644
--- a/modules/table.js
+++ b/modules/table.js
@@ -27,7 +27,8 @@ displaySystem.registerModule({
//text-align: left;
}
*/
- factory: function(config,onMessage) {
+ factory: function (config, onMessage) {
+
var numberOfLines = 8;
var pageTimeout = 5000;
var pageTimer;
@@ -57,24 +58,24 @@ displaySystem.registerModule({
function setFromString(pasteFromExcel) {
var lines = pasteFromExcel.trim().split(/[\n\r]+/);
- var data = lines.map(function(line) {
+ var data = lines.map(function (line) {
return line.split(/\t/);
});
header = data.shift();
- set(data,header);
+ set(data, header);
}
- function setPage(data,header,page) {
- var pageData = data.slice(page*numberOfLines,(page+1)*numberOfLines);
+ function setPage(data, header, page) {
+ var pageData = data.slice(page * numberOfLines, (page + 1) * numberOfLines);
var head = '';
if (header) {
- head = ' ';
+ head = ''+header.join(' ')+' ';
}
- var html = pageData.slice(0,numberOfLines).map(function(row) {
+ var html = pageData.slice(0, numberOfLines).map(function (row) {
return [
'' + header.join(' ') + '