mirror of
https://github.com/Wonderfall/hugo-WonderMod.git
synced 2024-11-24 11:31:37 +01:00
fix search result multiple hightlight on lost focus
also use set vars instead of fetching element again
This commit is contained in:
parent
704921ccd1
commit
8222f2bd11
@ -49,7 +49,7 @@ function activeToggle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// execute search as each character is typed
|
// execute search as each character is typed
|
||||||
document.getElementById("searchInput").onkeyup = function (e) {
|
sInput.onkeyup = function (e) {
|
||||||
// run a search query (for "term") every time a letter is typed
|
// run a search query (for "term") every time a letter is typed
|
||||||
// in the search box
|
// in the search box
|
||||||
const results = fuse.search(this.value); // the actual query being run using fuse.js
|
const results = fuse.search(this.value); // the actual query being run using fuse.js
|
||||||
@ -78,6 +78,13 @@ document.onkeydown = function (e) {
|
|||||||
let ae = document.activeElement;
|
let ae = document.activeElement;
|
||||||
let inbox = document.getElementById("searchbox").contains(ae)
|
let inbox = document.getElementById("searchbox").contains(ae)
|
||||||
|
|
||||||
|
if (ae === sInput) {
|
||||||
|
var elements = document.getElementsByClassName('active');
|
||||||
|
while (elements.length > 0) {
|
||||||
|
elements[0].classList.remove('active');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (key === "ArrowDown" && resultsAvailable && inbox) {
|
if (key === "ArrowDown" && resultsAvailable && inbox) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (ae == sInput) {
|
if (ae == sInput) {
|
||||||
@ -111,7 +118,7 @@ document.onkeydown = function (e) {
|
|||||||
ae.click(); // click on active link
|
ae.click(); // click on active link
|
||||||
} else if (key === "Escape") {
|
} else if (key === "Escape") {
|
||||||
resultsAvailable = false;
|
resultsAvailable = false;
|
||||||
document.getElementById("searchResults").innerHTML = sInput.value = ''; // clear inputbox and searchResults
|
resList.innerHTML = sInput.value = ''; // clear inputbox and searchResults
|
||||||
sInput.focus(); // shift focus to input box
|
sInput.focus(); // shift focus to input box
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user