From da804832b4319d6d27de900aad6427599d8fb774 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 29 Oct 2012 17:30:26 +0100 Subject: [PATCH] Fixed marking of active tab if used with nested tabs --- wcfsetup/install/files/js/WCF.js | 72 +++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 504fbc635b..5a702cf491 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -2856,16 +2856,6 @@ WCF.TabMenu = { } }); - // display active item on init - if ($tabMenu.data('active')) { - $tabMenu.find('.tabMenuContent').each(function(innerIndex, tabMenuItem) { - var $tabMenuItem = $(tabMenuItem); - if ($tabMenuItem.attr('id') == $tabMenu.data('active')) { - $tabMenu.wcfTabs('select', innerIndex); - } - }); - } - $tabMenu.data('isParent', ($tabMenu.children('.tabMenuContainer').length > 0)).data('parent', false); if (!$tabMenu.data('isParent')) { // check if we're a child element @@ -2879,11 +2869,25 @@ WCF.TabMenu = { if (!this._didInit) { this.selectTabs(); $(window).bind('hashchange', $.proxy(this.selectTabs, this)); + + if (!this._selectErroneousTab()) { + this._selectActiveTab(); + } } - // force display of first erroneous tab + this._didInit = true; + }, + + /** + * Force display of first erroneous tab, returns true, if at + * least one tab contains an error. + * + * @return boolean + */ + _selectErroneousTab: function() { for (var $containerID in this._containers) { var $tabMenu = this._containers[$containerID]; + if (!$tabMenu.data('isParent') && $tabMenu.find('.formError').length) { while (true) { if ($tabMenu.data('parent') === false) { @@ -2893,11 +2897,47 @@ WCF.TabMenu = { $tabMenu = $tabMenu.data('parent').wcfTabs('select', $tabMenu.wcfIdentify()); } - break; + return true; } } - this._didInit = true; + return false; + }, + + /** + * Selects the active tab menu item. + */ + _selectActiveTab: function() { + for (var $containerID in this._containers) { + var $tabMenu = this._containers[$containerID]; + if ($tabMenu.data('active')) { + var $index = $tabMenu.data('active'); + var $subIndex = null; + if (/-/.test($index)) { + var $tmp = $index.split('-'); + $index = $tmp[0]; + $subIndex = $tmp[1]; + } + + $tabMenu.find('.tabMenuContent').each(function(innerIndex, tabMenuItem) { + var $tabMenuItem = $(tabMenuItem); + if ($tabMenuItem.wcfIdentify() == $index) { + $tabMenu.wcfTabs('select', innerIndex); + + if ($subIndex !== null) { + if ($tabMenuItem.hasClass('tabMenuContainer')) { + $tabMenuItem.wcfTabs('select', $tabMenu.data('active')); + } + else { + $tabMenu.wcfTabs('select', $tabMenu.data('active')); + } + } + + return false; + } + }); + } + } }, /** @@ -2937,12 +2977,6 @@ WCF.TabMenu = { } } } - else { - // revert to default values - for (var $containerID in this._containers) { - this._containers[$containerID].wcfTabs('revertToDefault'); - } - } } }; -- 2.20.1