Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Referees 2018/table styling #36

Open
wants to merge 11 commits into
base: gh-pages
Choose a base branch
from
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ displaySystem.config({
},
//path to the modules, can even be a full url
modulePath: "modules"
});
});
13 changes: 10 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -22,7 +28,9 @@ body {
bottom: 0;
}


/* control window */

@media screen {
body.controls {
font-family: verdana, helvetica, sans-serif;
Expand All @@ -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;
Expand All @@ -56,4 +63,4 @@ body {
body.controls button {
margin-right: 4px;
}
}
}
68 changes: 34 additions & 34 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// display system main
var displaySystem = (function() {
var displaySystem = (function () {
var system = {};
var config;
var modules = {};
Expand All @@ -9,27 +9,27 @@ 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) {
var h = document.getElementsByTagName('head')[0];
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;
Expand All @@ -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",
Expand All @@ -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);
Expand All @@ -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 = {};
Expand All @@ -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] = [];
}
Expand All @@ -153,25 +153,25 @@ 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);
});
});
}

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);
});
}
Expand All @@ -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);
}
Expand All @@ -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) {
Expand Down
41 changes: 37 additions & 4 deletions modules/sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
Loading