From 1fffd8d0d8af1493e64f905aa2a0356abd985c7a Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 5 May 2017 13:57:29 +0200 Subject: [PATCH] Improved scroll guard for dialogs `event.target` and the parent nodes are now evaluated to allow scrolling inside overflow containers, while still preventing page scrolling. See #2237 --- .../files/js/WoltLabSuite/Core/Ui/Dialog.js | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index a04e1ba9da..b388c8922c 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -341,11 +341,34 @@ define( dialog.appendChild(contentContainer); contentContainer.addEventListener('wheel', function (event) { - // positive value: scrolling up - if (event.wheelDelta > 0 && contentContainer.scrollTop === 0) { - event.preventDefault(); + var allowScroll = false; + var element = event.target, clientHeight, scrollHeight, scrollTop; + while (true) { + clientHeight = element.clientHeight; + scrollHeight = element.scrollHeight; + + if (clientHeight < scrollHeight) { + scrollTop = element.scrollTop; + + // positive value: scrolling up + if (event.wheelDelta > 0 && scrollTop > 0) { + allowScroll = true; + break; + } + else if (event.wheelDelta < 0 && (scrollTop + clientHeight < scrollHeight)) { + allowScroll = true; + break; + } + } + + if (!element || element === contentContainer) { + break; + } + + element = element.parentNode; } - else if (event.wheelDelta < 0 && (contentContainer.scrollTop + contentContainer.clientHeight === contentContainer.scrollHeight)) { + + if (allowScroll === false) { event.preventDefault(); } }); -- 2.20.1