diff options
| author | Ivan Gabaldon <igabaldon@inetol.net> | 2025-06-28 11:10:58 +0200 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarIT.de> | 2025-07-03 17:35:05 +0200 |
| commit | 879ac4e60f14a30cddd61e024ed4ad93179bb9d6 (patch) | |
| tree | a25886efe9141db3d5087cad2ed034894641e42e /client/simple/src/js/main/00_toolkit.js | |
| parent | 95172213f69c8fe85a0af69dd2654c7a77327968 (diff) | |
[mod] theme/simple: fmt/lint major pass
*Not so safe* changes, no behaviour changes.
- More ES5 to ES2015+ conversion.
- Make Biome not cry anymore applying remaining changes.
Diffstat (limited to 'client/simple/src/js/main/00_toolkit.js')
| -rw-r--r-- | client/simple/src/js/main/00_toolkit.js | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/client/simple/src/js/main/00_toolkit.js b/client/simple/src/js/main/00_toolkit.js index ca5e1d0e0..81e5071f9 100644 --- a/client/simple/src/js/main/00_toolkit.js +++ b/client/simple/src/js/main/00_toolkit.js @@ -17,8 +17,8 @@ window.searxng = ((w, d) => { ElementPrototype.webkitMatchesSelector || ElementPrototype.msMatchesSelector || function (selector) { - var nodes = (this.parentNode || this.document).querySelectorAll(selector), - i = -1; + const nodes = (this.parentNode || this.document).querySelectorAll(selector); + let i = -1; while (nodes[++i] && nodes[i] !== this); return !!nodes[i]; }; @@ -33,7 +33,7 @@ window.searxng = ((w, d) => { } } - var searxng = window.searxng || {}; + const searxng = window.searxng || {}; searxng.on = (obj, eventType, callback, useCapture) => { useCapture = useCapture || false; @@ -45,10 +45,20 @@ window.searxng = ((w, d) => { d.addEventListener( eventType, (e) => { - var el = e.target || e.srcElement, - found = false; - while (el?.matches && el !== d && !(found = el.matches(obj))) el = el.parentElement; - if (found) callbackSafe(callback, el, e); + let el = e.target || e.srcElement; + let found = false; + + while (el?.matches && el !== d) { + found = el.matches(obj); + + if (found) break; + + el = el.parentElement; + } + + if (found) { + callbackSafe(callback, el, e); + } }, useCapture ); @@ -66,7 +76,7 @@ window.searxng = ((w, d) => { searxng.http = (method, url, data = null) => new Promise((resolve, reject) => { try { - var req = new XMLHttpRequest(); + const req = new XMLHttpRequest(); req.open(method, url, true); req.timeout = 20000; @@ -104,9 +114,9 @@ window.searxng = ((w, d) => { }); searxng.loadStyle = (src) => { - var path = searxng.settings.theme_static_path + "/" + src, - id = "style_" + src.replace(".", "_"), - s = d.getElementById(id); + const path = `${searxng.settings.theme_static_path}/${src}`; + const id = `style_${src.replace(".", "_")}`; + let s = d.getElementById(id); if (s === null) { s = d.createElement("link"); s.setAttribute("id", id); @@ -118,9 +128,9 @@ window.searxng = ((w, d) => { }; searxng.loadScript = (src, callback) => { - var path = searxng.settings.theme_static_path + "/" + src, - id = "script_" + src.replace(".", "_"), - s = d.getElementById(id); + const path = `${searxng.settings.theme_static_path}/${src}`; + const id = `script_${src.replace(".", "_")}`; + let s = d.getElementById(id); if (s === null) { s = d.createElement("script"); s.setAttribute("id", id); @@ -137,7 +147,7 @@ window.searxng = ((w, d) => { console.log(exception); } } else { - console.log("callback not executed : script '" + path + "' not loaded."); + console.log(`callback not executed : script '${path}' not loaded.`); } }; @@ -154,7 +164,7 @@ window.searxng = ((w, d) => { }); function getEndpoint() { - for (var className of d.getElementsByTagName("body")[0].classList.values()) { + for (const className of d.getElementsByTagName("body")[0].classList.values()) { if (className.endsWith("_endpoint")) { return className.split("_")[0]; } |