5363c7c2829b53feb5615b433b99f8f81c1e799d
larrym
  Thu Sep 22 10:59:09 2011 -0700
add code to support experimental UI work (redmine #5422)
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index ab78826..196075f 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -1,17 +1,19 @@
 // Javascript for use in hgTracks CGI
 
+// "use strict";
+
 var debug = false;
 var originalPosition;
 var originalSize;
 var originalCursor;
 var originalMouseOffset = {x:0, y:0};
 var startDragZoom = null;
 var imageV2 = false;
 var blockUseMap = false;
 var mapItems;
 var trackImg;               // jQuery element for the track image
 var trackImgTbl;            // jQuery element used for image table under imageV2
 var imgAreaSelect;          // jQuery element used for imgAreaSelect
 var originalImgTitle;
 var autoHideSetting = true; // Current state of imgAreaSelect autoHide setting
 var selectedMenuItem;       // currently choosen context menu item (via context menu).
@@ -1469,35 +1471,38 @@
 {
     // 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 (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();
     if(jQuery.fn.autocomplete && $('input#suggest') && db) {
+        if(jQuery.fn.Watermark) {
+            $('#suggest').Watermark("gene");
+        }
         if(newJQuery) {
             $('input#suggest').autocomplete({
                                                 delay: 500,
                                                 minLength: 2,
-                                                source: ajaxGet(function () {return db;}, new Object, true),
+                                                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) {
                                                         setPosition(ui.item.id, commify(getSizeFromCoordinates(ui.item.id)));
                                                         makeSureSuggestTrackIsVisible();
@@ -1686,31 +1691,31 @@
     currentMapItem = null;
 }
 
 function findMapItem(e)
 {
 // Find mapItem for given event; returns item object or null if none found.
 
     if(currentMapItem) {
         return currentMapItem;
     }
 
     // rightClick for non-map items that can be resolved to their parent tr and then trackName (e.g. items in gray bar)
     if(e.target.tagName.toUpperCase() != "AREA") {
         var tr = $( e.target ).parents('tr.imgOrd');
         if( $(tr).length == 1 ) {
-            a = /tr_(.*)/.exec($(tr).attr('id'));  // voodoo
+            var a = /tr_(.*)/.exec($(tr).attr('id'));  // voodoo
             if(a && a[1]) {
                 var id = a[1];
                 return makeMapItem(id);
             }
         }
     }
 
     // FIXME: do we really need to worry about non-imageV2 ?
     // Yeah, I think the rest of this is (hopefully) dead code
 
     var x,y;
     if(imageV2) {
         // It IS appropriate to use coordinates relative to the img WHEN we have a hit in the right-hand side, but NOT
         // when we have a hit in the left hand elements (which do not have relative coordinates).
         // XXXX still trying to figure this out.
@@ -2873,31 +2878,31 @@
         if(window.open(a[1]) == null) {
             windowOpenFailedMsg();
         }
         return;
     }
     showWarning("Couldn't parse out img src");
 }
 
 function jumpButtonOnClick()
 {
 // onClick handler for the "jump" button.
 // Handles situation where user types a gene name into the gene box and immediately hits the jump button,
 // expecting the browser to jump to that gene.
     var gene = $('#suggest').val();
     var db = getDb();
-    if(gene && db && gene.length > 0 && (getOriginalPosition() == getPosition() || getPosition().length == 0)) {
+    if(gene && gene != "gene" && db && gene.length > 0 && (getOriginalPosition() == getPosition() || getPosition().length == 0)) {
         pos = lookupGene(db, gene);
         if(pos) {
             setPosition(pos, null);
         } else {
             // turn this into a full text search.
             setPosition(gene, null);
         }
     }
     return true;
 }
 
 function remoteTrackCallback(rec)
 // jsonp callback to load a remote track.
 {
     if(rec.error) {
@@ -3082,15 +3087,37 @@
                                                         if(data.length > 0) {
                                                              data = data + "&";
                                                         }
                                                         data = data + this.name + "=" + cmd;
                                                      }
                                                }
                                             });
         if(data.length > 0) {
             navigateInPlace(data, null, false);
         }
         return false;
     } else {
         return true;
     }
 }
+
+function handleChangePosition(response, status)
+{
+    var json = eval("(" + response + ")");
+    setPosition(json.pos);
+}
+
+function changeAssemblies(ele)
+{
+// code to update page when user changes assembly select list.
+    $.ajax({
+               type: "GET",
+               url: "../cgi-bin/hgApi",
+               data: "cmd=defaultPos&db=" + getDb(),
+               dataType: "html",
+               trueSuccess: handleChangePosition,
+               success: catchErrorOrDispatch,
+               error: errorHandler,
+               cache: true
+           });
+    return false;
+}