From 21adc182a961d7c74b20a4f290a807ac9812b66b Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 6 Jun 2015 15:01:04 +0200 Subject: [PATCH] Resolved a few issues concerning the ACP and WCFSetup --- wcfsetup/install/files/js/WCF.js | 2 +- .../files/js/WoltLab/WCF/DOM/Traverse.js | 12 ++++++++ .../js/WoltLab/WCF/UI/Dropdown/Simple.js | 6 ++-- .../files/js/WoltLab/WCF/UI/TabMenu.js | 17 +++++++++++ .../files/js/WoltLab/WCF/UI/TabMenu/Simple.js | 30 +++++++++++++++---- 5 files changed, 57 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 6febc82f2f..328fbf8422 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -8337,7 +8337,7 @@ jQuery.fn.extend({ document.body.appendChild(this[0]); } - UIDialog.show(id, null, (args.length === 1 && typeof args[0] === 'object') ? args[0] : {}); + UIDialog.openStatic(id, null, (args.length === 1 && typeof args[0] === 'object') ? args[0] : {}); } }).bind(this)); } diff --git a/wcfsetup/install/files/js/WoltLab/WCF/DOM/Traverse.js b/wcfsetup/install/files/js/WoltLab/WCF/DOM/Traverse.js index ea3132f24f..4ef2f4c8f7 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/DOM/Traverse.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/DOM/Traverse.js @@ -22,6 +22,10 @@ define(['DOM/Util'], function(DOMUtil) { ]; var _children = function(el, type, value) { + if (!(el instanceof Element)) { + throw new TypeError("Expected a valid element as first argument."); + } + var children = []; for (var i = 0; i < el.childElementCount; i++) { @@ -34,6 +38,10 @@ define(['DOM/Util'], function(DOMUtil) { }; var _parent = function(el, type, value) { + if (!(el instanceof Element)) { + throw new TypeError("Expected a valid element as first argument."); + } + el = el.parentNode; while (el instanceof Element) { @@ -48,6 +56,10 @@ define(['DOM/Util'], function(DOMUtil) { }; var _sibling = function(el, siblingType, type, value) { + if (!(el instanceof Element)) { + throw new TypeError("Expected a valid element as first argument."); + } + if (el instanceof Element) { if (el[siblingType] !== null && _probe[type](el[siblingType], value)) { return el[siblingType]; diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js index 296cc0d5e2..ef996ae0b5 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js @@ -7,8 +7,8 @@ * @module WoltLab/WCF/UI/Dropdown/Simple */ define( - [ 'CallbackList', 'Dictionary', 'UI/Alignment', 'DOM/ChangeListener', 'DOM/Traverse', 'DOM/Util', 'UI/CloseOverlay'], - function(CallbackList, Dictionary, UIAlignment, DOMChangeListener, DOMTraverse, DOMUtil, UICloseOverlay) + [ 'CallbackList', 'Core', 'Dictionary', 'UI/Alignment', 'DOM/ChangeListener', 'DOM/Traverse', 'DOM/Util', 'UI/CloseOverlay'], + function(CallbackList, Core, Dictionary, UIAlignment, DOMChangeListener, DOMTraverse, DOMUtil, UICloseOverlay) { "use strict"; @@ -92,7 +92,7 @@ define( button.setAttribute('data-target', containerId); if (isLazyInitialization) { - event.trigger(button, 'click'); + Core.triggerEvent(button, 'click'); } }, diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js index aa27b324db..b3f49a7f00 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu.js @@ -20,6 +20,7 @@ define(['Dictionary', 'DOM/ChangeListener', 'DOM/Util', './TabMenu/Simple'], fun */ setup: function() { this._init(); + this._selectErroneousTabs(); DOMChangeListener.add('WoltLab/WCF/UI/TabMenu', this._init.bind(this)); }, @@ -46,6 +47,22 @@ define(['Dictionary', 'DOM/ChangeListener', 'DOM/Util', './TabMenu/Simple'], fun } }, + /** + * Selects the first tab containing an element with class `formError`. + */ + _selectErroneousTabs: function() { + _tabMenus.forEach(function(tabMenu) { + var foundError = false; + tabMenu.getContainers().forEach(function(container) { + if (!foundError && container.getElementsByClassName('formError').length) { + foundError = true; + + tabMenu.select(container.id); + } + }); + }); + }, + /** * Returns a SimpleTabMenu instance for given container id. * diff --git a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js index 6e48d58735..4f26561f81 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/TabMenu/Simple.js @@ -6,7 +6,7 @@ * @license GNU Lesser General Public License * @module WoltLab/WCF/UI/TabMenu/Simple */ -define(['Dictionary', 'DOM/Util', 'EventHandler'], function(Dictionary, DOMUtil, EventHandler) { +define(['Dictionary', 'DOM/Traverse', 'DOM/Util', 'EventHandler'], function(Dictionary, DOMTraverse, DOMUtil, EventHandler) { "use strict"; /** @@ -29,15 +29,15 @@ define(['Dictionary', 'DOM/Util', 'EventHandler'], function(Dictionary, DOMUtil, * Validates the properties and DOM structure of this container. * * Expected DOM: - * + *
* * - * baz - * + *
baz
+ *
* * @return {boolean} false if any properties are invalid or the DOM does not match the expectations */ @@ -46,7 +46,7 @@ define(['Dictionary', 'DOM/Util', 'EventHandler'], function(Dictionary, DOMUtil, return false; } - var nav = document.querySelector('#' + this._containerId + ' > nav'); + var nav = DOMTraverse.childByTag(this._container, 'NAV'); if (nav === null) { return false; } @@ -57,7 +57,7 @@ define(['Dictionary', 'DOM/Util', 'EventHandler'], function(Dictionary, DOMUtil, return false; } - var containers = document.querySelectorAll('#' + this._containerId + ' > .tabMenuContent'); + var containers = DOMTraverse.childrenByTag(this._container, 'DIV'); for (var i = 0, length = containers.length; i < length; i++) { var container = containers[i]; var name = container.getAttribute('data-name'); @@ -289,6 +289,24 @@ define(['Dictionary', 'DOM/Util', 'EventHandler'], function(Dictionary, DOMUtil, } return name; + }, + + /** + * Returns the list of registered content containers. + * + * @returns {Dictionary} content containers + */ + getContainers: function() { + return this._containers; + }, + + /** + * Returns the list of registered tabs. + * + * @returns {Dictionary} tab items + */ + getTabs: function() { + return this._tabs; } }; -- 2.20.1