Explicitly declare a non-passive event listener
authorAlexander Ebert <ebert@woltlab.com>
Mon, 10 May 2021 14:11:34 +0000 (16:11 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 10 May 2021 14:11:34 +0000 (16:11 +0200)
ts/WoltLabSuite/Core/Ui/Mobile.ts
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Mobile.js

index eff98789ea4d7be20a7656691fd1113dad2c0d0a..4f5f3ef7693f4fc89bd96e7b4506a5978945d792 100644 (file)
@@ -238,45 +238,49 @@ function toggleMobileNavigation(message: HTMLElement, quickOptions: HTMLElement,
 function setupLGTouchNavigation(): void {
   _enabledLGTouchNavigation = true;
   document.querySelectorAll(".boxMenuHasChildren > a").forEach((element: HTMLElement) => {
-    element.addEventListener("touchstart", function (event) {
-      if (_enabledLGTouchNavigation && element.getAttribute("aria-expanded") === "false") {
-        event.preventDefault();
-
-        element.setAttribute("aria-expanded", "true");
-
-        // Register an new event listener after the touch ended, which is triggered once when an
-        // element on the page is pressed. This allows us to reset the touch status of the navigation
-        // entry when the entry is no longer open, so that it does not redirect to the page when you
-        // click it again.
-        element.addEventListener(
-          "touchend",
-          () => {
-            document.body.addEventListener(
-              "touchstart",
-              () => {
-                document.body.addEventListener(
-                  "touchend",
-                  (event) => {
-                    const parent = element.parentElement!;
-                    const target = event.target as HTMLElement;
-                    if (!parent.contains(target) && target !== parent) {
-                      element.setAttribute("aria-expanded", "false");
-                    }
-                  },
-                  {
-                    once: true,
-                  },
-                );
-              },
-              {
-                once: true,
-              },
-            );
-          },
-          { once: true },
-        );
-      }
-    });
+    element.addEventListener(
+      "touchstart",
+      (event) => {
+        if (_enabledLGTouchNavigation && element.getAttribute("aria-expanded") === "false") {
+          event.preventDefault();
+
+          element.setAttribute("aria-expanded", "true");
+
+          // Register an new event listener after the touch ended, which is triggered once when an
+          // element on the page is pressed. This allows us to reset the touch status of the navigation
+          // entry when the entry is no longer open, so that it does not redirect to the page when you
+          // click it again.
+          element.addEventListener(
+            "touchend",
+            () => {
+              document.body.addEventListener(
+                "touchstart",
+                () => {
+                  document.body.addEventListener(
+                    "touchend",
+                    (event) => {
+                      const parent = element.parentElement!;
+                      const target = event.target as HTMLElement;
+                      if (!parent.contains(target) && target !== parent) {
+                        element.setAttribute("aria-expanded", "false");
+                      }
+                    },
+                    {
+                      once: true,
+                    },
+                  );
+                },
+                {
+                  once: true,
+                },
+              );
+            },
+            { once: true },
+          );
+        }
+      },
+      { passive: false },
+    );
   });
 }
 
index 00c8f11849ef7e8bf4fd1255fe5a56be8a8e36ae..45de7cd1d4a92934c7f681d7f275b25b81fec1cd 100644 (file)
@@ -205,7 +205,7 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "../
     function setupLGTouchNavigation() {
         _enabledLGTouchNavigation = true;
         document.querySelectorAll(".boxMenuHasChildren > a").forEach((element) => {
-            element.addEventListener("touchstart", function (event) {
+            element.addEventListener("touchstart", (event) => {
                 if (_enabledLGTouchNavigation && element.getAttribute("aria-expanded") === "false") {
                     event.preventDefault();
                     element.setAttribute("aria-expanded", "true");
@@ -229,7 +229,7 @@ define(["require", "exports", "tslib", "../Core", "../Dom/Change/Listener", "../
                         });
                     }, { once: true });
                 }
-            });
+            }, { passive: false });
         });
     }
     function enableLGTouchNavigation() {