From 5bdb5897886c43850770a64078a72b27b3181015 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 21 May 2021 15:42:39 +0200 Subject: [PATCH] Event listeners had been attached repeatedly --- ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts | 9 +++++++-- .../files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts b/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts index 7e73f68d05..ad379d9dde 100644 --- a/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts +++ b/ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts @@ -31,6 +31,7 @@ let _headerHeight = 0; class UiRedactorQuote { protected readonly _editor: RedactorEditor; protected readonly _elementId: string; + protected readonly _knownElements = new WeakSet(); protected _quote: HTMLElement | null = null; /** @@ -137,8 +138,12 @@ class UiRedactorQuote { */ protected _observeLoad(): void { document.querySelectorAll("woltlab-quote").forEach((quote: HTMLElement) => { - quote.addEventListener("mousedown", (ev) => this._edit(ev)); - this._setTitle(quote); + if (!this._knownElements.has(quote)) { + quote.addEventListener("mousedown", (ev) => this._edit(ev)); + this._setTitle(quote); + + this._knownElements.add(quote); + } }); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js index c2fd05bfd3..9d22917eb6 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js @@ -23,6 +23,7 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Util", "../../Ev * Initializes the quote management. */ constructor(editor, button) { + this._knownElements = new WeakSet(); this._quote = null; this._editor = editor; this._elementId = this._editor.$element[0].id; @@ -102,8 +103,11 @@ define(["require", "exports", "tslib", "../../Core", "../../Dom/Util", "../../Ev */ _observeLoad() { document.querySelectorAll("woltlab-quote").forEach((quote) => { - quote.addEventListener("mousedown", (ev) => this._edit(ev)); - this._setTitle(quote); + if (!this._knownElements.has(quote)) { + quote.addEventListener("mousedown", (ev) => this._edit(ev)); + this._setTitle(quote); + this._knownElements.add(quote); + } }); } /** -- 2.20.1