* Toggles a dropdown.
*
* @param string containerID
+ * @param {boolean=} disableAutoFocus
*/
- toggleDropdown: function(containerID) {
- window.bc_wcfSimpleDropdown._toggle(null, containerID);
+ toggleDropdown: function(containerID, disableAutoFocus) {
+ window.bc_wcfSimpleDropdown._toggle(null, containerID, null, disableAutoFocus);
},
/**
var $containerID = this._searchInput.parents('.dropdown').wcfIdentify();
if (!WCF.Dropdown.getDropdownMenu($containerID).hasClass('dropdownOpen')) {
- WCF.Dropdown.toggleDropdown($containerID);
+ WCF.Dropdown.toggleDropdown($containerID, true);
this._openDropdown();
}
*
* @param {string} containerId dropdown wrapper id
* @param {Element=} referenceElement alternative reference element, used for reusable dropdown menus
+ * @param {boolean=} disableAutoFocus
*/
- toggleDropdown: function(containerId, referenceElement) {
- this._toggle(null, containerId, referenceElement);
+ toggleDropdown: function(containerId, referenceElement, disableAutoFocus) {
+ this._toggle(null, containerId, referenceElement, disableAutoFocus);
},
/**
* Opens the dropdown unless it is already open.
*
* @param {string} containerId dropdown wrapper id
+ * @param {boolean=} disableAutoFocus
*/
- open: function(containerId) {
+ open: function(containerId, disableAutoFocus) {
var menu = _menus.get(containerId);
if (menu !== undefined && !menu.classList.contains('dropdownOpen')) {
- this.toggleDropdown(containerId);
+ this.toggleDropdown(containerId, undefined, disableAutoFocus);
}
},
* @param {?Event} event event object, should be 'null' if targetId is given
* @param {string?} targetId dropdown wrapper id
* @param {Element=} alternateElement alternative reference element for alignment
+ * @param {boolean=} disableAutoFocus
* @return {boolean} 'false' if event is not null
*/
- _toggle: function(event, targetId, alternateElement) {
+ _toggle: function(event, targetId, alternateElement, disableAutoFocus) {
if (event !== null) {
event.preventDefault();
event.stopPropagation();
this._notifyCallbacks(containerId, 'open');
- elAttr(menu, 'role', 'menu');
- elAttr(menu, 'tabindex', -1);
- menu.removeEventListener('keydown', _callbackDropdownMenuKeyDown);
- menu.addEventListener('keydown', _callbackDropdownMenuKeyDown);
- var firstListItem = null;
- elBySelAll('li', menu, function(listItem) {
- if (firstListItem === null) firstListItem = listItem;
- else if (listItem.classList.contains('active')) firstListItem = listItem;
-
- elAttr(listItem, 'role', 'menuitem');
- elAttr(listItem, 'tabindex', -1);
- });
- if (firstListItem !== null) {
- firstListItem.focus();
+ if (!disableAutoFocus) {
+ elAttr(menu, 'role', 'menu');
+ elAttr(menu, 'tabindex', -1);
+ menu.removeEventListener('keydown', _callbackDropdownMenuKeyDown);
+ menu.addEventListener('keydown', _callbackDropdownMenuKeyDown);
+ var firstListItem = null;
+ elBySelAll('li', menu, function (listItem) {
+ if (firstListItem === null) firstListItem = listItem;
+ else if (listItem.classList.contains('active')) firstListItem = listItem;
+
+ elAttr(listItem, 'role', 'menuitem');
+ elAttr(listItem, 'tabindex', -1);
+ });
+ if (firstListItem !== null) {
+ firstListItem.focus();
+ }
}
this.setAlignment(dropdown, menu, alternateElement);