From: Alexander Ebert Date: Wed, 22 Nov 2023 15:55:42 +0000 (+0100) Subject: Fix the detection of dynamically added user consent buttons X-Git-Tag: 6.0.3_dev_1~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=6302c1b15f9b34fd657f8c6ee82c40c82222b080;p=GitHub%2FWoltLab%2FWCF.git Fix the detection of dynamically added user consent buttons See https://www.woltlab.com/community/thread/302467-display-all-external-content-button-does-not-work-after-erroneous-field-message/ --- diff --git a/ts/WoltLabSuite/Core/Ui/Message/UserConsent.ts b/ts/WoltLabSuite/Core/Ui/Message/UserConsent.ts index 65ca0ef197..bbc2aa1ab9 100644 --- a/ts/WoltLabSuite/Core/Ui/Message/UserConsent.ts +++ b/ts/WoltLabSuite/Core/Ui/Message/UserConsent.ts @@ -6,6 +6,7 @@ * @license GNU Lesser General Public License */ +import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector"; import * as Ajax from "../../Ajax"; import * as Core from "../../Core"; import DomChangeListener from "../../Dom/Change/Listener"; @@ -14,7 +15,6 @@ import User from "../../User"; class UserConsent { private enableAll = false; - private readonly knownButtons = new WeakSet(); constructor() { if (window.sessionStorage.getItem(`${Core.getStoragePrefix()}user-consent`) === "all") { @@ -30,12 +30,8 @@ class UserConsent { if (this.enableAll) { this.enableAllExternalMedia(); } else { - document.querySelectorAll(".jsButtonMessageUserConsentEnable").forEach((button: HTMLAnchorElement) => { - if (!this.knownButtons.has(button)) { - this.knownButtons.add(button); - - button.addEventListener("click", (ev) => this.click(ev)); - } + wheneverFirstSeen(".jsButtonMessageUserConsentEnable", (button) => { + button.addEventListener("click", (event) => this.click(event)); }); } } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/UserConsent.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/UserConsent.js index 73f24d8fc9..bd7b95a1d9 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/UserConsent.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Message/UserConsent.js @@ -5,7 +5,7 @@ * @copyright 2001-2020 WoltLab GmbH * @license GNU Lesser General Public License */ -define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Change/Listener", "../../Dom/Util", "../../User"], function (require, exports, tslib_1, Ajax, Core, Listener_1, Util_1, User_1) { +define(["require", "exports", "tslib", "WoltLabSuite/Core/Helper/Selector", "../../Ajax", "../../Core", "../../Dom/Change/Listener", "../../Dom/Util", "../../User"], function (require, exports, tslib_1, Selector_1, Ajax, Core, Listener_1, Util_1, User_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.init = void 0; @@ -16,7 +16,6 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch User_1 = tslib_1.__importDefault(User_1); class UserConsent { enableAll = false; - knownButtons = new WeakSet(); constructor() { if (window.sessionStorage.getItem(`${Core.getStoragePrefix()}user-consent`) === "all") { this.enableAll = true; @@ -29,11 +28,8 @@ define(["require", "exports", "tslib", "../../Ajax", "../../Core", "../../Dom/Ch this.enableAllExternalMedia(); } else { - document.querySelectorAll(".jsButtonMessageUserConsentEnable").forEach((button) => { - if (!this.knownButtons.has(button)) { - this.knownButtons.add(button); - button.addEventListener("click", (ev) => this.click(ev)); - } + (0, Selector_1.wheneverFirstSeen)(".jsButtonMessageUserConsentEnable", (button) => { + button.addEventListener("click", (event) => this.click(event)); }); } }