Event listeners had been attached repeatedly
authorAlexander Ebert <ebert@woltlab.com>
Fri, 21 May 2021 13:42:39 +0000 (15:42 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 21 May 2021 13:42:39 +0000 (15:42 +0200)
ts/WoltLabSuite/Core/Ui/Redactor/Quote.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Quote.js

index 7e73f68d052af36f54956c71599bae282fe4690c..ad379d9ddec595b356042d2b7982ff72f6223b51 100644 (file)
@@ -31,6 +31,7 @@ let _headerHeight = 0;
 class UiRedactorQuote {
   protected readonly _editor: RedactorEditor;
   protected readonly _elementId: string;
+  protected readonly _knownElements = new WeakSet<HTMLElement>();
   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);
+      }
     });
   }
 
index c2fd05bfd3243a4a412ee8d023a4f0a50cac7e93..9d22917eb6259b8bb6be7af00c6a1fddbfcad84b 100644 (file)
@@ -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);
+                }
             });
         }
         /**