/**
* Initializes a dropdown.
*
- * @param jQuery button
- * @param boolean isLazyInitialization
+ * @param {jQuery} button
+ * @param {boolean|Event} isLazyInitialization
*/
initDropdown: function(button, isLazyInitialization) {
window.bc_wcfSimpleDropdown.init(button[0], isLazyInitialization);
}
if ($trigger !== null) {
- WCF.Dropdown.initDropdown($trigger, true);
+ WCF.Dropdown.initDropdown($trigger, event.originalEvent || event);
}
return false;
* Initializes a dropdown.
*
* @param {Element} button
- * @param {boolean} isLazyInitialization
+ * @param {boolean|Event} isLazyInitialization
*/
init: function(button, isLazyInitialization) {
this.setup();
elData(button, 'target', containerId);
if (isLazyInitialization) {
- setTimeout(function() { Core.triggerEvent(button, WCF_CLICK_EVENT); }, 10);
+ setTimeout(function() {
+ elData(button, 'dropdown-lazy-init', (isLazyInitialization instanceof MouseEvent));
+
+ Core.triggerEvent(button, WCF_CLICK_EVENT);
+
+ setTimeout(function() {
+ button.removeAttribute('data-dropdown-lazy-init');
+ }, 10);
+ }, 10);
}
},
//noinspection JSCheckFunctionSignatures
targetId = elData(event.currentTarget, 'target');
+
+ if (disableAutoFocus === undefined && event instanceof MouseEvent) {
+ disableAutoFocus = true;
+ }
}
var dropdown = _dropdowns.get(targetId), preventToggle = false;
if (dropdown !== undefined) {
+ var button;
+
// check if the dropdown is still the same, as some components (e.g. page actions)
// re-create the parent of a button
if (event) {
- var button = event.currentTarget, parent = button.parentNode;
+ button = event.currentTarget, parent = button.parentNode;
if (parent !== dropdown) {
parent.classList.add('dropdown');
parent.id = dropdown.id;
}
}
+ if (disableAutoFocus === undefined) {
+ button = dropdown.closest('.dropdownToggle');
+ if (!button) {
+ button = elBySel('.dropdownToggle', dropdown);
+
+ if (!button && dropdown.id) {
+ button = elBySel('[data-target="' + dropdown.id + '"]');
+ }
+ }
+
+ if (button && elDataBool(button, 'dropdown-lazy-init')) {
+ disableAutoFocus = true;
+ }
+ }
+
// Repeated clicks on the dropdown button will not cause it to close, the only way
// to close it is by clicking somewhere else in the document or on another dropdown
// toggle. This is used with the search bar to prevent the dropdown from closing by