6f9fec828621f2ec766636195885ff4a88ef3cb4 larrym Tue Nov 15 10:46:18 2011 -0800 work on #3484; corner-case where user hits enter w/o selecting item from list. Some experimental code for #5933 (only turned on in larrym's tree) diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js index 55c72aa..d2a6341 100644 --- src/hg/js/hgTracks.js +++ src/hg/js/hgTracks.js @@ -124,30 +124,33 @@ }, set: function (position, size) { // Set value of position and size (in hiddens and input elements). // We assume size has already been commified. // Either position or size may be null. if(position) { // There are multiple tags with name == "position" // (one in TrackHeaderForm and another in TrackForm). var tags = document.getElementsByName("position"); for (var i = 0; i < tags.length; i++) { var ele = tags[i]; ele.value = position; } } + if($('#positionDisplay').length) { + $('#positionDisplay').text(position); + } if(size) { $('#size').text(size); } var pos = parsePosition(position); if(pos) { // fixup external static links on page' // Example ensembl link: http://www.ensembl.org/Homo_sapiens/contigview?chr=21&start=33031934&end=33041241 genomePos.linkFixup(pos, "ensemblLink", new RegExp("(.+start=)[0-9]+"), "end"); // Example NCBI link: http://www.ncbi.nlm.nih.gov/mapview/maps.cgi?taxid=9606&CHR=21&BEG=33031934&END=33041241 genomePos.linkFixup(pos, "ncbiLink", new RegExp("(.+BEG=)[0-9]+"), "END"); // Example medaka link: http://utgenome.org/medakabrowser_ens_jump.php?revision=version1.0&chr=chromosome18&start=14435198&end=14444829 genomePos.linkFixup(pos, "medakaLink", new RegExp("(.+start=)[0-9]+"), "end"); @@ -506,31 +509,31 @@ // dragSelect.startTime is null if mouse has never been moved var singleClick = ( (selection.x2 == selection.x1) || dragSelect.startTime == null || (now.getTime() - dragSelect.startTime) < 100); var newPosition = genomePos.update(img, selection, singleClick); if(newPosition != undefined) { if(imageV2.inPlaceUpdate) { imageV2.navigateInPlace("position=" + newPosition, null, true); } else { jQuery('body').css('cursor', 'wait'); document.TrackHeaderForm.submit(); } } } else { // what is this doing? genomePos.set(genomePos.original, genomePos.originalSize); - genomePos.original = genomePos.originalSize = null; + genomePos.original = genomePos.originalSize = null; // <- XXXX I think this is unnecessary. } dragSelect.startTime = null; setTimeout('posting.allowMapClicks();',50); // Necessary incase the dragSelect.selectEnd was over a map item. select takes precedence. return true; }, load: function (firstTime) { var imgHeight = 0; if (imageV2.enabled) imgHeight = imageV2.imgTbl.height(); // No longer disable without ruler, because shift-drag still works if(typeof(hgTracks) != "undefined") { @@ -1169,31 +1172,31 @@ $(".area").each( function(t) { this.onmouseover = dragReorder.mapItemMouseOver; this.onmouseout = dragReorder.mapItemMouseOut; this.onclick = posting.mapClk; }); } } ////////////////////////// //// Drag Scroll code //// ////////////////////////// jQuery.fn.panImages = function(){ // globals across all panImages - genomePos.original = genomePos.getOriginalPos(); + genomePos.original = genomePos.getOriginalPos(); // XXXX what is this for? (this already happened in initVars). var leftLimit = hgTracks.imgBoxLeftLabel * -1; var rightLimit = (hgTracks.imgBoxPortalWidth - hgTracks.imgBoxWidth + leftLimit); var only1xScrolling = ((hgTracks.imgBoxWidth - hgTracks.imgBoxPortalWidth) == 0);//< hgTracks.imgBoxLeftLabel); var prevX = (hgTracks.imgBoxPortalOffsetX + hgTracks.imgBoxLeftLabel) * -1; var portalWidth = 0; var savedPosition; this.each(function(){ var pic; var pan; if ( $(this).is("img") ) { pan = $(this).parent("div"); pic = $(this); @@ -2796,34 +2799,38 @@ } else { return true; } }, jumpButtonOnClick: function () // called from hgTracks.c { // 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 && gene.length > 0 && gene != "gene" && db + && $('#positionDisplay').length == 0 && (genomePos.getOriginalPos() == genomePos.get() || genomePos.get().length == 0)) { - pos = lookupGene(db, gene); + var pos = lookupGene(db, gene); if(pos) { + vis.makeTrackVisible($("#suggestTrack").val()); genomePos.set(pos, null); + // Following doesn't work b/c we get the hugo symbol from the suggest list, not the known gene id. + // $(document.TrackForm || document.TrackHeaderForm).append("<input type='hidden' name='hgFind.matches' " + "value='" + name + "'>"); } else { // turn this into a full text search. genomePos.set(gene, null); } } return true; }, navigateInPlace: function (params, disabledEle, keepCurrentTrackVisible) { // request an hgTracks image, using params // disabledEle is optional; this element will be enabled when update is complete // If keepCurrentTrackVisible is true, we try to maintain relative position of the item under the mouse after the in-place update. jQuery('body').css('cursor', ''); var currentId, currentIdYOffset; @@ -2850,56 +2857,68 @@ cmd: 'wholeImage', loadingId: showLoadingImage("imgTbl"), disabledEle: disabledEle, currentId: currentId, currentIdYOffset: currentIdYOffset, cache: false }); } } //////////////////////////////////// //// suggest (aka gene search) //// //////////////////////////////////// var suggestBox = { + lastEntered: null, init: function (db) { - if(jQuery.fn.autocomplete && $('input#suggest') && db) { + var ele = $('#positionInput'); + if(!ele.length) { + ele = $('input#suggest'); + } + if(jQuery.fn.autocomplete && ele.length && db) { if(jQuery.fn.Watermark) { - $('#suggest').Watermark("gene"); + var str; + if(hgTracks.assemblySupportsGeneSuggest) { + str = "enter new position, gene symbol or annotation search terms"; + } else { + str = "enter new position or annotation search terms"; } - $('input#suggest').autocomplete({ + $('#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 //// ////////////////////// @@ -3008,30 +3027,38 @@ $( 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()); + } + }); + } + 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