8295800d611b301861e0b6e8597e856ae96abf78 chmalee Mon Nov 24 16:19:31 2025 -0800 successful HGVS searches get saved into the 'recent searches' dropdown on hgTracks. the position box tries to suggest hgvs when the search term is longer than 8 characters, otherwise we assume it's a gene, refs #35984 diff --git src/hg/js/autocomplete.js src/hg/js/autocomplete.js index bca7a215600..f5da6076455 100644 --- src/hg/js/autocomplete.js +++ src/hg/js/autocomplete.js @@ -1,213 +1,237 @@ // support stuff for auto-complete using jQuery UI's autocomplete widget // // requires ajax.js // requires utils.js /* suggest (aka gene search) Requires three elements on page: positionDisplay (static display), positionInput (input textbox) and position (hidden). */ /* jshint esnext: true */ var hgTracks = hgTracks || {}; var suggestBox = { ajaxGet: function ajaxGet(db) { // Returns autocomplete source function // db is the relevant assembly (e.g. "hg18") var cache = {}; // cache is is used as a hash to cache responses from the server. return function(request, callback) { var key = request.term; if (key.length < 2) { // show the most recent searches let searchStack = window.localStorage.getItem("searchStack"); if (key.length === 0 && searchStack) { let searchObj = JSON.parse(searchStack); let currDb = getDb(); if (currDb in searchObj) { // sort the results list according to the stack order: let entries = Object.entries(searchObj[currDb].results); let stack = searchObj[currDb].stack; let callbackData = []; for (let s of stack) { callbackData.push(searchObj[currDb].results[s]); } callback(callbackData); } return; } else { return; } } if (!cache[key]) { + if (key.length < 8) { + // probably a gene name $.ajax({ url: "../cgi-bin/hgSuggest", data: "db=" + db + "&prefix=" + encodeURIComponent(key), // dataType: "json", // XXXX this doesn't work under IE, so we retrieve as text and do an eval to force to an object. trueSuccess: function(response, status) { // We get a lot of duplicate requests (especially the first letters of words), // so we keep a cache of the suggestions lists we've retreived. cache[this.key] = response; this.cont(JSON.parse(response)); }, success: catchErrorOrDispatch, error: function(request, status, errorThrown) { // tolerate errors (i.e. don't report them) to avoid spamming people on flaky network connections // with tons of error messages (#8816). }, key: key, cont: callback }); + } else { + // probably an hgvs term? + $.ajax({ + url: "../cgi-bin/hgSuggest", + data: "db=" + db + "&prefix=" + encodeURIComponent(key) + "&type=hgvs", + // dataType: "json", // XXXX this doesn't work under IE, so we retrieve as text and do an eval to force to an object. + trueSuccess: function(response, status) { + // We get a lot of duplicate requests (especially the first letters of words), + // so we keep a cache of the suggestions lists we've retreived. + cache[this.key] = response; + this.cont(JSON.parse(response)); + }, + success: catchErrorOrDispatch, + error: function(request, status, errorThrown) { + // tolerate errors (i.e. don't report them) to avoid spamming people on flaky network connections + // with tons of error messages (#8816). + }, + key: key, + cont: callback + }); + } } else { callback(JSON.parse(cache[key])); } // warn(request.term); }; }, clearFindMatches: function() { // clear any hgFind.matches set by a previous user selection (e.g. when user directly edits the search box) if ($('#hgFindMatches').length) $('#hgFindMatches').remove(); }, updateFindMatches: function(val) { // highlight genes choosen from suggest list (#6330) if ($('#hgFindMatches').length) $('#hgFindMatches').val(val); else $('#positionInput').parents('form').append(""); }, initialized: false, lastMouseDown : null, init: function(db, assemblySupportsGeneSuggest, selectCallback, clickCallback) { // selectCallback(item): called when the user selects a new genomic position from the list // clickCallback(position): called when the user clicks on positionDisplay this.initialized = true; var lastSelected = null; // this is the last value entered by the user via a suggestion (used to distinguish manual entry in the same field) var $posInput = $('#positionInput'); if ($posInput[0] !== document.activeElement) { // Reset value before adding watermark -- only if user is not already typing here $posInput.val(""); } var waterMark = suggestBox.restoreWatermark(db, assemblySupportsGeneSuggest); if (assemblySupportsGeneSuggest) { $.widget("custom.autocompletePosInput", $.ui.autocomplete, { _renderMenu: function(ul, items) { var that = this; jQuery.each(items, function(index, item) { that._renderItemData(ul, item); }); if ($(this)[0].term === "") { ul.append("