[mod] theme/simple: fmt/lint minor pass

*Safe* changes, no behaviour changes.

- Initial ES5 to ES2015+ conversion.
- Plenty of styling diff changes.
This commit is contained in:
Ivan Gabaldon 2025-06-28 10:19:15 +02:00 committed by Markus Heiser
parent a947d5b3cf
commit 95172213f6
13 changed files with 620 additions and 650 deletions

View file

@ -2,80 +2,77 @@
/* global searxng */
searxng.ready(function () {
'use strict';
searxng.ready(() => {
searxng.infinite_scroll_supported =
"IntersectionObserver" in window &&
"IntersectionObserverEntry" in window &&
"intersectionRatio" in window.IntersectionObserverEntry.prototype;
searxng.infinite_scroll_supported = (
'IntersectionObserver' in window &&
'IntersectionObserverEntry' in window &&
'intersectionRatio' in window.IntersectionObserverEntry.prototype);
if (searxng.endpoint !== 'results') {
if (searxng.endpoint !== "results") {
return;
}
if (!searxng.infinite_scroll_supported) {
console.log('IntersectionObserver not supported');
console.log("IntersectionObserver not supported");
return;
}
let d = document;
var onlyImages = d.getElementById('results').classList.contains('only_template_images');
const d = document;
var onlyImages = d.getElementById("results").classList.contains("only_template_images");
function newLoadSpinner () {
var loader = d.createElement('div');
loader.classList.add('loader');
function newLoadSpinner() {
var loader = d.createElement("div");
loader.classList.add("loader");
return loader;
}
function replaceChildrenWith (element, children) {
element.textContent = '';
children.forEach(child => element.appendChild(child));
function replaceChildrenWith(element, children) {
element.textContent = "";
children.forEach((child) => element.appendChild(child));
}
function loadNextPage (callback) {
var form = d.querySelector('#pagination form.next_page');
function loadNextPage(callback) {
var form = d.querySelector("#pagination form.next_page");
if (!form) {
return
return;
}
replaceChildrenWith(d.querySelector('#pagination'), [ newLoadSpinner() ]);
replaceChildrenWith(d.querySelector("#pagination"), [newLoadSpinner()]);
var formData = new FormData(form);
searxng.http('POST', d.querySelector('#search').getAttribute('action'), formData).then(
function (response) {
var nextPageDoc = new DOMParser().parseFromString(response, 'text/html');
var articleList = nextPageDoc.querySelectorAll('#urls article');
var paginationElement = nextPageDoc.querySelector('#pagination');
d.querySelector('#pagination').remove();
searxng
.http("POST", d.querySelector("#search").getAttribute("action"), formData)
.then((response) => {
var nextPageDoc = new DOMParser().parseFromString(response, "text/html");
var articleList = nextPageDoc.querySelectorAll("#urls article");
var paginationElement = nextPageDoc.querySelector("#pagination");
d.querySelector("#pagination").remove();
if (articleList.length > 0 && !onlyImages) {
// do not add <hr> element when there are only images
d.querySelector('#urls').appendChild(d.createElement('hr'));
d.querySelector("#urls").appendChild(d.createElement("hr"));
}
articleList.forEach(articleElement => {
d.querySelector('#urls').appendChild(articleElement);
articleList.forEach((articleElement) => {
d.querySelector("#urls").appendChild(articleElement);
});
if (paginationElement) {
d.querySelector('#results').appendChild(paginationElement);
d.querySelector("#results").appendChild(paginationElement);
callback();
}
}
).catch(
function (err) {
})
.catch((err) => {
console.log(err);
var e = d.createElement('div');
var e = d.createElement("div");
e.textContent = searxng.settings.translations.error_loading_next_page;
e.classList.add('dialog-error');
e.setAttribute('role', 'alert');
replaceChildrenWith(d.querySelector('#pagination'), [ e ]);
}
)
e.classList.add("dialog-error");
e.setAttribute("role", "alert");
replaceChildrenWith(d.querySelector("#pagination"), [e]);
});
}
if (searxng.settings.infinite_scroll && searxng.infinite_scroll_supported) {
const intersectionObserveOptions = {
rootMargin: "20rem",
rootMargin: "20rem"
};
const observedSelector = 'article.result:last-child';
const observer = new IntersectionObserver(entries => {
const observedSelector = "article.result:last-child";
const observer = new IntersectionObserver((entries) => {
const paginationEntry = entries[0];
if (paginationEntry.isIntersecting) {
observer.unobserve(paginationEntry.target);
@ -84,5 +81,4 @@ searxng.ready(function () {
});
observer.observe(d.querySelector(observedSelector), intersectionObserveOptions);
}
});