8928abf68fefbf2d30087af20d96dc29a4ff9620
larrym
  Fri Jun 22 14:50:06 2012 -0700
refactor suggestBox code into autocomplete.js so it can be re-used in hgGateway
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index 2234634..40f28af 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -2931,84 +2931,30 @@
                 dataType: "html",
                 trueSuccess: imageV2.updateImgAndMap,
                 success: catchErrorOrDispatch,
                 error: errorHandler,
                 cmd: 'wholeImage',
                 loadingId: showLoadingImage("imgTbl"),
                 disabledEle: disabledEle,
                 currentId: currentId,
                 currentIdYOffset: currentIdYOffset,
                 cache: false
             });
     }
 
 }
 
-  ////////////////////////////////////
- //// suggest  (aka gene search) ////
-////////////////////////////////////
-var suggestBox = {
-    lastEntered: null,
-
-    init: function (db)
-    {
-        var ele = $('#positionInput');
-        if(!ele.length) {
-            ele = $('input#suggest');
-        }
-        if(jQuery.fn.autocomplete && ele.length && db) {
-            if(jQuery.fn.Watermark) {
-                var str;
-                if(hgTracks.assemblySupportsGeneSuggest) {
-                     str = "enter new position, gene symbol or annotation search terms";
-                } else {
-                     str = "enter new position or annotation search terms";
-                }
-                $('#positionInput').Watermark(str, '#686868');
-            }
-            ele.autocomplete({
-                delay: 500,
-                minLength: 2,
-                source: ajaxGet(function () {return getDb();}, new Object, true),
-                open: function(event, ui) {
-                    var pos = $(this).offset().top + $(this).height();
-                    if (!isNaN(pos)) {
-                        var maxHeight = $(window).height() - pos - 30;  // take off a little more because IE needs it
-                        var auto = $('.ui-autocomplete');
-                        var curHeight = $(auto).children().length * 21;
-                        if (curHeight > maxHeight)
-                            $(auto).css({maxHeight: maxHeight+'px',overflow:'scroll'});
-                        else
-                            $(auto).css({maxHeight: 'none',overflow:'hidden'});
-                    }
-                },
-                select: function (event, ui) {
-                        genomePos.set(ui.item.id, commify(getSizeFromCoordinates(ui.item.id)));
-                        vis.makeTrackVisible($("#suggestTrack").val());
-                        suggestBox.lastEntered = ui.item.value;
-                        // jQuery('body').css('cursor', 'wait');
-                        // document.TrackHeaderForm.submit();
-                    }
-            });
-
-            // I want to set focus to the suggest element, but unforunately that prevents PgUp/PgDn from
-            // working, which is a major annoyance.
-            // $('input#suggest').focus();
-        }
-    }
-}
-
   //////////////////////
  //// track search ////
 //////////////////////
 var trackSearch = {
 
     searchKeydown: function (event)
     {
         if (event.which == 13) {
             // Required to fix problem on IE and Safari where value of hgt_tSearch is "-" (i.e. not "Search").
             $("input[name=hgt_tsPage]").val(0);  // NOTE: must match TRACK_SEARCH_PAGER in hg/inc/searchTracks.h
             $('#trackSearch').submit();
             // This doesn't work with IE or Safari.
             // $('#searchSubmit').click();
         }
     },
@@ -3048,62 +2994,57 @@
 {
     // The page may be reached via browser history (back button)
     // If so, then this code should detect if the image has been changed via js/ajax
     // and will reload the image if necessary.
     // NOTE: this is needed for IE but other browsers can detect the dirty page much earlier
     if (imageV2.isDirtyPage()) {
         // mark as non dirty to avoid infinite loop in chrome.
         $('#dirty').val('false');
         jQuery('body').css('cursor', 'wait');
             window.location = "../cgi-bin/hgTracks?hgsid=" + getHgsid();
             return false;
     }
     initVars();
 
     var db = getDb();
-    suggestBox.init(db);
+    suggestBox.init(db, hgTracks.assemblySupportsGeneSuggest,
+         function (position) {
+              genomePos.set(position, commify(getSizeFromCoordinates(position)));
+              vis.makeTrackVisible($("#suggestTrack").val());
+         },
+         function (position) {
+              genomePos.set(position, commify(getSizeFromCoordinates(position)));
+         });
 
     // Convert map AREA gets to post the form, ensuring that cart variables are kept up to date (but turn this off for search form).
     if($("FORM").length > 0 && $('#trackSearch').length == 0) {
         var allLinks = $('a');
         $( allLinks ).unbind('click');
         $( allLinks ).click( posting.saveSettings );
     }
     if($('#pdfLink').length == 1) {
         $('#pdfLink').click(function(i) {
             var thisForm=$('#TrackForm');
             if(thisForm != undefined && $(thisForm).length == 1) {
                 //alert("posting form:"+$(thisForm).attr('name'));
                 updateOrMakeNamedVariable($(thisForm),'hgt.psOutput','on');
                 return postTheForm($(thisForm).attr('name'),this.href);
             }
             return true;
         });
     }
 
-    if($("#positionInput").length) {
-        $("#positionInput").change(function(event) {
-            if(!suggestBox.lastEntered || suggestBox.lastEntered != $('#positionInput').val()) {
-                $('#position').val($('#positionInput').val());
-            }
-        });
-        $("#positionDisplay").click(function(event) {
-            genomePos.set($(this).text());
-            $('#positionInput').val($(this).text());
-        });
-    }
-
     if(imageV2.enabled) {
 
         // Make imgTbl allow drag reorder of imgTrack rows
         dragReorder.init();
         var imgTable = $(".tableWithDragAndDrop");
         if($(imgTable).length > 0) {
             $(imgTable).tableDnD({
                 onDragClass: "trDrag",
                 dragHandle: "dragHandle",
                 scrollAmount: 40,
                 onDragStart: function(ev, table, row) {
                     mouse.saveOffset(ev);
                     $(document).bind('mousemove',posting.blockTheMapOnMouseMove);
 
                     // Can drag a contiguous set of rows if dragging blue button