From f0aa83bef648c2c3d7c570d0dae1b748ec2b0e6d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 24 Jun 2015 19:25:45 +0200 Subject: [PATCH] Improved `UI/SimpleDropdown` --- .../js/WoltLab/WCF/UI/Dropdown/Simple.js | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) 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 ca345a62c5..1fc5326631 100644 --- a/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js +++ b/wcfsetup/install/files/js/WoltLab/WCF/UI/Dropdown/Simple.js @@ -195,6 +195,33 @@ define( this.setAlignment(dropdown, menu); }, + /** + * Returns true if target dropdown exists and is open. + * + * @param {string} containerId dropdown wrapper id + * @return {boolean} true if dropdown exists and is open + */ + isOpen: function(containerId) { + var menu = _menus.get(containerId); + if (menu !== undefined && menu.classList.contains('dropdownOpen')) { + return true; + } + + return false; + }, + + /** + * Opens the dropdown unless it is already open. + * + * @param {string} containerId dropdown wrapper id + */ + open: function(containerId) { + var menu = _menus.get(containerId); + if (menu !== undefined && !menu.classList.contains('dropdownOpen')) { + this.toggleDropdown(containerId); + } + }, + /** * Closes the dropdown identified by given id without notifying callbacks. * @@ -313,7 +340,12 @@ define( * @return {boolean} 'false' if event is not null */ _toggle: function(event, targetId) { - targetId = (event === null) ? targetId : event.currentTarget.getAttribute('data-target'); + if (event !== null) { + event.preventDefault(); + event.stopPropagation(); + + targetId = event.currentTarget.getAttribute('data-target'); + } // check if 'isOverlayDropdownButton' is set which indicates if // the dropdown toggle is in an overlay @@ -350,12 +382,7 @@ define( // TODO WCF.Dropdown.Interactive.Handler.closeAll(); - if (event !== null) { - event.stopPropagation(); - return false; - } - - return true; + return (event === null); } }; -- 2.20.1