From: Alexander Ebert Date: Wed, 24 Jun 2015 17:25:45 +0000 (+0200) Subject: Improved `UI/SimpleDropdown` X-Git-Tag: 3.0.0_Beta_1~2252 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f0aa83bef648c2c3d7c570d0dae1b748ec2b0e6d;p=GitHub%2FWoltLab%2FWCF.git Improved `UI/SimpleDropdown` --- 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); } };