From: Matthias Schmidt Date: Tue, 16 Mar 2021 11:26:06 +0000 (+0100) Subject: Only add DOM change listener once in `Ui/Empty` X-Git-Tag: 5.4.0_Alpha_1~152 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6dc92dd22bac11a664bca14d3c91b5329cdebc5b;p=GitHub%2FWoltLab%2FWCF.git Only add DOM change listener once in `Ui/Empty` See #4073 --- diff --git a/ts/WoltLabSuite/Core/Ui/Empty.ts b/ts/WoltLabSuite/Core/Ui/Empty.ts index fd2074c147..8f025ed1ea 100644 --- a/ts/WoltLabSuite/Core/Ui/Empty.ts +++ b/ts/WoltLabSuite/Core/Ui/Empty.ts @@ -28,13 +28,15 @@ const observer = new MutationObserver((mutations) => { }); }); -export function setup(): void { +function observeElements(): void { document.querySelectorAll(".jsReloadPageWhenEmpty").forEach((el) => { el.classList.remove("jsReloadPageWhenEmpty"); observer.observe(el, { childList: true, }); }); - - DomChangeListener.add("WoltLabSuite/Core/Ui/Empty", () => setup()); +} +export function setup(): void { + observeElements(); + DomChangeListener.add("WoltLabSuite/Core/Ui/Empty", () => observeElements()); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Empty.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Empty.js index 6747b2c3c2..aa3358fa57 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Empty.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Empty.js @@ -27,14 +27,17 @@ define(["require", "exports", "tslib", "../Dom/Change/Listener"], function (requ } }); }); - function setup() { + function observeElements() { document.querySelectorAll(".jsReloadPageWhenEmpty").forEach((el) => { el.classList.remove("jsReloadPageWhenEmpty"); observer.observe(el, { childList: true, }); }); - Listener_1.default.add("WoltLabSuite/Core/Ui/Empty", () => setup()); + } + function setup() { + observeElements(); + Listener_1.default.add("WoltLabSuite/Core/Ui/Empty", () => observeElements()); } exports.setup = setup; });