sort category listing

This commit is contained in:
Neale Pickett 2017-11-10 00:50:30 +00:00
parent ae028eb4ec
commit b0a79c9406
1 changed files with 47 additions and 41 deletions

View File

@ -6,56 +6,62 @@ function loadPuzzle(cat, id, points) {
} }
function puzzlesRefresh(term, obj) { function puzzlesRefresh(term, obj) {
term.clear(); term.clear();
for (var cat in obj) { let cats = [];
var puzzles = obj[cat]; for (let cat in obj) {
cats.push(cat);
}
cats.sort();
var pdiv = createElement('div'); for (let cat of cats) {
pdiv.className = 'category'; let puzzles = obj[cat];
var h = createElement('h2'); let pdiv = createElement('div');
pdiv.appendChild(h); pdiv.className = 'category';
h.textContent = cat;
var l = createElement('ul'); let h = createElement('h2');
pdiv.appendChild(l); pdiv.appendChild(h);
h.textContent = cat;
for (var puzzle of puzzles) { let l = createElement('ul');
var points = puzzle[0]; pdiv.appendChild(l);
var id = puzzle[1];
var i = createElement('li'); for (var puzzle of puzzles) {
l.appendChild(i); var points = puzzle[0];
var id = puzzle[1];
if (points == 0) { var i = createElement('li');
i.textContent = "‡"; l.appendChild(i);
} else {
var a = createElement('a'); if (points === 0) {
i.appendChild(a); i.textContent = "‡";
a.className = "link"; } else {
a.textContent = points; var a = createElement('a');
a.href = cat + "/" + id + "/index.html"; i.appendChild(a);
// a.addEventListener("click", loadPuzzle.bind(undefined, cat, id, points)); a.className = "link";
a.textContent = points;
a.href = cat + "/" + id + "/index.html";
// 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);