From 059f4157faaf4796964a1c71556f948fdfe3a698 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Tue, 30 Nov 2021 19:31:55 +0100 Subject: [PATCH] [mod] simple theme: move initilization of document.searxng to searxng.min.js keep searxng.min.js as small as possible --- .../themes/simple/src/js/head/00_init.js | 32 ++++--------------- .../themes/simple/src/js/main/01_init.js | 31 ++++++++++++++++++ .../js/main/{00_toolkit.js => 02_toolkit.js} | 0 searx/templates/simple/base.html | 18 +++++------ 4 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 searx/static/themes/simple/src/js/main/01_init.js rename searx/static/themes/simple/src/js/main/{00_toolkit.js => 02_toolkit.js} (100%) diff --git a/searx/static/themes/simple/src/js/head/00_init.js b/searx/static/themes/simple/src/js/head/00_init.js index dab0e368a..86373fb37 100644 --- a/searx/static/themes/simple/src/js/head/00_init.js +++ b/searx/static/themes/simple/src/js/head/00_init.js @@ -8,33 +8,13 @@ (function(w, d) { 'use strict'; - // add data- properties - var script = d.currentScript || (function() { - var scripts = d.getElementsByTagName('script'); - return scripts[scripts.length - 1]; - })(); + // update the css + var hmtlElementClassList = d.getElementsByTagName("html")[0].classList; + hmtlElementClassList.remove('no-js'); + hmtlElementClassList.add('js'); // try to detect touch screen - w.searxng = { - touch: (("ontouchstart" in w) || w.DocumentTouch && document instanceof DocumentTouch) || false, - method: script.getAttribute('data-method'), - autocompleter: script.getAttribute('data-autocompleter') === 'true', - search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true', - infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true', - hotkeys: script.getAttribute('data-hotkeys') === 'true', - static_path: script.getAttribute('data-static-path'), - translations: JSON.parse(script.getAttribute('data-translations')), - theme : { - // image that is displayed if load of failed - img_load_error: 'img/img_load_error.svg' - } - }; - - // update the css - var hmtlElement = d.getElementsByTagName("html")[0]; - hmtlElement.classList.remove('no-js'); - hmtlElement.classList.add('js'); - if (w.searxng.touch) { - hmtlElement.classList.add('touch'); + if (("ontouchstart" in w) || w.DocumentTouch && d instanceof DocumentTouch) { + hmtlElementClassList.add('touch'); } })(window, document); \ No newline at end of file diff --git a/searx/static/themes/simple/src/js/main/01_init.js b/searx/static/themes/simple/src/js/main/01_init.js new file mode 100644 index 000000000..2d63585cc --- /dev/null +++ b/searx/static/themes/simple/src/js/main/01_init.js @@ -0,0 +1,31 @@ +/** + * @license + * (C) Copyright Contributors to the SearXNG project. + * (C) Copyright Contributors to the searx project (2014 - 2021). + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +(function(w, d) { + 'use strict'; + + // add data- properties + var script = d.currentScript || (function() { + var scripts = d.getElementsByTagName('script'); + return scripts[scripts.length - 1]; + })(); + + // try to detect touch screen + w.searxng = { + touch: d.getElementsByTagName("html")[0].classList.contains('touch'), + method: script.getAttribute('data-method'), + autocompleter: script.getAttribute('data-autocompleter') === 'true', + search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true', + infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true', + hotkeys: script.getAttribute('data-hotkeys') === 'true', + static_path: script.getAttribute('data-static-path'), + translations: JSON.parse(script.getAttribute('data-translations')), + theme : { + // image that is displayed if load of failed + img_load_error: 'img/img_load_error.svg' + }, + }; +})(window, document); \ No newline at end of file diff --git a/searx/static/themes/simple/src/js/main/00_toolkit.js b/searx/static/themes/simple/src/js/main/02_toolkit.js similarity index 100% rename from searx/static/themes/simple/src/js/main/00_toolkit.js rename to searx/static/themes/simple/src/js/main/02_toolkit.js diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html index bb1f51cad..0a8b93887 100644 --- a/searx/templates/simple/base.html +++ b/searx/templates/simple/base.html @@ -19,14 +19,7 @@ {% endif %} {% block styles %}{% endblock %} - + {% block head %} @@ -61,7 +54,14 @@

- +