summaryrefslogtreecommitdiff
path: root/searx/static
diff options
context:
space:
mode:
authorMarkus Heiser <markus.heiser@darmarit.de>2022-04-13 17:08:19 +0200
committerMarkus Heiser <markus.heiser@darmarit.de>2022-05-07 17:58:30 +0200
commited2a4c80879d2d3741514ea1117ab672b8f55d54 (patch)
tree6a1cb65e74ceade9372f65e2cfb7cb9e04322d3e /searx/static
parent9177172ea21852e16f00896806bf1b573fd9bb8f (diff)
downloadsearxng-ed2a4c80879d2d3741514ea1117ab672b8f55d54.tar.gz
searxng-ed2a4c80879d2d3741514ea1117ab672b8f55d54.zip
[mod] client_settings: pass settings from server to JS client
Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/static')
-rw-r--r--searx/static/themes/simple/src/js/head/00_init.js23
-rw-r--r--searx/static/themes/simple/src/js/main/00_toolkit.js4
-rw-r--r--searx/static/themes/simple/src/js/main/infinite_scroll.js4
-rw-r--r--searx/static/themes/simple/src/js/main/keyboard.js2
-rw-r--r--searx/static/themes/simple/src/js/main/preferences.js2
-rw-r--r--searx/static/themes/simple/src/js/main/search.js8
6 files changed, 14 insertions, 29 deletions
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 acd437f39..4aeece8c2 100644
--- a/searx/static/themes/simple/src/js/head/00_init.js
+++ b/searx/static/themes/simple/src/js/head/00_init.js
@@ -1,9 +1,4 @@
-/**
- * @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
- */
+/* SPDX-License-Identifier: AGPL-3.0-or-later */
(function (w, d) {
'use strict';
@@ -13,23 +8,13 @@
return scripts[scripts.length - 1];
})();
- // try to detect touch screen
w.searxng = {
- 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 <img src='...'> failed
- img_load_error: 'img/img_load_error.svg'
- }
+ settings: JSON.parse(atob(script.getAttribute('client_settings')))
};
// update the css
var hmtlElement = d.getElementsByTagName("html")[0];
hmtlElement.classList.remove('no-js');
hmtlElement.classList.add('js');
-})(window, document); \ No newline at end of file
+
+})(window, document);
diff --git a/searx/static/themes/simple/src/js/main/00_toolkit.js b/searx/static/themes/simple/src/js/main/00_toolkit.js
index f53842d72..699731ee4 100644
--- a/searx/static/themes/simple/src/js/main/00_toolkit.js
+++ b/searx/static/themes/simple/src/js/main/00_toolkit.js
@@ -101,7 +101,7 @@ window.searxng = (function (w, d) {
};
searxng.loadStyle = function (src) {
- var path = searxng.static_path + src,
+ var path = searxng.settings.theme_static_path + src,
id = "style_" + src.replace('.', '_'),
s = d.getElementById(id);
if (s === null) {
@@ -115,7 +115,7 @@ window.searxng = (function (w, d) {
};
searxng.loadScript = function (src, callback) {
- var path = searxng.static_path + src,
+ var path = searxng.settings.theme_static_path + src,
id = "script_" + src.replace('.', '_'),
s = d.getElementById(id);
if (s === null) {
diff --git a/searx/static/themes/simple/src/js/main/infinite_scroll.js b/searx/static/themes/simple/src/js/main/infinite_scroll.js
index b900e66e2..07db3305a 100644
--- a/searx/static/themes/simple/src/js/main/infinite_scroll.js
+++ b/searx/static/themes/simple/src/js/main/infinite_scroll.js
@@ -62,7 +62,7 @@ searxng.ready(function () {
function (err) {
console.log(err);
var e = d.createElement('div');
- e.textContent = searxng.translations.error_loading_next_page;
+ e.textContent = searxng.settings.translations.error_loading_next_page;
e.classList.add('dialog-error');
e.setAttribute('role', 'alert');
replaceChildrenWith(d.querySelector('#pagination'), [ e ]);
@@ -70,7 +70,7 @@ searxng.ready(function () {
)
}
- if (searxng.infinite_scroll && searxng.infinite_scroll_supported) {
+ if (searxng.settings.infinite_scroll && searxng.infinite_scroll_supported) {
const intersectionObserveOptions = {
rootMargin: "20rem",
};
diff --git a/searx/static/themes/simple/src/js/main/keyboard.js b/searx/static/themes/simple/src/js/main/keyboard.js
index a8ab7222f..f29ed86f4 100644
--- a/searx/static/themes/simple/src/js/main/keyboard.js
+++ b/searx/static/themes/simple/src/js/main/keyboard.js
@@ -154,7 +154,7 @@ searxng.ready(function () {
}
};
- if (searxng.hotkeys) {
+ if (searxng.settings.hotkeys) {
searxng.on(document, "keydown", function (e) {
// check for modifiers so we don't break browser's hotkeys
if (Object.prototype.hasOwnProperty.call(vimKeys, e.keyCode) && !e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey) {
diff --git a/searx/static/themes/simple/src/js/main/preferences.js b/searx/static/themes/simple/src/js/main/preferences.js
index 09f9cdde4..1e3ae5981 100644
--- a/searx/static/themes/simple/src/js/main/preferences.js
+++ b/searx/static/themes/simple/src/js/main/preferences.js
@@ -15,7 +15,7 @@
for (const [engine_name, description] of Object.entries(engine_descriptions)) {
let elements = d.querySelectorAll('[data-engine-name="' + engine_name + '"] .engine-description');
for (const element of elements) {
- let source = ' (<i>' + searxng.translations['Source'] + ':&nbsp;' + description[1] + '</i>)';
+ let source = ' (<i>' + searxng.settings.translations.Source + ':&nbsp;' + description[1] + '</i>)';
element.innerHTML = description[0] + source;
}
}
diff --git a/searx/static/themes/simple/src/js/main/search.js b/searx/static/themes/simple/src/js/main/search.js
index 798c9b2d3..edd68d259 100644
--- a/searx/static/themes/simple/src/js/main/search.js
+++ b/searx/static/themes/simple/src/js/main/search.js
@@ -59,11 +59,11 @@
createClearButton(qinput);
// autocompleter
- if (searxng.autocompleter) {
+ if (searxng.settings.autocomplete_provider) {
searxng.autocomplete = AutoComplete.call(w, {
Url: "./autocompleter",
- EmptyMessage: searxng.translations.no_item_found,
- HttpMethod: searxng.method,
+ EmptyMessage: searxng.settings.translations.no_item_found,
+ HttpMethod: searxng.settings.http_method,
HttpHeaders: {
"Content-type": "application/x-www-form-urlencoded",
"X-Requested-With": "XMLHttpRequest"
@@ -92,7 +92,7 @@
}
// vanilla js version of search_on_category_select.js
- if (qinput !== null && d.querySelector('.help') != null && searxng.search_on_category_select) {
+ if (qinput !== null && d.querySelector('.help') != null && searxng.settings.search_on_category_select) {
d.querySelector('.help').className = 'invisible';
searxng.on('#categories input', 'change', function () {