From: Alexander Ebert Date: Sun, 15 Jan 2017 18:48:57 +0000 (+0100) Subject: Scroll to tab menu if it was scrolled out of view X-Git-Tag: 3.0.1~38 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a677632130072e6f72441637e5f986037a8a2708;p=GitHub%2FWoltLab%2FWCF.git Scroll to tab menu if it was scrolled out of view --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js index 7c24ec81ba..16e6a2076b 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js @@ -12,7 +12,6 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos var _activeList = null; var _enableTabScroll = false; var _tabMenus = new Dictionary(); - var _scrollListenerUuid = null; /** * @exports WoltLabSuite/Core/Ui/TabMenu @@ -52,6 +51,35 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos }); } }); + + if (window.location.hash.match(/^#(.*)$/)) { + var hash = RegExp.$1; + window.setTimeout(function () { + // check if page was initially scrolled using a tab id + var tabMenuContent = elById(hash); + if (tabMenuContent && tabMenuContent.classList.contains('tabMenuContent')) { + var scrollY = (window.scrollY || window.pageYOffset); + if (scrollY > 0) { + var parent = tabMenuContent.parentNode; + var offsetTop = parent.offsetTop - 50; + if (offsetTop < 0) offsetTop = 0; + + if (scrollY > offsetTop) { + var y = DomUtil.offset(parent).top; + + if (y <= 50) { + y = 0; + } + else { + y -= 50; + } + + window.scrollTo(0, y); + } + } + } + }, 100); + } }, /**