Fixed tab menu change on location hash update
authorAlexander Ebert <ebert@woltlab.com>
Sat, 8 Oct 2016 12:05:17 +0000 (14:05 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 8 Oct 2016 12:05:23 +0000 (14:05 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js

index 347c4322f184bb9d1252528c29bca55bd1e9cb36..1762f77c8785440b44931bc7755dfb6dae31a9e0 100644 (file)
@@ -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);
+                                               }
+                                       });
+                               }
+                       });
                },
                
                /**
index 3bc3b93a4d91e7616500263f713724f9ea366bc2..53c3bf57d3ba65ce8a36c6b71ec0ac2c7e20e45a 100644 (file)
@@ -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.
                 *