]> git.pond.sub.org Git - eow/blob - static/eow.js
Replace Dojo with jQuery
[eow] / static / eow.js
1 function setup() {
2   $.ajaxSetup({
3     timeout: 30000
4   });
5
6   $("#cmdline").ajaxForm({
7     url: "/eow/command",
8     type: "GET"
9   });
10 }
11
12 function eowOut(output) {
13   $("#output").append("<pre>" + output + "</pre>");
14   window.scrollTo(0, window.scrollMaxY);
15 }
16
17 function get_next_update() {
18   $.getScript("/eow/update", function(data, textStatus) {
19       console.log(textStatus);
20       return data;
21     });
22 }
23
24 function submit_cmdline(command) {
25   $.ajax({
26     // The following URL must match that used to test the server.
27     url: "/eow/command", 
28     dataType: "text",
29
30     timeout: 30000, // Time in milliseconds
31
32     // The LOAD function will be called on a successful response.
33     success: function(data, textStatus) {
34         console.log(textStatus + " " + data);
35     },
36
37     // The ERROR function will be called in an error case.
38     error: function(xhr, textStatus, error) {
39       if (textStatus == "timeout") {
40         xhr.abort();
41       }
42
43       console.error("HTTP status code: ", xhr.status);
44     },
45
46     data: {
47         "q": command
48       }
49   });
50 }
51
52 function prompt(p) {
53   $("#prompt").text(p);
54 }
55
56 function msg(m) {
57   eowOut(m);
58 }
59
60 function next() {
61   get_next_update();
62 }
63
64 function setup_client() {
65   $("#inputfield").focus();
66 }
67
68 function inputfield_keyup(e) {
69   if (e.keyCode == 13) { // Enter
70     eowOut($("#prompt").text() + e.target.value);
71     submit_cmdline(e.target.value);
72     window.scrollTo(0, window.scrollMaxY);
73     e.target.value = "";
74   }
75 }