From 9a193735fbf1fe70bc0ce8a6cd30021dd94c352c Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 10 Aug 2022 13:24:51 +0400 Subject: [PATCH] Hiding of the suggestions drop-down list - Suggestions disappear when search is performed as a result of pressing enter in the search box. --- static/skin/viewer.js | 13 ++++++++++++- test/server.cpp | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/static/skin/viewer.js b/static/skin/viewer.js index c10c599c9..971c21220 100644 --- a/static/skin/viewer.js +++ b/static/skin/viewer.js @@ -125,7 +125,17 @@ function getSearchPattern() { return null; } + +let autoCompleteJS = null; + +function closeSuggestions() { + if ( autoCompleteJS ) { + autoCompleteJS.close(); + } +} + function updateSearchBoxForLocationChange() { + closeSuggestions(); document.getElementById("kiwixsearchbox").value = getSearchPattern(); } @@ -217,7 +227,7 @@ document.addEventListener('DOMContentLoaded', function () { const kiwixSearchBox = document.querySelector('#kiwixsearchbox'); const kiwixSearchFormWrapper = document.querySelector('.kiwix_searchform'); - const autoCompleteJS = new autoComplete( + autoCompleteJS = new autoComplete( { selector: "#kiwixsearchbox", placeHolder: kiwixSearchBox.title, @@ -263,6 +273,7 @@ document.addEventListener('DOMContentLoaded', function () { ); document.querySelector('#kiwixsearchform').addEventListener('submit', function(event) { + closeSuggestions(); try { const selectedElem = document.querySelector('.autoComplete_selected > a'); if (selectedElem) { diff --git a/test/server.cpp b/test/server.cpp index 2d7d6f3e9..93bd9f4b5 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -202,7 +202,7 @@ R"EXPECTEDRESULT( - + const blankPageUrl = `${root}/skin/blank.html`;