Fixes for click-to-refine.
authorDavid Humphrey (:humph) <david.humphrey@senecac.on.ca>
Tue, 08 Feb 2011 23:06:38 -0500
changeset 37 4d8b63c55e4c
parent 36 7c4d0cd619e8
child 38 0af4a5e5e4ab
push id28
push userdavid.humphrey@senecac.on.ca
push dateWed, 09 Feb 2011 04:07:07 +0000
Fixes for click-to-refine.
server/static/search.js
--- a/server/static/search.js
+++ b/server/static/search.js
@@ -45,17 +45,17 @@ var results;
 
   var findWord = (function() {
     function isChar(c){
       return 'A' <= c && c <= 'z';
     }
 
     return function(text, offset) {
       if (!text || text.length <= offset) {
-        return;
+        return '';
       }
 
       var preoffset = offset;
       while(preoffset && isChar(text[preoffset - 1])) {
         preoffset--;
       }
 
       var postoffset = offset;
@@ -63,22 +63,28 @@ var results;
         postoffset++;
       }
 
       return text.substring(preoffset, postoffset + 1) || '';
     };
   })();
 
   $('body').bind('click', function() {
+    if (e.target.nodeName !== 'DIV') {
+      return;
+    }
+
     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();
     }
   });
 
   function log(data){
     $("#matchingbugs").html(data);
   };
 
 });