From 8222f2bd113dfef5a10f1bbdbc2d66dc9a36e1d1 Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Sat, 16 Jan 2021 13:26:55 +0530 Subject: [PATCH] fix search result multiple hightlight on lost focus also use set vars instead of fetching element again --- assets/js/fastsearch.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/assets/js/fastsearch.js b/assets/js/fastsearch.js index 78248175..3b7061a7 100644 --- a/assets/js/fastsearch.js +++ b/assets/js/fastsearch.js @@ -49,7 +49,7 @@ function activeToggle() { } // 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 // in the search box 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 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) { e.preventDefault(); if (ae == sInput) { @@ -111,7 +118,7 @@ document.onkeydown = function (e) { ae.click(); // click on active link } else if (key === "Escape") { 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 } }