Skip to content

Commit

Permalink
fix issues related to this PR: vufind-org/vufind#3064
Browse files Browse the repository at this point in the history
  • Loading branch information
crhallberg committed Jan 29, 2024
1 parent 6e1a4b8 commit 62a61f7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* https://github.com/vufind-org/autocomplete.js (v2.1.7) (2023-06-21) */
/* https://github.com/vufind-org/autocomplete.js (v2.1.8) (2024-01-29) */
function Autocomplete(_settings) {
const _DEFAULTS = {
delay: 250,
Expand Down Expand Up @@ -59,6 +59,7 @@ function Autocomplete(_settings) {
}

let lastInput = false;
let lastCB;
function _show(input) {
lastInput = input;
list.style.left = "-100%"; // hide offscreen
Expand All @@ -76,6 +77,7 @@ function Autocomplete(_settings) {
list.classList.remove("open");
_currentIndex = -1;
lastInput = false;
lastCB = false;
}

function _selectItem(item, input) {
Expand Down Expand Up @@ -171,7 +173,6 @@ function Autocomplete(_settings) {
_currentIndex = -1;
}

let lastCB;
function _search(handler, input) {
if (input.value.length < settings.minInputLength) {
_hide();
Expand Down Expand Up @@ -255,6 +256,7 @@ function Autocomplete(_settings) {
if (!input) {
return false;
}

if (typeof handler === "undefined") {
throw new Error(
"Autocomplete needs handler to return items based on a query: function(query, callback) {}"
Expand Down Expand Up @@ -294,7 +296,14 @@ function Autocomplete(_settings) {
input.setAttribute("spellcheck", "false"); // ^

// Activation / De-activation
input.addEventListener("focus", (_) => _search(handler, input), false);
if (input.getAttribute("autofocus") !== null) {
// ignore the first autofocus
input.addEventListener("focus", () => {
input.addEventListener("focus", () => _search(handler, input));
}, { once: true });
} else {
input.addEventListener("focus", () => _search(handler, input));
}
input.addEventListener("blur", _hide, false);

// Input typing
Expand Down Expand Up @@ -326,6 +335,11 @@ function Autocomplete(_settings) {
false
);

input.ac = {
show: _show,
hide: _hide,
}

return input;
};
}
Expand Down

0 comments on commit 62a61f7

Please sign in to comment.