From: Alexander Ebert Date: Mon, 10 May 2021 14:11:34 +0000 (+0200) Subject: Explicitly declare a non-passive event listener X-Git-Tag: 5.4.0_Alpha_2~15 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=04653e2e29df634c566153b1da2a757538f60a94;p=GitHub%2FWoltLab%2FWCF.git Explicitly declare a non-passive event listener --- diff --git a/ts/WoltLabSuite/Core/Ui/Mobile.ts b/ts/WoltLabSuite/Core/Ui/Mobile.ts index eff98789ea..4f5f3ef769 100644 --- a/ts/WoltLabSuite/Core/Ui/Mobile.ts +++ b/ts/WoltLabSuite/Core/Ui/Mobile.ts @@ -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 }, + ); }); } diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Mobile.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Mobile.js index 00c8f11849..45de7cd1d4 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Mobile.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Mobile.js @@ -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() {