25f258c7fdfbdf417a917fcd00fff78d698def9b
chmalee
Fri Aug 30 12:01:24 2024 -0700
Big run through of changes to accomodate jquery 3.7.1 upgrade. Most of the changes are replacing the event methods with a change to .on(event, function(..)). A couple more changes are removing calls to jquery.type(). Also fixes various plugins and styles
diff --git src/hg/js/autocomplete.js src/hg/js/autocomplete.js
index d25fef5..1d60c19 100644
--- src/hg/js/autocomplete.js
+++ src/hg/js/autocomplete.js
@@ -78,111 +78,120 @@
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) {
- $('#positionInput').autocomplete({
+ $.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("
Showing 5 most recent searches. Enter 2 or more characters to start auto-complete search. Click the go button or press Enter to search across all tracks, hubs and our website. See 'examples' link above.
");
+ } else {
+ ul.append("
Click the go button or press Enter to search across all tracks, hubs and our website. See 'examples' link above.
");
+ }
+ },
+ _renderItem: function(ul, item) {
+ // In order to use HTML markup in the autocomplete, one has to overwrite
+ // autocomplete's _renderItem method using .html instead of .text.
+ // http://forum.jquery.com/topic/using-html-in-autocomplete
+ let clockIcon = '';
+ if ($("#positionInput").val().length < 2) {
+ clockIcon = ' ';
+ }
+ return $("")
+ .data("ui-autocomplete-item", item)
+ .append($("").html(clockIcon + item.label))
+ .appendTo(ul);
+ }
+ });
+ $('#positionInput').autocompletePosInput({
delay: 500,
minLength: 0,
source: this.ajaxGet(db),
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',
zIndex: 12
});
else $(auto).css({
maxHeight: 'none',
overflow: 'hidden',
zIndex: 12
});
+ // we need to remove the ui-menu-item class from the informational div
+ // because it is not selectable/focuseable
+ document.querySelectorAll('.autoCompleteInfo').forEach(function(i) {
+ i.classList.remove("ui-menu-item");
+ });
}
},
select: function(event, ui) {
lastSelected = ui.item.value;
suggestBox.updateFindMatches(ui.item.internalId);
addRecentSearch(db, ui.item.geneSymbol, ui.item);
selectCallback(ui.item);
// jQuery('body').css('cursor', 'wait');
// document.TrackHeaderForm.submit();
}
- })
- ._renderMenu = function(ul, items) {
- var that = this;
- jQuery.each(items, function(index, item) {
- that._renderItem(ul, item);
});
- if ($(this)[0].term === "") {
- ul.append("
Showing 5 most recent searches. Enter 2 or more characters to start auto-complete search. Click the go button or press Enter to search across all tracks, hubs and our website. See 'examples' link above.
");
- } else {
- ul.append("
Click the go button or press Enter to search across all tracks, hubs and our website. See 'examples' link above.
");
- }
- };
- $("#positionInput")._renderItem = function(ul, item) {
- // In order to use HTML markup in the autocomplete, one has to overwrite
- // autocomplete's _renderItem method using .html instead of .text.
- // http://forum.jquery.com/topic/using-html-in-autocomplete
- let clockIcon = '';
- if ($("#positionInput").val().length < 2) {
- clockIcon = ' ';
- }
- return $("")
- .data("item.autocomplete", item)
- .append($("").html(clockIcon + item.label))
- .appendTo(ul);
- };
}
// I want to set focus to the suggest element, but unforunately that prevents PgUp/PgDn from
// working, which is a major annoyance.
- $('#positionInput').focus(function() {$(this).autocomplete("search", "");});
- $("#positionInput").change(function(event) {
+ $('#positionInput').on("focus", function() {$(this).autocompletePosInput("search", "");});
+ $("#positionInput").on("change", function(event) {
if (!lastSelected || lastSelected !== $('#positionInput').val()) {
// This handles case where user typed or edited something rather than choosing from a suggest list;
// in this case, we only change the position hidden; we do NOT update the displayed coordinates.
var val = $('#positionInput').val();
// handles case where users zeroes out positionInput; in that case we revert to currently displayed position
if (!val || val.length === 0 || val === waterMark)
val = $('#positionDisplay').text();
else
val = val.replace(/\u2013|\u2014/g, "-"); // replace en-dash and em-dash with hyphen
$('#position').val(val);
suggestBox.clearFindMatches();
}
});
- $("#positionDisplay").mousedown(function(event) {
+ $("#positionDisplay").on("mousedown", function(event) {
// this let's the user click on the genomic position (e.g. if they want to edit it)
lastMouseDown = event.offsetX;
});
- $("#positionDisplay").mouseup(function(event) {
+ $("#positionDisplay").on("mouseup", function(event) {
if (event.offsetX !== lastMouseDown)
return;
// this let's the user click on the genomic position (e.g. if they want to edit it)
clickCallback($(this).text());
$('#positionInput').val($(this).text());
suggestBox.clearFindMatches();
if (hgTracks.windows)
{
genomePos.positionDisplayDialog();
}
});
},
restoreWatermark: function(db, assemblySupportsGeneSuggest) {
var waterMark;