]> git.pond.sub.org Git - eow/blob - static/eow.js
xdump notes
[eow] / static / eow.js
1 function byId(id) {
2   return document.getElementById(id);
3 }
4
5 function eowOut(output) {
6   var t = document.createTextNode(output);
7   var p = document.createElement("pre");
8   p.appendChild(t);
9   byId("output").appendChild(p);
10   window.scrollTo(0, window.scrollMaxY);
11 }
12
13 //t = window.setTimeout(f, 10000);
14 //window.clearTimeout(t)
15 //e = document.getElementById(id)
16
17 function get_next_update() {
18   dojo.xhrGet( {
19     // The following URL must match that used to test the server.
20     url: "/eow/update", 
21     handleAs: "javascript",
22     //handleAs: "text",
23
24     timeout: 30000, // Time in milliseconds
25
26     // The LOAD function will be called on a successful response.
27     load: function(response, ioArgs) {
28       console.log(response);
29       return response;
30     },
31
32     // The ERROR function will be called in an error case.
33     error: function(response, ioArgs) {
34         if (response.dojoType == "timeout") {
35           ioArgs.xhr.abort();
36           get_next_update();
37           return response;
38         }
39
40         console.error("HTTP status code: ", ioArgs.xhr.status);
41         return response;
42     }
43   });
44 }
45
46 function submit_cmdline(cmdline_form) {
47   dojo.xhrGet( {
48     // The following URL must match that used to test the server.
49     url: "/eow/command", 
50     handleAs: "text",
51
52     timeout: 30000, // Time in milliseconds
53
54     // The LOAD function will be called on a successful response.
55     load: function(response, ioArgs) {
56         console.log(response);
57         return response;
58       },
59
60     // The ERROR function will be called in an error case.
61     error: function(response, ioArgs) {
62         if (response.dojoType == "timeout") {
63           ioArgs.xhr.abort();
64           return response;
65         }
66
67         console.error("HTTP status code: ", ioArgs.xhr.status);
68         return response;
69       },
70
71     form: cmdline_form
72   });
73 }
74
75 function prompt(p) {
76   byId("prompt").textContent = p;
77 }
78
79 function msg(m) {
80   eowOut(m);
81 }
82
83 function next() {
84   get_next_update();
85 }
86
87 function setup_client() {
88   var input = byId("inputfield");
89   input.focus();
90 }
91
92 function inputfield_keyup(e) {
93   if (e.keyCode == 13) { // Enter
94     eowOut(byId("prompt").textContent + e.target.value);
95     submit_cmdline(e.target.form.id);
96     window.scrollTo(0, window.scrollMaxY);
97     e.target.value = "";
98   }
99 }