]> git.pond.sub.org Git - eow/blobdiff - static/eow.js
Replace Dojo with jQuery
[eow] / static / eow.js
index 7dedd45a9ac0d7f52ea45f0273f6b76a5c92206f..b3f27ed5cd6d32414ad3c460635ba66401c1d218 100644 (file)
@@ -1,79 +1,56 @@
-function byId(id) {
-  return document.getElementById(id);
+function setup() {
+  $.ajaxSetup({
+    timeout: 30000
+  });
+
+  $("#cmdline").ajaxForm({
+    url: "/eow/command",
+    type: "GET"
+  });
 }
 
 function eowOut(output) {
-  var t = document.createTextNode(output);
-  var p = document.createElement("pre");
-  p.appendChild(t);
-  byId("output").appendChild(p);
+  $("#output").append("<pre>" + output + "</pre>");
   window.scrollTo(0, window.scrollMaxY);
 }
 
-//t = window.setTimeout(f, 10000);
-//window.clearTimeout(t)
-//e = document.getElementById(id)
-
 function get_next_update() {
-  dojo.xhrGet( {
-    // The following URL must match that used to test the server.
-    url: "/eow/update", 
-    handleAs: "javascript",
-    //handleAs: "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;
-    },
-
-    // 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;
-    }
-  });
+  $.getScript("/eow/update", function(data, textStatus) {
+      console.log(textStatus);
+      return data;
+    });
 }
 
-function submit_cmdline(cmdline_form) {
-  dojo.xhrGet( {
+function submit_cmdline(command) {
+  $.ajax({
     // The following URL must match that used to test the server.
     url: "/eow/command", 
-    handleAs: "text",
+    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();
-         return response;
-       }
+    error: function(xhr, textStatus, error) {
+      if (textStatus == "timeout") {
+       xhr.abort();
+      }
 
-       console.error("HTTP status code: ", ioArgs.xhr.status);
-       return response;
-      },
+      console.error("HTTP status code: ", xhr.status);
+    },
 
-    form: cmdline_form
+    data: {
+       "q": command
+      }
   });
 }
 
 function prompt(p) {
-  byId("prompt").textContent = p;
+  $("#prompt").text(p);
 }
 
 function msg(m) {
@@ -85,14 +62,13 @@ function next() {
 }
 
 function setup_client() {
-  var input = byId("inputfield");
-  input.focus();
+  $("#inputfield").focus();
 }
 
 function inputfield_keyup(e) {
   if (e.keyCode == 13) { // Enter
-    eowOut(byId("prompt").textContent + e.target.value);
-    submit_cmdline(e.target.form.id);
+    eowOut($("#prompt").text() + e.target.value);
+    submit_cmdline(e.target.value);
     window.scrollTo(0, window.scrollMaxY);
     e.target.value = "";
   }