diff options
author | Bnyro <bnyro@tutanota.com> | 2023-09-09 16:49:14 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2023-09-18 21:29:11 +0200 |
commit | a55e0ac553e608e5657573a8173aa5a040a49054 (patch) | |
tree | d3d7dbdd8648e1f5007756628c2bc7cbfb19d774 /searx/static/themes/simple | |
parent | 90b0bfd1bf30ecd6b6e8b54d300be5fba45aecca (diff) | |
download | searxng-a55e0ac553e608e5657573a8173aa5a040a49054.tar.gz searxng-a55e0ac553e608e5657573a8173aa5a040a49054.zip |
[feat] search on category select without JS
Co-authored-by: Alexandre Flament <alex@al-f.net>
Diffstat (limited to 'searx/static/themes/simple')
-rw-r--r-- | searx/static/themes/simple/src/js/main/search.js | 33 | ||||
-rw-r--r-- | searx/static/themes/simple/src/less/search.less | 56 |
2 files changed, 61 insertions, 28 deletions
diff --git a/searx/static/themes/simple/src/js/main/search.js b/searx/static/themes/simple/src/js/main/search.js index 361d2fdcf..2ad8e48c5 100644 --- a/searx/static/themes/simple/src/js/main/search.js +++ b/searx/static/themes/simple/src/js/main/search.js @@ -151,28 +151,27 @@ } // vanilla js version of search_on_category_select.js - if (qinput !== null && d.querySelector('.help') != null && searxng.settings.search_on_category_select) { - d.querySelector('.help').className = 'invisible'; - - searxng.on('#categories input', 'change', function () { - var i, categories = d.querySelectorAll('#categories input[type="checkbox"]'); - for (i = 0; i < categories.length; i++) { - if (categories[i] !== this && categories[i].checked) { - categories[i].click(); - } - } - if (! this.checked) { - this.click(); - } - submitIfQuery(); - return false; - }); - + if (qinput !== null && searxng.settings.search_on_category_select) { searxng.on(d.getElementById('safesearch'), 'change', submitIfQuery); searxng.on(d.getElementById('time_range'), 'change', submitIfQuery); searxng.on(d.getElementById('language'), 'change', submitIfQuery); } + // most common browsers at the time of writing this support :has, except for Firefox + // can be removed when Firefox / Firefox ESL starts supporting it as well + try { + // this fails when the browser does not support :has + d.querySelector("html:has(body)"); + } catch (_) { + // manually deselect the old selection when a new category is selected + for (let button of d.querySelectorAll("button.category_button")) { + searxng.on(button, 'click', () => { + const selected = d.querySelector("button.category_button.selected"); + console.log(selected); + selected.classList.remove("selected"); + }) + } + } }); })(window, document, window.searxng); diff --git a/searx/static/themes/simple/src/less/search.less b/searx/static/themes/simple/src/less/search.less index e70ef30ad..4b5ef3b94 100644 --- a/searx/static/themes/simple/src/less/search.less +++ b/searx/static/themes/simple/src/less/search.less @@ -23,12 +23,15 @@ "spacer categories"; } -.category { +.category_checkbox, +.category_button { display: inline-block; position: relative; .ltr-margin-right(1rem); padding: 0; +} +.category_checkbox { input { display: none; } @@ -57,6 +60,35 @@ } } +button.category_button { + background-color: inherit; + color: var(--color-base-font); + cursor: pointer; + padding: 0.2rem 0; + display: inline-flex; + align-items: center; + text-transform: capitalize; + font-size: 0.9em; + border: none; + border-bottom: 2px solid transparent; + + svg { + padding-right: 0.2rem; + } + + &.selected, + &:active, + &:focus-within { + color: var(--color-categories-item-selected-font); + border-bottom: 2px solid var(--color-categories-item-border-selected); + } +} + +#categories_container:has(button.category_button:focus-within) button.category_button.selected { + color: var(--color-base-font); + border-bottom: none; +} + #search_logo { grid-area: logo; display: flex; @@ -205,11 +237,6 @@ html.no-js #clear_search.hide_if_nojs { #categories { font-size: 90%; clear: both; - - .checkbox_container { - margin: auto; - margin-top: 2px; - } } } @@ -219,7 +246,7 @@ html.no-js #clear_search.hide_if_nojs { #categories_container { width: max-content; - .category { + .category_checkbox { display: inline-block; width: auto; } @@ -271,16 +298,23 @@ html.no-js #clear_search.hide_if_nojs { width: auto; margin: 0; + svg { + display: none; + } + } + + .category_checkbox { label { padding: 1rem !important; margin: 0 !important; - - svg { - display: none; - } } } + .category_button { + padding: 1rem !important; + margin: 0 !important; + } + #search_view:focus-within { display: block; background-color: var(--color-search-background); |