Homogenize indentation (dom and messaging were using spaces) to tabs

This commit is contained in:
Tissevert 2018-11-29 22:09:09 +01:00
parent 242b97e745
commit fff6ac34a1
2 changed files with 78 additions and 78 deletions

View File

@ -1,36 +1,36 @@
function Dom() {
return {
clear: clear,
make: make
}
return {
clear: clear,
make: make
}
function clear(elem) {
while(elem.firstChild) {
elem.removeChild(elem.firstChild);
}
}
function clear(elem) {
while(elem.firstChild) {
elem.removeChild(elem.firstChild);
}
}
function make(tag, properties, children) {
var e = document.createElement(tag);
function make(tag, properties, children) {
var e = document.createElement(tag);
properties = properties || {};
children = children || [];
for(key in properties) {
var value = properties[key];
switch(key) {
case "class":
e.className = Array.isArray(value) ? value.join(' ') : value;
break;;
case "onClick":
e.addEventListener("click", value);
break;;
default:
e[key] = value;
}
}
for(key in properties) {
var value = properties[key];
switch(key) {
case "class":
e.className = Array.isArray(value) ? value.join(' ') : value;
break;;
case "onClick":
e.addEventListener("click", value);
break;;
default:
e[key] = value;
}
}
for(var i = 0; i < children.length; i++) {
e.appendChild(children[i]);
}
return e;
}
return e;
}
}

View File

@ -1,62 +1,62 @@
function Messaging() {
var ws = new WebSocket('ws://' + window.location.hostname + '/play/');
var keepAlivePeriod = 20000;
var routes = {callbacks: [], children: {}};
var ws = new WebSocket('ws://' + window.location.hostname + '/play/');
var keepAlivePeriod = 20000;
var routes = {callbacks: [], children: {}};
return {
addEventListener: addEventListener,
send: send,
start: start
}
return {
addEventListener: addEventListener,
send: send,
start: start
}
function get(obj, path, write) {
write = write || false;
if(path.length < 1) {
return obj;
} else {
if(obj.children[path[0]] == undefined && write) {
obj.children[path[0]] = {callbacks: [], children: {}};
}
if(obj.children[path[0]] != undefined) {
return get(obj.children[path[0]], path.slice(1), write);
} else {
return null;
}
}
}
function get(obj, path, write) {
write = write || false;
if(path.length < 1) {
return obj;
} else {
if(obj.children[path[0]] == undefined && write) {
obj.children[path[0]] = {callbacks: [], children: {}};
}
if(obj.children[path[0]] != undefined) {
return get(obj.children[path[0]], path.slice(1), write);
} else {
return null;
}
}
}
function addEventListener(path, callback) {
var route = get(routes, path, true);
route.callbacks.push(callback);
}
function addEventListener(path, callback) {
var route = get(routes, path, true);
route.callbacks.push(callback);
}
function messageListener(event) {
var o = JSON.parse(event.data);
var path = [];
var tmp = o;
while(tmp != undefined && tmp.tag != undefined) {
path.push(tmp.tag);
tmp = tmp.message;
}
var route = get(routes, path);
if(route != undefined && route.callbacks != undefined) {
route.callbacks.forEach(function(f) {f(o);});
} else {
debug.textContent = event.data;
}
};
function messageListener(event) {
var o = JSON.parse(event.data);
var path = [];
var tmp = o;
while(tmp != undefined && tmp.tag != undefined) {
path.push(tmp.tag);
tmp = tmp.message;
}
var route = get(routes, path);
if(route != undefined && route.callbacks != undefined) {
route.callbacks.forEach(function(f) {f(o);});
} else {
debug.textContent = event.data;
}
};
function start() {
function start() {
//ping();
addEventListener(["Pong"], ping);
ws.addEventListener('message', messageListener);
}
addEventListener(["Pong"], ping);
ws.addEventListener('message', messageListener);
}
function send(o) {
ws.send(JSON.stringify(o));
}
function send(o) {
ws.send(JSON.stringify(o));
}
function ping() {
setTimeout(function() {send({tag: "Ping"});}, keepAlivePeriod);
}
function ping() {
setTimeout(function() {send({tag: "Ping"});}, keepAlivePeriod);
}
}