]> git.pond.sub.org Git - eow/blobdiff - static/eow.js
Use scrollIntoView instead of scrollMaxY
[eow] / static / eow.js
index 55fb20c134b5db38691cbeaaf3d57ee7d4113724..631894f0b70ff92059ca0daa4dddb03d8bb3c4e2 100644 (file)
@@ -1,40 +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("<pre>" + output + "</pre>");
+  $("input")[0].scrollIntoView(false);
 }
 
 function get_next_update() {
-  dojo.xhrGet( {
+  $.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 submit_cmdline(command) {
+  $.ajax({
     // The following URL must match that used to test the server.
-    url: "/eow/update", 
-    handleAs: "javascript",
-    //handleAs: "text",
+    url: "/eow/command", 
+    dataType: "text",
 
     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) {
-       if (response.dojoType == "timeout") {
-         ioArgs.xhr.abort();
-         get_next_update();
-         return response;
-       }
-
-       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(minutes, btus) {
-  eowOut("[" + minutes + "," + btus + "]: ");
+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 = "";
+  }
+}