From: Alexander Ebert Date: Sat, 4 Mar 2017 13:51:21 +0000 (+0100) Subject: Fixed tab menu interaction X-Git-Tag: 3.1.0_Alpha_1~609 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f5a0c36c3de5b153a2480dcfde9b6e98710dbf53;p=GitHub%2FWoltLab%2FWCF.git Fixed tab menu interaction See #2223 --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js index 16e6a2076b..c5cd39deb9 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js @@ -41,7 +41,7 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos }); window.addEventListener('hashchange', function () { - var hash = window.location.hash.replace(/^#/, ''); + var hash = SimpleTabMenu.getIdentifierFromHash(); var element = (hash) ? elById(hash) : null; if (element !== null && element.classList.contains('tabMenuContent')) { _tabMenus.forEach(function (tabMenu) { @@ -52,8 +52,8 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos } }); - if (window.location.hash.match(/^#(.*)$/)) { - var hash = RegExp.$1; + var hash = SimpleTabMenu.getIdentifierFromHash(); + if (hash) { window.setTimeout(function () { // check if page was initially scrolled using a tab id var tabMenuContent = elById(hash); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js index 00f736b5ca..4806e45559 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js @@ -129,12 +129,9 @@ define(['Dictionary', 'EventHandler', 'Dom/Traverse', 'Dom/Util'], function(Dict var returnValue = null; if (!oldTabs) { - var hash = window.location.hash.replace(/^#/, ''), selectTab = null; + var hash = TabMenuSimple.getIdentifierFromHash(); + var selectTab = null; if (hash !== '') { - if (hash.match(/^(.+)\/.*$/)) { - hash = RegExp.$1; - } - selectTab = this._tabs.get(hash); // check for parent tab menu @@ -276,11 +273,20 @@ define(['Dictionary', 'EventHandler', 'Dom/Traverse', 'Dom/Util'], function(Dict }); } + var location = window.location.href.replace(/#[^#]+$/, ''); + if (TabMenuSimple.getIdentifierFromHash() === name) { + location += window.location.hash; + } + else { + location += '#' + name; + } + // update history + //noinspection JSCheckFunctionSignatures window.history.replaceState( undefined, undefined, - window.location.href.replace(/#[^#]+$/, '') + '#' + name + location ); } @@ -382,5 +388,13 @@ define(['Dictionary', 'EventHandler', 'Dom/Traverse', 'Dom/Util'], function(Dict } }; + TabMenuSimple.getIdentifierFromHash = function () { + if (window.location.hash.match(/^#([^\/]+)+(?:\/.+)?/)) { + return RegExp.$1; + } + + return ''; + }; + return TabMenuSimple; });