Fix multiple calls to sendmsg() in search.js.
authorDavid Humphrey (:humph) <david.humphrey@senecac.on.ca>
Wed, 09 Feb 2011 18:05:15 -0500
changeset 42 ad1a64fce944dfdc830b81103c3b2ef0321605dd
parent 41 673ed6975d584137d90c112dc686b7bf6a8bc49a
child 43 b5b7850447e9d0a0402df43e31160abe3d0c673a
push id33
push userdavid.humphrey@senecac.on.ca
push dateWed, 09 Feb 2011 23:09:08 +0000
Fix multiple calls to sendmsg() in search.js.
server/static/search.js
--- a/server/static/search.js
+++ b/server/static/search.js
@@ -4,17 +4,17 @@ var results;
 
   $(window).bind("focus", function(){
     $("#keywords").focus();
   });
 
   function sendmsg(){
     var terms = $("#keywords").val();
     if ("console" in window) console.log("terms: |" + terms + "|");
-    location.hash = "#" + encodeURIComponent(terms);
+
     var xhr = new XMLHttpRequest();
     xhr.open("GET", "/json?" + encodeURI(terms), true);
     xhr.onreadystatechange = function() {
         if (xhr.readyState != 4 || xhr.status != 200)
             return;
         var results = JSON.parse(xhr.responseText);
         var div = $("#matchingbugs");
         div.html(results.bugs.length + " results for '" + $("#keywords").val() + "' in " +  (Date.now() - xhr.sendTime) + " (total)/" +
@@ -24,29 +24,33 @@ var results;
         div.append(document.createTextNode(v.summary)); div.append("<br>"); });
         if (results.hasMore)
             div.append("<br>(Showing " + results.bugs.length + " of " + results.totalResults + " results)<br>");
         };
     xhr.sendTime = Date.now();
     xhr.send(null);
   };
 
-  $("#submitton").bind("click", sendmsg);
+  function update() {
+    location.hash = "#" + encodeURIComponent($("#keywords").val);
+  }
+
+  $("#submitton").bind("click", update);
 
   $(window).bind("hashchange", function() {
       $("#keywords").val(decodeURIComponent(location.hash.substring(1)));
-      sendmsg();      
+      sendmsg();
   });
-  
+
   $("#keywords").bind("keyup", function(e){
 
  if(e.keyCode == 32 || e.keyCode == 13 ||
    (e.keyCode == 8 && $("#keywords").val().substr(-2, 1) == " "))
 {
-      sendmsg();
+      update();
   }});
 
   if (location.hash) {
       $("#keywords").val(decodeURIComponent(location.hash.substring(1)));
       sendmsg();
   }
 
   var findWord = (function() {
@@ -80,17 +84,17 @@ var results;
 
     var s = window.getSelection();
     if (s.anchorNode && s.anchorNode.nodeValue) {
       var word = findWord(s.anchorNode.nodeValue, s.focusOffset);
       $("#keywords").val(function(index, value) {
         return word.length ? value + ' ' + word : value;
       });
 
-      sendmsg();
+      update();
       $("#keywords").focus();
     }
   });
 
   function log(data){
     $("#matchingbugs").html(data);
   };