From: Alexander Ebert Date: Sun, 17 Jul 2016 19:33:20 +0000 (+0200) Subject: Code cleanup X-Git-Tag: 3.0.0_Beta_1~1055 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=dbbe141b2cc99a503d8273a0055c56d66f8d4862;p=GitHub%2FWoltLab%2FWCF.git Code cleanup --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 032d892e8e..24fe5f84dd 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -2757,18 +2757,6 @@ WCF.String = { * which will be filled with the currently selected tab. */ WCF.TabMenu = { - /** - * list of tabmenu containers - * @var object - */ - _containers: { }, - - /** - * initialization state - * @var boolean - */ - _didInit: false, - /** * Initializes all TabMenus */ @@ -2776,228 +2764,13 @@ WCF.TabMenu = { require(['WoltLab/WCF/Ui/TabMenu'], function(UiTabMenu) { UiTabMenu.setup(); }); - - return; - - var $containers = $('.tabMenuContainer:not(.staticTabMenuContainer)'); - var self = this; - $containers.each(function(index, tabMenu) { - var $tabMenu = $(tabMenu); - var $containerID = $tabMenu.wcfIdentify(); - if (self._containers[$containerID]) { - // continue with next container - return true; - } - - if ($tabMenu.data('store') && !$('#' + $tabMenu.data('store')).length) { - $('').appendTo($tabMenu.parents('form').find('.formSubmit')); - } - - // init jQuery UI TabMenu - self._containers[$containerID] = $tabMenu; - $tabMenu.wcfTabs({ - active: false, - activate: function(event, eventData) { - var $panel = $(eventData.newPanel); - var $container = $panel.closest('.tabMenuContainer'); - - // store currently selected item - var $tabMenu = $container; - while (true) { - // do not trigger on init - if ($tabMenu.data('isParent') === undefined) { - break; - } - - if ($tabMenu.data('isParent')) { - if ($tabMenu.data('store')) { - $('#' + $tabMenu.data('store')).val($panel.attr('id')); - } - - break; - } - else { - $tabMenu = $tabMenu.data('parent'); - } - } - - // set panel id as location hash - if (WCF.TabMenu._didInit) { - // do not update history if within an overlay - if ($panel.data('inTabMenu') == undefined) { - $panel.data('inTabMenu', ($panel.parents('.dialogContainer').length)); - } - - if (!$panel.data('inTabMenu')) { - if (window.history) { - window.history.pushState(null, document.title, window.location.toString().replace(/#.+$/, '') + '#' + $panel.attr('id')); - } - else { - location.hash = '#' + $panel.attr('id'); - } - } - } - } - }); - - $tabMenu.data('isParent', ($tabMenu.children('.tabMenuContainer, .tabMenuContent').length > 0)).data('parent', false); - if (!$tabMenu.data('isParent')) { - // check if we're a child element - if ($tabMenu.parent().hasClass('tabMenuContainer')) { - $tabMenu.data('parent', $tabMenu.parent()); - } - } - }); - - // try to resolve location hash - if (!this._didInit) { - this._selectActiveTab(); - $(window).bind('hashchange', $.proxy(this.selectTabs, this)); - - if (!this._selectErroneousTab()) { - this.selectTabs(); - } - - if ($.browser.mozilla && location.hash) { - var $target = $(location.hash); - if ($target.length && $target.hasClass('tabMenuContent')) { - var $offset = $target.offset(); - window.scrollTo($offset.left, $offset.top); - } - } - } - - this._didInit = true; }, /** * Reloads the tab menus. */ reload: function() { - this._containers = { }; this.init(); - }, - - /** - * Force display of first erroneous tab and returns true if at least one - * tab contains an error. - * - * @return boolean - */ - _selectErroneousTab: function() { - var $foundErrors = false; - for (var $containerID in this._containers) { - var $tabMenu = this._containers[$containerID]; - - if ($tabMenu.find('.formError').length) { - $foundErrors = true; - - if (!$tabMenu.data('isParent')) { - while (true) { - if ($tabMenu.data('parent') === false) { - break; - } - - $tabMenu = $tabMenu.data('parent').wcfTabs('selectTab', $tabMenu.wcfIdentify()); - } - - return true; - } - } - } - - // found an error in a non-nested tab menu - if ($foundErrors) { - for (var $containerID in this._containers) { - var $tabMenu = this._containers[$containerID]; - var $formError = $tabMenu.find('.formError:eq(0)'); - - if ($formError.length) { - // find the tab container - $tabMenu.wcfTabs('selectTab', $formError.parents('.tabMenuContent').wcfIdentify()); - - while (true) { - if ($tabMenu.data('parent') === false) { - break; - } - - $tabMenu = $tabMenu.data('parent').wcfTabs('selectTab', $tabMenu.wcfIdentify()); - } - - return 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('selectTab', $tabMenu.data('active')); - } - else { - $tabMenu.wcfTabs('selectTab', $tabMenu.data('active')); - } - } - - return false; - } - }); - } - } - }, - - /** - * Resolves location hash to display tab menus. - * - * @return boolean - */ - selectTabs: function() { - if (location.hash) { - var $hash = location.hash.substr(1); - - // try to find matching tab menu container - var $tabMenu = $('#' + $.wcfEscapeID($hash)); - if ($tabMenu.length === 1 && $tabMenu.hasClass('ui-tabs-panel')) { - $tabMenu = $tabMenu.parent('.ui-tabs'); - if ($tabMenu.length) { - $tabMenu.wcfTabs('selectTab', $hash); - - // check if this is a nested tab menu - if ($tabMenu.hasClass('ui-tabs-panel')) { - $hash = $tabMenu.wcfIdentify(); - $tabMenu = $tabMenu.parent('.ui-tabs'); - if ($tabMenu.length) { - $tabMenu.wcfTabs('selectTab', $hash); - } - } - - return true; - } - } - } - - return false; } };