From 7425b5f0498909087628465dfe6e6bfa4c42a422 Mon Sep 17 00:00:00 2001 From: Serghei Iakovlev Date: Sun, 10 Jul 2022 20:13:20 +0200 Subject: Simplify search page --- assets/js/search.js | 20 +++++++------------- i18n/en.toml | 5 +---- i18n/ru.toml | 5 +---- layouts/partials/search-results.html | 9 --------- layouts/shortcodes/form-search.html | 15 +++++++++------ 5 files changed, 18 insertions(+), 36 deletions(-) delete mode 100644 layouts/partials/search-results.html diff --git a/assets/js/search.js b/assets/js/search.js index 4a2a815..b8c8c80 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -153,7 +153,6 @@ function handleClearSearchButtonClicked() { } function hideSearchResults() { - document.getElementById('clear-search-results').classList.add('hide-element'); document.getElementById('site-search').classList.remove('expanded'); document.getElementById('search-results').classList.add('hide-element'); } @@ -284,7 +283,6 @@ function chunkify(input, chunkSize) { function showSearchResults() { document.getElementById('search-results').classList.remove('hide-element'); document.getElementById('site-search').classList.remove('expanded'); - document.getElementById('clear-search-results').classList.remove('hide-element'); } function scrollToTop() { @@ -308,10 +306,14 @@ function ellipsize(input, maxLength) { } // RegExp.escape() polyfill -if (!RegExp.escape) { +// +// For more see: +// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping +// - https://github.com/benjamingr/RegExp.escape/issues/37 +if (!Object.prototype.hasOwnProperty.call(RegExp, 'escape')) { RegExp.escape = function(str) { // $& means the whole matched string - return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); + return str.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&'); }; } @@ -348,13 +350,5 @@ document.addEventListener('DOMContentLoaded', function () { e.preventDefault(); }); - searchInput.addEventListener('keydown', (e) => { - if (e.key === 'Enter') { - handleSearchQuery(e); - } - }); - - document - .getElementById('clear-search-results') - .addEventListener('click', () => handleClearSearchButtonClicked()); + searchInput.addEventListener('keyup', (e) => handleSearchQuery(e)); }); diff --git a/i18n/en.toml b/i18n/en.toml index f65d31f..24ef81d 100644 --- a/i18n/en.toml +++ b/i18n/en.toml @@ -53,14 +53,11 @@ other = 'Contents' [search_help] - other = "To search the site, enter a search term and press Enter." + other = "To search the site, enter a search term." [search_site] other = 'Search site' -[clear_search_results] - other = 'New Search' - [search_enter_term] other = 'Please enter a search term.' diff --git a/i18n/ru.toml b/i18n/ru.toml index 1bbb38e..dc47e82 100644 --- a/i18n/ru.toml +++ b/i18n/ru.toml @@ -53,14 +53,11 @@ other = 'Содержание' [search_help] - other = "Для поиска по сайту введите поисковый запрос и нажмите Enter." + other = "Для поиска по сайту введите поисковый запрос." [search_site] other = 'Поиск по сайту' -[clear_search_results] - other = 'Новый поиск' - [search_enter_term] other = 'Введите поисковый запрос.' diff --git a/layouts/partials/search-results.html b/layouts/partials/search-results.html deleted file mode 100644 index fd4c48d..0000000 --- a/layouts/partials/search-results.html +++ /dev/null @@ -1,9 +0,0 @@ -
-
-
- {{ i18n "search_results" }} - -
-
-
-
diff --git a/layouts/shortcodes/form-search.html b/layouts/shortcodes/form-search.html index e9a9175..f328f38 100644 --- a/layouts/shortcodes/form-search.html +++ b/layouts/shortcodes/form-search.html @@ -10,14 +10,17 @@ -
- -
-{{- partial "search-results" . -}} +
+
+
+ {{ i18n "search_results" }} + +
+
+
+
{{- $vendors := slice (resources.Get "js/vendor/lunr.js") -}} {{- $vendors = $vendors | append (resources.Get "js/vendor/lunr.multi.js" ) -}} -- cgit v1.2.3