diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2021-11-30 12:43:18 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarit.de> | 2021-11-30 12:43:18 +0100 |
| commit | 4798acc6615efada91c8fb29083a521daf5e1e27 (patch) | |
| tree | b7926f91cee25b90369ac9d6410b0f679b13eb3e /searx/static/themes/simple/js/searxng.js | |
| parent | 7dc9cc91a89ba482b4de2ea2acb47044aca87bcb (diff) | |
[build] /static
Diffstat (limited to 'searx/static/themes/simple/js/searxng.js')
| -rw-r--r-- | searx/static/themes/simple/js/searxng.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/searx/static/themes/simple/js/searxng.js b/searx/static/themes/simple/js/searxng.js index 830c21d61..c84227541 100644 --- a/searx/static/themes/simple/js/searxng.js +++ b/searx/static/themes/simple/js/searxng.js @@ -879,8 +879,19 @@ searxng.ready(function() { * * @license Free to use under the MIT License. * +* @example <caption>Example usage of searxng.ImageLayout class.</caption> +* searxng.image_thumbnail_layout = new searxng.ImageLayout( +* '#urls', // container_selector +* '#urls .result-images', // results_selector +* 'img.image_thumbnail', // img_selector +* 14, // verticalMargin +* 6, // horizontalMargin +* 200 // maxHeight +* ); +* searxng.image_thumbnail_layout.watch(); */ + (function (w, d) { function ImageLayout(container_selector, results_selector, img_selector, verticalMargin, horizontalMargin, maxHeight) { this.container_selector = container_selector; @@ -1007,6 +1018,11 @@ searxng.ready(function() { var results_nodes = d.querySelectorAll(this.results_selector); var results_length = results_nodes.length; + function img_load_error(event) { + // console.log("ERROR can't load: " + event.originalTarget.src); + event.originalTarget.src = w.searxng.static_path + w.searxng.theme.img_load_error; + } + function throttleAlign() { if (obj.isAlignDone) { obj.isAlignDone = false; @@ -1017,15 +1033,22 @@ searxng.ready(function() { } } + // https://developer.mozilla.org/en-US/docs/Web/API/Window/pageshow_event w.addEventListener('pageshow', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/FileReader/load_event w.addEventListener('load', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event w.addEventListener('resize', throttleAlign); for (i = 0; i < results_length; i++) { img = results_nodes[i].querySelector(this.img_selector); if (img !== null && img !== undefined) { img.addEventListener('load', throttleAlign); + // https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror img.addEventListener('error', throttleAlign); + if (w.searxng.theme.img_load_error) { + img.addEventListener('error', img_load_error, {once: true}); + } } } }; |