ee8e50093a2e4939372d923a1b10cf5894f0c791
larrym
  Mon Mar 7 16:18:03 2011 -0800
make right-click highlight found item in hgTracks (redmine 3062); also includes some code to handle transition to new jQuery libraries (currently dead code)
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index 8e9631d..003b2a7 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -1,44 +1,44 @@
 // Javascript for use in hgTracks CGI
-// $Header: /projects/compbio/cvsroot/kent/src/hg/js/hgTracks.js,v 1.69 2010/06/11 18:14:23 larrym Exp $
 
 var debug = false;
 var originalPosition;
 var originalSize;
 var originalCursor;
 var originalMouseOffset = {x:0, y:0};
 var clickClipHeight;
 var revCmplDisp;
 var insideX;
 var startDragZoom = null;
 var newWinWidth;
 var imageV2 = false;
 var imgBoxPortal = 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).
 var browser;                // browser ("msie", "safari" etc.)
 var mapIsUpdateable = true;
 var currentMapItem;
 var floatingMenuItem;
 var visibilityStrsOrder = new Array("hide", "dense", "full", "pack", "squish");     // map browser numeric visibility codes to strings
 var supportZoomCodon = false;
+var newJQuery = false;       // temporary #define for use while testing jQuery 1.5/jQuery UI 1.8 in dev trees
 
 function initVars(img)
 {
 // There are various entry points, so we call initVars in several places to make sure this variables get updated.
     if(!originalPosition) {
         // remember initial position and size so we can restore it if user cancels
         originalPosition = getOriginalPosition();
         originalSize = $('#size').text();
         originalCursor = jQuery('body').css('cursor');
     }
 }
 
 function selectStart(img, selection)
 {
     initVars();
@@ -1185,41 +1185,54 @@
     if(thisForm == undefined || $(thisForm).length == 0)
         thisForm=$("FORM");
     if($(thisForm).length > 1 )
         thisForm=$(thisForm)[0];
     if(thisForm != undefined && $(thisForm).length == 1) {
         //alert("posting form:"+$(thisForm).attr('name'));
         return postTheForm($(thisForm).attr('name'),obj.href);
     }
     return true;
 }
 
 $(document).ready(function()
 {
     var db = getDb();
     if(jQuery.fn.autocomplete && $('input#suggest') && db) {
+        if(newJQuery) {
+            $('input#suggest').autocomplete({
+                                                delay: 500,
+                                                minLength: 2,
+                                                source: ajaxGet(function () {return db;}, new Object),
+                                                select: function (event, ui) {
+                                                        setPosition(ui.item.id, commify(getSizeFromCoordinates(ui.item.id)));
+                                                        // jQuery('body').css('cursor', 'wait');
+                                                        // document.TrackHeaderForm.submit();
+                                                    }
+                                            });
+
+        } else {
         $('input#suggest').autocomplete({
                                             delay: 500,
                                             minchars: 2,
                                             ajax_get: ajaxGet(function () {return db;}, new Object),
                                             callback: function (obj) {
                                                 setPosition(obj.id, commify(getSizeFromCoordinates(obj.id)));
                                                 // 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();
     }
     initVars();
 
     if(jQuery.jStore) {
         // Experimental (currently dead) code to handle "user hits back button" problem.
         if(false) {
             jQuery.extend(jQuery.jStore.defaults, {
                               project: 'hgTracks',
                               engine: 'flash',
                               flash: '/jStore.Flash.html'
                           });
         }
@@ -1525,46 +1538,66 @@
                     chromStart = parseInt(a[1]) + 1;
                 a = /t=(\d+)/.exec(href);
                 if(a && a[1])
                     chromEnd = parseInt(a[1]);
             }
             if(chrom == null || chromStart == null || chromEnd == null) {
                 showWarning("couldn't parse out genomic coordinates");
             } else {
                 if(cmd == 'getDna')
                 {
                     if(window.open("../cgi-bin/hgc?g=getDna&i=mixed&c=" + chrom + "&l=" + (chromStart - 1) + "&r=" + chromEnd) == null) {
                         windowOpenFailedMsg();
                     }
                 } else {
                     var newPosition = setPositionByCoordinates(chrom, chromStart, chromEnd);
+                    var reg = new RegExp("hgg_gene=([^&]+)");
+                    var a = reg.exec(href);
+                    var name;
+                    // pull item name out of the url so we can set hgFind.matches (redmine 3062)
+                    if(a && a[1]) {
+                        name = a[1];
+                    } else {
+                        reg = new RegExp("[&?]i=([^&]+)");
+                        a = reg.exec(href);
+                        if(a && a[1]) {
+                            name = a[1];
+                        }
+                    }
                     if(browser == "safari" || imageV2) {
                         // We need to parse out more stuff to support resetting the position under imageV2 via ajax, but it's probably possible.
                         // See comments below on safari problems.
                         jQuery('body').css('cursor', 'wait');
+                        var ele;
                         if(document.TrackForm)
-                            document.TrackForm.submit();
+                            ele = document.TrackForm;
                         else
-                            document.TrackHeaderForm.submit();
+                            ele = document.TrackHeaderForm;
+                        if(name)
+                            $(ele).append("<input type='hidden' name='hgFind.matches' value='" + name + "'>");
+                        ele.submit();
                     } else {
                         // XXXX This attempt to "update whole track image in place" didn't work for a variety of reasons, so this is dead code, but
                         // I'm leaving it in case we try to implement this functionality in the future.
                         jQuery('body').css('cursor', '');
+                        var data = "hgt.trackImgOnly=1&hgt.ideogramToo=1&position=" + newPosition + "&hgsid=" + getHgsid();
+                        if(name)
+                            data += "&hgFind.matches=" + name;
                         $.ajax({
                                    type: "GET",
                                    url: "../cgi-bin/hgTracks",
-                                   data: "hgt.trackImgOnly=1&hgt.ideogramToo=1&position=" + newPosition + "&hgsid=" + getHgsid(),
+                                   data: data,
                                    dataType: "html",
                                    trueSuccess: handleUpdateTrackMap,
                                    success: catchErrorOrDispatch,
                                    error: errorHandler,
                                    cmd: cmd,
                                    cache: false
                                });
                     }
                 }
             }
     } else if (cmd == 'zoomCodon' || cmd == 'zoomExon') {
         var num, ajaxCmd;
         if(cmd == 'zoomCodon') {
             num = prompt("Please enter the codon number to jump to:");
             ajaxCmd = 'codonToPos';
@@ -1652,30 +1685,54 @@
     } else if (cmd == 'float') {
         if(floatingMenuItem && floatingMenuItem == id) {
             $.floatMgr.FOArray = new Array();
             floatingMenuItem = null;
         } else {
             if(floatingMenuItem) {
                 // This doesn't work.
                 $('#img_data_' + floatingMenuItem).parent().restartFloat();
                 // This does work
                 $.floatMgr.FOArray = new Array();
             }
             floatingMenuItem = id;
             reloadFloatingItem();
             updateTrackImg(id, "hgt.transparentImage=0", "");
         }
+    } else if (cmd == 'locateItem') {
+        // currently experimental
+        // o["Locate item" ] = {onclick: function(menuItemClicked, menuObject) { contextMenuHit(menuItemClicked, menuObject, "locateItem"); return true; }};
+        $('#hgLookupDialog').dialog({
+                               resizable: false,
+                               height: 'auto',
+                               width: 'auto',
+                               modal: true,
+                               closeOnEscape: true,
+                               autoOpen: false,
+                               buttons: { "OK": function() {
+                                              $(this).dialog("close");
+                                          }},
+                                    });
+        // this doesn't work (not sure why).
+        $('input#itemLookupSuggest').autocomplete({
+            delay: 500,
+            minLength: 2,
+            source: ajaxGet(function () {return db;}, new Object),
+            select: function (event, ui) {
+                setPosition(ui.item.id, commify(getSizeFromCoordinates(ui.item.id)));
+            }
+            });
+        $('#hgLookupDialog').dialog('open');
     } else {   // if( cmd in 'hide','dense','squish','pack','full','show' )
         // Change visibility settings:
         //
         // First change the select on our form:
         var rec = trackDbJson[id];
         var selectUpdated = updateVisibility(id, cmd);
 
         // Now change the track image
         if(imageV2 && cmd == 'hide')
         {
             // Hide local display of this track and update server side cart.
             // Subtracks controlled by 2 settings so del vis and set sel=0.  Others, just set vis hide.
             if(tdbIsSubtrack(rec))
                 setCartVars( [ id, id+"_sel" ], [ '[]', 0 ] ); // Remove subtrack level vis and explicitly uncheck.
             else if(tdbIsFolderContent(rec))