Clean up CSS and JS for autosuggest, a=chris

Chris Pollett [2012-05-27 18:35:54]
Clean up CSS and JS for autosuggest, a=chris
Filename
css/search.css
lib/index_bundle_iterators/intersect_iterator.php
scripts/autosuggest.js
diff --git a/css/search.css b/css/search.css
index 5cd85b3..157b6d9 100755
--- a/css/search.css
+++ b/css/search.css
@@ -593,25 +593,33 @@ body.mobile
     font-size:16pt;
 }

-.searchbox input, .autoresult
+.searchbox input
 {
     width: 6.5in;
     font-size:16pt;
-    margin-right:0;
-    margin-left:0;
+    margin:0;
     border:0;
-    padding-top: 0;
+    padding: 0;
     padding-bottom:0.05in;
-    padding-right:0;
-    padding-left:0;
-    margin:0;
 }

-.dropdown
-{
-    width: 6.55in;
+.mobile .searchbox input
+{
+    width:180px;
+    font-size:12pt;
+}
+
+.mobile .landing .searchbox input
+{
+    width:235px;
+    font-size:12pt;
+}
+
+.dropdown
+{
+    width: 6.5in;
+    margin:0;
     margin-left:0.023in;
-    height: 1.5in;
     border-color: #AAA;
     border-width: 0.05in;
     border-top-style:none;
@@ -624,9 +632,6 @@ body.mobile
     overflow-y: auto;
     overflow-x: hidden;
     padding-bottom:0in;
-    margin-bottom:0in;
-    margin-right:0;
-    padding-top: 0.01in;
 }

 .mobile .dropdown
@@ -634,48 +639,54 @@ body.mobile
     display:none;
 }

-.mobile .searchbox input
+.autoresult
 {
-    width:180px;
-    font-size:12pt;
+    position:relative;
+    top:0.15in;
+    background:#DDF;
+    width: 6.30in;
+    font-size:16pt;
+    margin:0;
+    border:0;
+    padding:0;
+    padding-bottom:0.05in;
+    z-index:-1;
+    visibility:hidden;
 }

-.mobile .landing .searchbox input
-{
-    width:235px;
-    font-size:12pt;
+.landing .autoresult {
+    position:relative;
+    top:0;
 }

-#aslist li
+.autoresult li
 {
-    position:relative;
-    top:-0.015in;
+    width:6.10in;
     background:#DDF;
-    width: 6.5in;
     font-size:16pt;
     margin-right:0in;
     margin-left:0in;
     padding-top:0;
-    padding-right:0in;
+    padding-right:0.1in;
     padding-left:0.1in;
     cursor:pointer;
     list-style:none;
 }

-#aslist li span
+.autoresult li span
 {
-    width:6.5in;
     padding:0;
     margin:0;
+    height:18pt;
     display:block;
 }

-#aslist li span.unselected
+.autoresult li span.unselected
 {
     background:white;
 }

-#aslist li span.selected
+.autoresult li span.selected
 {
     background:#AAE;
     color:black;
diff --git a/lib/index_bundle_iterators/intersect_iterator.php b/lib/index_bundle_iterators/intersect_iterator.php
index edf4bfb..f05aad0 100644
--- a/lib/index_bundle_iterators/intersect_iterator.php
+++ b/lib/index_bundle_iterators/intersect_iterator.php
@@ -255,7 +255,7 @@ class IntersectIterator extends IndexBundleIterator
         if(count($position_list[$l[1]]) == 0) {
             $stop = true;
         }
-        while(!$stop){
+        while(!$stop) {
             $p = array_shift($position_list[$l[1]]);
             for ($i = 0;$i < $num_words; $i++){
                 if(isset($position_list[$i][0]) && $p == $position_list[$i][0]){
@@ -264,8 +264,8 @@ class IntersectIterator extends IndexBundleIterator
             }
             $q = $interval[0][0];
             if($p > $r[0]) {
-                array_push($covers,array($l[0],$r[0]));
-                array_push($interval,array($p,$l[1]));
+                array_push($covers, array($l[0], $r[0]));
+                array_push($interval, array($p, $l[1]));
             } else {
                 if($p < $q) {
                     array_unshift($interval, array($p, $l[1]));
@@ -276,14 +276,14 @@ class IntersectIterator extends IndexBundleIterator
             }
             $l = array_shift($interval);
             $r = end($interval);
-            if(count($position_list[$l[1]]) == 0){
+            if(count($position_list[$l[1]]) == 0) {
                 $stop = true;
             }

         }
-        array_push($covers,array($l[0],$r[0]));
+        array_push($covers, array($l[0],$r[0]));
         $score = 0;
-        if($is_doc){
+        if($is_doc) {
             $weight = TITLE_WEIGHT;
             $cover = array_shift($covers);
             while(isset($cover[1]) && $cover[1] < AD_HOC_TITLE_LENGTH) {
@@ -297,7 +297,7 @@ class IntersectIterator extends IndexBundleIterator
         }
         else{
             $weight = LINK_WEIGHT;
-            foreach($covers as $cover){
+            foreach($covers as $cover) {
                 $score += ($weight/($cover[1] - $cover[0] + 1));
             }
         }
diff --git a/scripts/autosuggest.js b/scripts/autosuggest.js
index 373a89c..3ae91c7 100644
--- a/scripts/autosuggest.js
+++ b/scripts/autosuggest.js
@@ -38,7 +38,7 @@
  * @return String text_field Current value from the search box
  *
  */
-function askeyup(e,text_field) {
+function askeyup(e, text_field) {
     var keynum;
     var term_array;
     var inputTerm = text_field.value;
@@ -53,7 +53,7 @@ function askeyup(e,text_field) {
         keynum = e.which;
     }
     term_array = inputTerm.split(" ");
-    concat_array = inputTerm.split(" ",term_array.length-1);
+    concat_array = inputTerm.split(" ",term_array.length-1);
     if (inputTerm != "") {
         for(var i=0; i < concat_array.length ; i++) {
             concat_term += concat_array[i] + " ";
@@ -63,25 +63,30 @@ function askeyup(e,text_field) {
     inputTerm = term_array[term_array.length-1];

     if (keynum != 40 && keynum != 38) {
-        search_list="";
+        search_list="";
         autosuggest(dictionary, inputTerm);
+        if(count <= 1) {
+            search_list="";
+        }
         document.getElementById("asdropdown").style.visibility = "visible";
-        document.getElementById("asdropdown").scrollTop =  0;
+        document.getElementById("asdropdown").scrollTop =  0;
         results_dropdown.innerHTML = search_list;
         cursor_pos=-1;
         if (search_list != "") {
             results_dropdown.style.visibility = "visible";
         }
         else {
-            results_dropdown.style.visibility = "hidden";
+            results_dropdown.style.visibility = "hidden";
         }
         items = results_dropdown.children.length;
         if (items == 0) {
             document.getElementById("asdropdown").className = "";
+            document.getElementById("asdropdown").style.height = "0";
         } else {
             document.getElementById("asdropdown").className = "dropdown";
             if (items < 6) {
-                document.getElementById("asdropdown").style.height = "" + items * 0.25 + "in";
+                document.getElementById("asdropdown").style.height = ""
+                    + items * 0.25 + "in";
             } else {
                 document.getElementById("asdropdown").style.height = "1.5in";
             }
@@ -90,32 +95,32 @@ function askeyup(e,text_field) {
     if (results_dropdown.style.visibility == "visible") {
         if(keynum == 40) {
             if (cursor_pos == -1) {
-                cursor_pos = 0;
+                cursor_pos = 0;
                 setDisplay(cursor_pos,"selected");
             }
             else {
-                setDisplay(cursor_pos,"unselected");
+                setDisplay(cursor_pos,"unselected");
                 cursor_pos++;
-                if (cursor_pos == items) {
+                if (cursor_pos == items) {
                     cursor_pos=0;
                 }
-                setDisplay(cursor_pos,"selected");
-            }
+                setDisplay(cursor_pos,"selected");
+            }
             scrollpos = (cursor_pos > 2) ? (cursor_pos - 2) : 0;
             document.getElementById("asdropdown").scrollTop = scrollpos * 26;
-        } else if(keynum == 38) {
+        } else if(keynum == 38) {
             if (cursor_pos == -1)
             {
                 cursor_pos = items-1;
-                setDisplay(cursor_pos,"selected");
+                setDisplay(cursor_pos,"selected");
             }
             else {
-                setDisplay(cursor_pos,"unselected");
-                cursor_pos--;
-                if (cursor_pos == -1) {
+                setDisplay(cursor_pos,"unselected");
+                cursor_pos--;
+                if (cursor_pos == -1) {
                     cursor_pos=items-1;
                 }
-                setDisplay(cursor_pos,"selected");
+                setDisplay(cursor_pos,"selected");
             }
             scrollpos = (cursor_pos > 2) ? (cursor_pos - 2) : 0;
             document.getElementById("asdropdown").scrollTop = scrollpos * 26;
@@ -129,7 +134,7 @@ function askeyup(e,text_field) {
  * and place in the search box
  */
 function setDisplay(cursor_pos, class_name)  {
-    var astobj = document.getElementById("search-name");
+    var astobj = document.getElementById("search-name");
     astobj.value = document.getElementById(cursor_pos).innerHTML;
     document.getElementById(cursor_pos).className = class_name;
 }
@@ -142,7 +147,7 @@ function aslitem_click(liObj) {
     var astobj = document.getElementById("search-name");
     astobj.value = liObj.innerHTML;
     results_dropdown.innerHTML = "";
-    document.getElementById("asdropdown").style.visibility = "hidden";
+    document.getElementById("asdropdown").style.visibility = "hidden";
 }

 /**
@@ -152,7 +157,7 @@ function hover_display(liObj) {
     if (cursor_pos > -1) {
         document.getElementById(cursor_pos).className = "unselected";
     }
-    cursor_pos = liObj.id;
+    cursor_pos = liObj.id;
     liObj.className = "selected";
 }

@@ -172,8 +177,10 @@ function getValues(trie_array, parent_word, max_display) {
             } else {
                 list_string = concat_term.trim() + " " + decode(parent_word);
                 list_string = list_string.trim();
-                search_list += "<li><span id=" + count + " class='unselected' onmouseover=hover_display(this) ";
-                search_list += "onclick=aslitem_click(this)>" + list_string + "</span></li>";
+                search_list += "<li><span id=" + count +
+                    " class='unselected' onmouseover=hover_display(this) ";
+                search_list += "onclick=aslitem_click(this)>" + list_string +
+                    "</span></li>";
                 count++;
             }
         }
@@ -235,7 +242,6 @@ function autosuggest(trie_array, term) {
         [start_char, ] = tmp;
         enc_chr = encode(start_char);
         trie_array = exist(trie_array[enc_chr], term);
-
     } else {
         trie_array = trie_array[term];
     }
ViewGit