From f03cf6f951d8742f72c2bd98117cd9eeb143ebe6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 8 Oct 2016 14:05:17 +0200 Subject: [PATCH] Fixed tab menu change on location hash update --- .../install/files/js/WoltLabSuite/Core/Ui/TabMenu.js | 12 ++++++++++++ .../files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js index 347c4322f1..1762f77c87 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js @@ -40,6 +40,18 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos disable: this._scrollDisable.bind(this), setup: this._scrollEnable.bind(this, true) }); + + window.addEventListener('hashchange', function () { + var hash = window.location.hash.replace(/^#/, ''); + var element = (hash) ? elById(hash) : null; + if (element !== null && element.classList.contains('tabMenuContent')) { + _tabMenus.forEach(function (tabMenu) { + if (tabMenu.hasTab(hash)) { + tabMenu.select(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 3bc3b93a4d..53c3bf57d3 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js @@ -291,6 +291,16 @@ define(['Dictionary', 'EventHandler', 'Dom/Traverse', 'Dom/Util'], function(Dict this.init(oldTabs); }, + /** + * Returns true if this tab menu has a tab with provided name. + * + * @param {string} name tab name + * @return {boolean} true if tab name matches + */ + hasTab: function (name) { + return this._tabs.has(name); + }, + /** * Handles clicks on a tab. * -- 2.20.1