changeset 24:5388c9950377 default tip

preview appears for main input box, timed
author Maria Emerson <memerson@mozilla.com>
date Wed, 23 Jul 2008 10:29:50 -0700
parents 4d223fd05668
children
files preview/hip.css preview/hip.js
diffstat 2 files changed, 55 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/preview/hip.css	Tue Jul 22 15:39:31 2008 -0700
+++ b/preview/hip.css	Wed Jul 23 10:29:50 2008 -0700
@@ -1,3 +1,9 @@
+#searchbar  {
+  display: none !important;
+}
+
+
+
 #search-box {
   border: 1px solid #000000;
   background: #272727;
--- a/preview/hip.js	Tue Jul 22 15:39:31 2008 -0700
+++ b/preview/hip.js	Wed Jul 23 10:29:50 2008 -0700
@@ -77,7 +77,11 @@
 function makeSuggestionHtml( tagName, list, hilitedNumber ) {
   var result = "";
 
-  for (var i = 0; i < list.length; i++) {
+  if (hilitedNumber == -1) {
+    result += "<div id=\"preview-pane\"/>";
+  }
+
+ for (var i = 0; i < list.length; i++) {
     if ( i == hilitedNumber ) {
       result += "<" + tagName + " class=\"hilited suggestion\">" + list[i] + "</" + tagName + ">";
       result += "<div id=\"preview-pane\"/>"
@@ -266,7 +270,31 @@
   }
 }
 
-
+var timeoutId;
+var doneTyping = true;
+function timeInput ( event ) {
+  window.clearTimeout(timeoutId);
+  doneTyping = false;
+  timeoutId = setTimeout("afterTimeout()", 250 );
+}
+function afterTimeout() {
+  doneTyping = true;
+  var input = $("#search-box").val();
+  var object = getSelection();
+  if (!object && input.match(" ")) {
+    object = input.substring(input.indexOf(" "));
+  }
+  if (object && object != " ") {
+    if (input.match("google")) {
+      $("#preview-pane").show(); 
+      setPreview("google", object);
+    }
+    else if (input.match("map")) {
+      $("#preview-pane").show(); 
+      setPreview("map", object);
+    }
+  }
+}
 
 function updateDisplay( number ) {
   var suggestions = gQs.getSuggestionsAsHtml();
@@ -279,18 +307,25 @@
   // PREVIEW PANE STUFF
   // This should be done based on command and sentence structure above, not string parsing... yuck
   if (selection != "") {
-    var curSuggestion = suggestions[hilitedSuggestion];
-    if (curSuggestion) {
-      var object = curSuggestion.substring(curSuggestion.indexOf(" "));
-      
-      if (curSuggestion.match("google") && !object.match("needarg")) {
-        setPreview("google", object);
+    if (hilitedSuggestion == -1) {
+      if (!doneTyping)
+        window.clearTimeout(timeoutId);
+      $("#preview-pane").hide();
+    }
+    else {
+      var curSuggestion = suggestions[hilitedSuggestion];
+      if (curSuggestion) {
+	var object = curSuggestion.substring(curSuggestion.indexOf(" "));
+	
+	if (curSuggestion.match("google") && !object.match("needarg")) {
+	  setPreview("google", object);
+	}
+	else if (curSuggestion.match("map") && !object.match("needarg")) {
+	  setPreview("map", object);
+	}
+	else 
+	  $("#preview-pane").height("0px");
       }
-      else if (curSuggestion.match("map") && !object.match("needarg")) {
-        setPreview("map", object);
-      }
-      else 
-        $("#preview-pane").height("0px");
     }
   }   
    
@@ -343,6 +378,7 @@
     $("#status-line").html( "All you gotta do is rub that lamp." );
     $("#search-box").focus();
     $("#search-box").keyup( searchBoxQuery );
+    $("#search-box").keyup( timeInput );    
     $("#autocomplete-popup").css(
         "width",
         $("#search-box").css("width")