mirror of https://github.com/dirtbags/moth.git
puzzles.js: normalize whitespace; sort categories
This commit is contained in:
parent
b85cd306aa
commit
68398a4f91
|
@ -4,60 +4,62 @@ var puzzlesJsonUrl = "puzzles.json?" + ms;
|
||||||
console.log(puzzlesJsonUrl);
|
console.log(puzzlesJsonUrl);
|
||||||
|
|
||||||
function loadPuzzle(cat, id, points) {
|
function loadPuzzle(cat, id, points) {
|
||||||
console.log("Requested " + cat + "/" + id + "(" + points + ")");
|
console.log("Requested " + cat + "/" + id + "(" + points + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
function puzzlesRefresh(term, obj) {
|
function puzzlesRefresh(term, obj) {
|
||||||
term.clear();
|
term.clear();
|
||||||
|
|
||||||
for (var cat in obj) {
|
var k = Object.keys(obj);
|
||||||
var puzzles = obj[cat];
|
k.sort();
|
||||||
|
k.forEach(function(cat) {
|
||||||
|
var puzzles = obj[cat];
|
||||||
|
|
||||||
var pdiv = createElement('div');
|
var pdiv = createElement('div');
|
||||||
pdiv.className = 'category';
|
pdiv.className = 'category';
|
||||||
|
|
||||||
var h = createElement('h2');
|
var h = createElement('h2');
|
||||||
pdiv.appendChild(h);
|
pdiv.appendChild(h);
|
||||||
h.textContent = cat;
|
h.textContent = cat;
|
||||||
|
|
||||||
var l = createElement('ul');
|
var l = createElement('ul');
|
||||||
pdiv.appendChild(l);
|
pdiv.appendChild(l);
|
||||||
|
|
||||||
for (var puzzle of puzzles) {
|
for (var puzzle of puzzles) {
|
||||||
var points = puzzle[0];
|
var points = puzzle[0];
|
||||||
var id = puzzle[1];
|
var id = puzzle[1];
|
||||||
|
|
||||||
var i = createElement('li');
|
var i = createElement('li');
|
||||||
l.appendChild(i);
|
l.appendChild(i);
|
||||||
|
|
||||||
if (points == 0) {
|
if (points == 0) {
|
||||||
i.textContent = "‡";
|
i.textContent = "‡";
|
||||||
} else {
|
} else {
|
||||||
var a = createElement('a');
|
var a = createElement('a');
|
||||||
i.appendChild(a);
|
i.appendChild(a);
|
||||||
a.className = "link";
|
a.className = "link";
|
||||||
a.textContent = points;
|
a.textContent = points;
|
||||||
a.href = cat + "/" + id + "/index.html";
|
a.href = cat + "/" + id + "/index.html";
|
||||||
// a.addEventListener("click", loadPuzzle.bind(undefined, cat, id, points));
|
// a.addEventListener("click", loadPuzzle.bind(undefined, cat, id, points));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
term.appendShallow(pdiv);
|
term.appendShallow(pdiv);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function puzzles_start() {
|
function puzzles_start() {
|
||||||
var element = document.getElementById("puzzles");
|
var element = document.getElementById("puzzles");
|
||||||
var puzzlesTerminal = new Terminal(element);
|
var puzzlesTerminal = new Terminal(element);
|
||||||
var refreshInterval = 40 * 1000;
|
var refreshInterval = 40 * 1000;
|
||||||
|
|
||||||
var refreshCallback = puzzlesRefresh.bind(undefined, puzzlesTerminal);
|
var refreshCallback = puzzlesRefresh.bind(undefined, puzzlesTerminal);
|
||||||
var refreshFunction = loadJSON.bind(undefined, puzzlesJsonUrl, refreshCallback);
|
var refreshFunction = loadJSON.bind(undefined, puzzlesJsonUrl, refreshCallback);
|
||||||
|
|
||||||
puzzlesTerminal.clear();
|
puzzlesTerminal.clear();
|
||||||
puzzlesTerminal.par("Loading...");
|
puzzlesTerminal.par("Loading...");
|
||||||
refreshFunction();
|
refreshFunction();
|
||||||
setInterval(refreshFunction, refreshInterval);
|
setInterval(refreshFunction, refreshInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("load", puzzles_start);
|
window.addEventListener("load", puzzles_start);
|
||||||
|
|
Loading…
Reference in New Issue