14dbfe57d9b670fa554c64cd4604e37fdefe037d chmalee Fri Jan 5 15:33:17 2024 -0800 Working version of saving last five user entered terms in the search bar, refs #29611 diff --git src/hg/js/hgGateway.js src/hg/js/hgGateway.js index 194ba2a..fc768bc 100644 --- src/hg/js/hgGateway.js +++ src/hg/js/hgGateway.js @@ -1128,30 +1128,55 @@ cart.send({ cgiVar: settings }, onSuccess , onFail); cart.flush(); } function overwriteWithGene() { $('#positionInput').val(item.geneSymbol); } if (item.geneSymbol) { selectedGene = item.geneSymbol; // Overwrite item's long value with symbol after the autocomplete plugin is done: window.setTimeout(overwriteWithGene, 0); } else { selectedGene = item.value; } } + function onSelectOther(item) { + function overwriteWithGene() { + $('#positionInput').val(item.geneSymbol); + } + if (item.geneSymbol) { + selectedGene = item.geneSymbol; + // Overwrite item's long value with symbol after the autocomplete plugin is done: + window.setTimeout(overwriteWithGene, 0); + } else { + selectedGene = item.value; + } + window.location.assign(item.id); + } + + function onSelect(item) { + // Switch out to the right type of select function for the type of category + // match: track hits (including genes), help page, etc + if (["helpDocs", "publicHubs", "trackDb"].includes(item.type) || + item.id.startsWith("hgc")) { + onSelectOther(item); + } else { + onSelectGene(item); + } + } + function setAssemblyOptions(uiState) { var assemblySelectLabel = 'Assembly'; if (uiState.dbOptions) { var html = '', option, i, selected; for (i = 0; i < uiState.dbOptions.length; i++) { option = uiState.dbOptions[i]; selected = (option.value === uiState.db) ? 'selected ' : ''; html += '<option ' + selected + 'value="' + option.value + '">' + option.label + '</option>'; } $('#selectAssembly').html(html); } if (uiState.genomeLabel) { if (uiState.hubUrl && uiState.genomeLabel.indexOf('Hub') < 0) { assemblySelectLabel = uiState.genomeLabel + ' Hub Assembly'; @@ -1238,36 +1263,37 @@ function updateFindPositionSection(uiState) { // Update the assembly menu, positionInput and description. var suggestUrl = null; if (uiState.suggestTrack) { suggestUrl = 'hgSuggest?db=' + uiState.db + '&prefix='; } setAssemblyOptions(uiState); if (uiState.position) { $('#positionDisplay').text(addCommasToPosition(uiState.position)); } autocompleteCat.init($('#positionInput'), { baseUrl: suggestUrl, watermark: positionWatermark, onServerReply: processHgSuggestResults, - onSelect: onSelectGene, + onSelect: onSelect, enterSelectsIdentical: true, onEnterTerm: goToHgTracks }); selectedGene = null; setAssemblyDescriptionTitle(uiState.db, uiState.genome); updateDescription(uiState.description); + $('#positionInput').focus(function() {$(this).autocompleteCat("search", "");}); if (uiState.db && $('#findPositionContents').css('display') === 'none') { initFindPositionContents(); } } function removeDups(inList, isDup) { // Return a list with only unique items from inList, using isDup(a, b) -> true if a =~ b var inLength = inList.length; // inListDups is an array of boolean flags for marking duplicates, parallel to inList. var inListDups = []; var outList = []; var i, j; for (i = 0; i < inLength; i++) { // If something has already been marked as a duplicate, skip it. if (! inListDups[i]) {