From 7dc9cc91a89ba482b4de2ea2acb47044aca87bcb Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Tue, 30 Nov 2021 12:33:44 +0100 Subject: [PATCH] [mod] simple theme, JS: introduce window.searxng.theme namespace In window.searxng.theme the theme data can be passed through to JS implementations. Initial the window.searxng.theme namespace starts with a value for `img_load_error`:: // image that is displayed if load of failed img_load_error: 'img/img_load_error.svg' The searx/static/themes/__common__/js/image_layout.js is patched to uses the value, if the theme defines a value for img_load_error in this namespace. Signed-off-by: Markus Heiser --- searx/static/themes/__common__/js/image_layout.js | 6 ++++-- searx/static/themes/simple/src/js/head/00_init.js | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/searx/static/themes/__common__/js/image_layout.js b/searx/static/themes/__common__/js/image_layout.js index e178c2968..be4fe84e0 100644 --- a/searx/static/themes/__common__/js/image_layout.js +++ b/searx/static/themes/__common__/js/image_layout.js @@ -149,7 +149,7 @@ function img_load_error(event) { // console.log("ERROR can't load: " + event.originalTarget.src); - event.originalTarget.src = window.searxng.static_path + 'img/img_load_error.svg'; + event.originalTarget.src = w.searxng.static_path + w.searxng.theme.img_load_error; } function throttleAlign() { @@ -175,7 +175,9 @@ img.addEventListener('load', throttleAlign); // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror img.addEventListener('error', throttleAlign); - img.addEventListener('error', img_load_error, {once: true}); + if (w.searxng.theme.img_load_error) { + img.addEventListener('error', img_load_error, {once: true}); + } } } }; 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 21b1754bf..dab0e368a 100644 --- a/searx/static/themes/simple/src/js/head/00_init.js +++ b/searx/static/themes/simple/src/js/head/00_init.js @@ -24,6 +24,10 @@ 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