moth/www/res/puzzles.js

48 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-04-04 21:45:00 -06:00
var puzzles_terminal;
var puzzles_url = "hack/puzzles.html";
2016-04-03 21:12:48 -06:00
function Puzzles(element) {
var term = new Terminal(element);
2016-04-04 21:45:00 -06:00
var refreshInterval;
function loaded() {
var doc = this.response;
var puzzles = doc.getElementById("puzzles");
var h1 = document.createElement("h1");
h1.textContent = "Puzzles";
2016-04-03 21:12:48 -06:00
term.clear();
2016-04-04 21:45:00 -06:00
term.append(h1);
2016-04-04 22:07:28 -06:00
term.appendShallow(puzzles);
2016-04-04 21:45:00 -06:00
}
function refresh() {
var myRequest = new XMLHttpRequest();
myRequest.responseType = "document";
myRequest.addEventListener("load", loaded);
myRequest.open("GET", puzzles_url);
myRequest.send();
}
function start() {
term.clear();
term.par("Loading...");
2016-04-04 10:40:21 -06:00
term.par("This is going to show you the list of open puzzles. It should refresh itself periodically, since not refreshing was a source of major confusion in the last setup, at least for kids, who seem not to realize what the reload button in the browser does.")
2016-04-04 21:45:00 -06:00
refreshInterval = setInterval(refresh, 20 * 1000);
refresh();
2016-04-03 21:12:48 -06:00
}
2016-04-04 21:45:00 -06:00
setTimeout(start, 3000);
2016-04-03 21:12:48 -06:00
}
function puzzles_start() {
2016-04-04 21:45:00 -06:00
puzzles_terminal = new Puzzles(document.getElementById("puzzles"));
2016-04-03 21:12:48 -06:00
}
window.addEventListener("load", puzzles_start);