Fixed tab menu interaction
authorAlexander Ebert <ebert@woltlab.com>
Sat, 4 Mar 2017 13:51:21 +0000 (14:51 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 4 Mar 2017 13:51:21 +0000 (14:51 +0100)
See #2223

wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu/Simple.js

index 16e6a2076b767646f22ce54b79d9b2c7d025d933..c5cd39deb94129d34ade2a14ceba6f504b930845 100644 (file)
@@ -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);
index 00f736b5ca8835faa0d497db923de3ec2ab27531..4806e455594af3d4bded140e1cec69d958ee4835 100644 (file)
@@ -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;
 });