X-Git-Url: http://git.pond.sub.org/?p=eow;a=blobdiff_plain;f=static%2Feow.js;h=631894f0b70ff92059ca0daa4dddb03d8bb3c4e2;hp=f85607584d06d431ba35b1851bb9cdbf19b9fc5a;hb=d0df339544e58ba26876518ca78eedc1ebb72583;hpb=0efe5441c5ae67bf40daf04ea66538a946f2f0ad diff --git a/static/eow.js b/static/eow.js index f856075..631894f 100644 --- a/static/eow.js +++ b/static/eow.js @@ -1,29 +1,86 @@ +function setup() { + $.ajaxSetup({ + timeout: 30000 + }); + + $("#cmdline").ajaxForm({ + url: "/eow/command", + type: "GET" + }); +} + function eowOut(output) { - var t = document.createTextNode(output); - var p = document.createElement("p"); - p.appendChild(t); - dojo.byId("output").appendChild(p); + $("#output").append("
" + output + "
"); + $("input")[0].scrollIntoView(false); +} + +function get_next_update() { + $.ajax({ + url: "/eow/update", + dataType: "script", + success: function(data, textStatus) { + console.log(textStatus + " " + data); + }, + error: function(xhr, textStatus, error) { + if (textStatus == "timeout") { + xhr.abort(); + next(); + } + + console.error("HTTP status code: ", xhr.status); + } + }); } -function hello() { - dojo.xhrGet( { +function submit_cmdline(command) { + $.ajax({ // The following URL must match that used to test the server. - url: "/eow/static/ajax.txt", - handleAs: "javascript", + url: "/eow/command", + dataType: "text", - timeout: 5000, // Time in milliseconds + timeout: 30000, // Time in milliseconds // The LOAD function will be called on a successful response. - load: function(response, ioArgs) { - console.log(response); - return response; + success: function(data, textStatus) { + console.log(textStatus + " " + data); }, // The ERROR function will be called in an error case. - error: function(response, ioArgs) { - console.error("HTTP status code: ", ioArgs.xhr.status); - return response; - } + error: function(xhr, textStatus, error) { + if (textStatus == "timeout") { + xhr.abort(); + } + + console.error("HTTP status code: ", xhr.status); + }, + + data: { + "q": command + } }); } +function prompt(p) { + $("#prompt").text(p); +} + +function msg(m) { + eowOut(m); +} + +function next() { + get_next_update(); +} + +function setup_client() { + $("#inputfield").focus(); +} + +function inputfield_keyup(e) { + if (e.keyCode == 13) { // Enter + eowOut($("#prompt").text() + e.target.value); + submit_cmdline(e.target.value); + window.scrollTo(0, window.scrollMaxY); + e.target.value = ""; + } +}