[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 import { P as Popper, c as createPopper } from './popper.js?5.1.3'; 2 import { b as isRTL, E as EventHandler, d as defineJQueryPlugin, B as BaseComponent, j as isDisabled, M as Manipulator, n as noop, a as typeCheckConfig, k as isElement, h as getElement, S as SelectorEngine, i as isVisible, g as getNextActiveElement, c as getElementFromSelector } from './dom.js?5.1.3'; 3 4 /** 5 * -------------------------------------------------------------------------- 6 * Bootstrap (v5.1.3): dropdown.js 7 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 8 * -------------------------------------------------------------------------- 9 */ 10 /** 11 * ------------------------------------------------------------------------ 12 * Constants 13 * ------------------------------------------------------------------------ 14 */ 15 16 const NAME = 'dropdown'; 17 const DATA_KEY = 'bs.dropdown'; 18 const EVENT_KEY = `.$DATA_KEY}`; 19 const DATA_API_KEY = '.data-api'; 20 const ESCAPE_KEY = 'Escape'; 21 const SPACE_KEY = 'Space'; 22 const TAB_KEY = 'Tab'; 23 const ARROW_UP_KEY = 'ArrowUp'; 24 const ARROW_DOWN_KEY = 'ArrowDown'; 25 const RIGHT_MOUSE_BUTTON = 2; // MouseEvent.button value for the secondary button, usually the right button 26 27 const REGEXP_KEYDOWN = new RegExp(`$ARROW_UP_KEY}|$ARROW_DOWN_KEY}|$ESCAPE_KEY}`); 28 const EVENT_HIDE = `hide$EVENT_KEY}`; 29 const EVENT_HIDDEN = `hidden$EVENT_KEY}`; 30 const EVENT_SHOW = `show$EVENT_KEY}`; 31 const EVENT_SHOWN = `shown$EVENT_KEY}`; 32 const EVENT_CLICK_DATA_API = `click$EVENT_KEY}$DATA_API_KEY}`; 33 const EVENT_KEYDOWN_DATA_API = `keydown$EVENT_KEY}$DATA_API_KEY}`; 34 const EVENT_KEYUP_DATA_API = `keyup$EVENT_KEY}$DATA_API_KEY}`; 35 const CLASS_NAME_SHOW = 'show'; 36 const CLASS_NAME_DROPUP = 'dropup'; 37 const CLASS_NAME_DROPEND = 'dropend'; 38 const CLASS_NAME_DROPSTART = 'dropstart'; 39 const CLASS_NAME_NAVBAR = 'navbar'; 40 const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]'; 41 const SELECTOR_MENU = '.dropdown-menu'; 42 const SELECTOR_NAVBAR_NAV = '.navbar-nav'; 43 const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'; 44 const PLACEMENT_TOP = isRTL() ? 'top-end' : 'top-start'; 45 const PLACEMENT_TOPEND = isRTL() ? 'top-start' : 'top-end'; 46 const PLACEMENT_BOTTOM = isRTL() ? 'bottom-end' : 'bottom-start'; 47 const PLACEMENT_BOTTOMEND = isRTL() ? 'bottom-start' : 'bottom-end'; 48 const PLACEMENT_RIGHT = isRTL() ? 'left-start' : 'right-start'; 49 const PLACEMENT_LEFT = isRTL() ? 'right-start' : 'left-start'; 50 const Default = { 51 offset: [0, 2], 52 boundary: 'clippingParents', 53 reference: 'toggle', 54 display: 'dynamic', 55 popperConfig: null, 56 autoClose: true 57 }; 58 const DefaultType = { 59 offset: '(array|string|function)', 60 boundary: '(string|element)', 61 reference: '(string|element|object)', 62 display: 'string', 63 popperConfig: '(null|object|function)', 64 autoClose: '(boolean|string)' 65 }; 66 /** 67 * ------------------------------------------------------------------------ 68 * Class Definition 69 * ------------------------------------------------------------------------ 70 */ 71 72 class Dropdown extends BaseComponent { 73 constructor(element, config) { 74 super(element); 75 this._popper = null; 76 this._config = this._getConfig(config); 77 this._menu = this._getMenuElement(); 78 this._inNavbar = this._detectNavbar(); 79 } // Getters 80 81 82 static get Default() { 83 return Default; 84 } 85 86 static get DefaultType() { 87 return DefaultType; 88 } 89 90 static get NAME() { 91 return NAME; 92 } // Public 93 94 95 toggle() { 96 return this._isShown() ? this.hide() : this.show(); 97 } 98 99 show() { 100 if (isDisabled(this._element) || this._isShown(this._menu)) { 101 return; 102 } 103 104 const relatedTarget = { 105 relatedTarget: this._element 106 }; 107 const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, relatedTarget); 108 109 if (showEvent.defaultPrevented) { 110 return; 111 } 112 113 const parent = Dropdown.getParentFromElement(this._element); // Totally disable Popper for Dropdowns in Navbar 114 115 if (this._inNavbar) { 116 Manipulator.setDataAttribute(this._menu, 'popper', 'none'); 117 } else { 118 this._createPopper(parent); 119 } // If this is a touch-enabled device we add extra 120 // empty mouseover listeners to the body's immediate children; 121 // only needed because of broken event delegation on iOS 122 // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html 123 124 125 if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) { 126 [].concat(...document.body.children).forEach(elem => EventHandler.on(elem, 'mouseover', noop)); 127 } 128 129 this._element.focus(); 130 131 this._element.setAttribute('aria-expanded', true); 132 133 this._menu.classList.add(CLASS_NAME_SHOW); 134 135 this._element.classList.add(CLASS_NAME_SHOW); 136 137 EventHandler.trigger(this._element, EVENT_SHOWN, relatedTarget); 138 } 139 140 hide() { 141 if (isDisabled(this._element) || !this._isShown(this._menu)) { 142 return; 143 } 144 145 const relatedTarget = { 146 relatedTarget: this._element 147 }; 148 149 this._completeHide(relatedTarget); 150 } 151 152 dispose() { 153 if (this._popper) { 154 this._popper.destroy(); 155 } 156 157 super.dispose(); 158 } 159 160 update() { 161 this._inNavbar = this._detectNavbar(); 162 163 if (this._popper) { 164 this._popper.update(); 165 } 166 } // Private 167 168 169 _completeHide(relatedTarget) { 170 const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE, relatedTarget); 171 172 if (hideEvent.defaultPrevented) { 173 return; 174 } // If this is a touch-enabled device we remove the extra 175 // empty mouseover listeners we added for iOS support 176 177 178 if ('ontouchstart' in document.documentElement) { 179 [].concat(...document.body.children).forEach(elem => EventHandler.off(elem, 'mouseover', noop)); 180 } 181 182 if (this._popper) { 183 this._popper.destroy(); 184 } 185 186 this._menu.classList.remove(CLASS_NAME_SHOW); 187 188 this._element.classList.remove(CLASS_NAME_SHOW); 189 190 this._element.setAttribute('aria-expanded', 'false'); 191 192 Manipulator.removeDataAttribute(this._menu, 'popper'); 193 EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget); 194 } 195 196 _getConfig(config) { 197 config = { ...this.constructor.Default, 198 ...Manipulator.getDataAttributes(this._element), 199 ...config 200 }; 201 typeCheckConfig(NAME, config, this.constructor.DefaultType); 202 203 if (typeof config.reference === 'object' && !isElement(config.reference) && typeof config.reference.getBoundingClientRect !== 'function') { 204 // Popper virtual elements require a getBoundingClientRect method 205 throw new TypeError(`$NAME.toUpperCase()}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`); 206 } 207 208 return config; 209 } 210 211 _createPopper(parent) { 212 if (typeof Popper === 'undefined') { 213 throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)'); 214 } 215 216 let referenceElement = this._element; 217 218 if (this._config.reference === 'parent') { 219 referenceElement = parent; 220 } else if (isElement(this._config.reference)) { 221 referenceElement = getElement(this._config.reference); 222 } else if (typeof this._config.reference === 'object') { 223 referenceElement = this._config.reference; 224 } 225 226 const popperConfig = this._getPopperConfig(); 227 228 const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false); 229 this._popper = createPopper(referenceElement, this._menu, popperConfig); 230 231 if (isDisplayStatic) { 232 Manipulator.setDataAttribute(this._menu, 'popper', 'static'); 233 } 234 } 235 236 _isShown() { 237 let element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._element; 238 return element.classList.contains(CLASS_NAME_SHOW); 239 } 240 241 _getMenuElement() { 242 return SelectorEngine.next(this._element, SELECTOR_MENU)[0]; 243 } 244 245 _getPlacement() { 246 const parentDropdown = this._element.parentNode; 247 248 if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) { 249 return PLACEMENT_RIGHT; 250 } 251 252 if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) { 253 return PLACEMENT_LEFT; 254 } // We need to trim the value because custom properties can also include spaces 255 256 257 const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end'; 258 259 if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) { 260 return isEnd ? PLACEMENT_TOPEND : PLACEMENT_TOP; 261 } 262 263 return isEnd ? PLACEMENT_BOTTOMEND : PLACEMENT_BOTTOM; 264 } 265 266 _detectNavbar() { 267 return this._element.closest(`.$CLASS_NAME_NAVBAR}`) !== null; 268 } 269 270 _getOffset() { 271 const { 272 offset 273 } = this._config; 274 275 if (typeof offset === 'string') { 276 return offset.split(',').map(val => Number.parseInt(val, 10)); 277 } 278 279 if (typeof offset === 'function') { 280 return popperData => offset(popperData, this._element); 281 } 282 283 return offset; 284 } 285 286 _getPopperConfig() { 287 const defaultBsPopperConfig = { 288 placement: this._getPlacement(), 289 modifiers: [{ 290 name: 'preventOverflow', 291 options: { 292 boundary: this._config.boundary 293 } 294 }, { 295 name: 'offset', 296 options: { 297 offset: this._getOffset() 298 } 299 }] 300 }; // Disable Popper if we have a static display 301 302 if (this._config.display === 'static') { 303 defaultBsPopperConfig.modifiers = [{ 304 name: 'applyStyles', 305 enabled: false 306 }]; 307 } 308 309 return { ...defaultBsPopperConfig, 310 ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig) 311 }; 312 } 313 314 _selectMenuItem(_ref) { 315 let { 316 key, 317 target 318 } = _ref; 319 const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible); 320 321 if (!items.length) { 322 return; 323 } // if target isn't included in items (e.g. when expanding the dropdown) 324 // allow cycling to get the last item in case key equals ARROW_UP_KEY 325 326 327 getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus(); 328 } // Static 329 330 331 static jQueryInterface(config) { 332 return this.each(function () { 333 const data = Dropdown.getOrCreateInstance(this, config); 334 335 if (typeof config !== 'string') { 336 return; 337 } 338 339 if (typeof data[config] === 'undefined') { 340 throw new TypeError(`No method named "$config}"`); 341 } 342 343 data[config](); 344 }); 345 } 346 347 static clearMenus(event) { 348 if (event && (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY)) { 349 return; 350 } 351 352 const toggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE); 353 354 for (let i = 0, len = toggles.length; i < len; i++) { 355 const context = Dropdown.getInstance(toggles[i]); 356 357 if (!context || context._config.autoClose === false) { 358 continue; 359 } 360 361 if (!context._isShown()) { 362 continue; 363 } 364 365 const relatedTarget = { 366 relatedTarget: context._element 367 }; 368 369 if (event) { 370 const composedPath = event.composedPath(); 371 const isMenuTarget = composedPath.includes(context._menu); 372 373 if (composedPath.includes(context._element) || context._config.autoClose === 'inside' && !isMenuTarget || context._config.autoClose === 'outside' && isMenuTarget) { 374 continue; 375 } // Tab navigation through the dropdown menu or events from contained inputs shouldn't close the menu 376 377 378 if (context._menu.contains(event.target) && (event.type === 'keyup' && event.key === TAB_KEY || /input|select|option|textarea|form/i.test(event.target.tagName))) { 379 continue; 380 } 381 382 if (event.type === 'click') { 383 relatedTarget.clickEvent = event; 384 } 385 } 386 387 context._completeHide(relatedTarget); 388 } 389 } 390 391 static getParentFromElement(element) { 392 return getElementFromSelector(element) || element.parentNode; 393 } 394 395 static dataApiKeydownHandler(event) { 396 // If not input/textarea: 397 // - And not a key in REGEXP_KEYDOWN => not a dropdown command 398 // If input/textarea: 399 // - If space key => not a dropdown command 400 // - If key is other than escape 401 // - If key is not up or down => not a dropdown command 402 // - If trigger inside the menu => not a dropdown command 403 if (/input|textarea/i.test(event.target.tagName) ? event.key === SPACE_KEY || event.key !== ESCAPE_KEY && (event.key !== ARROW_DOWN_KEY && event.key !== ARROW_UP_KEY || event.target.closest(SELECTOR_MENU)) : !REGEXP_KEYDOWN.test(event.key)) { 404 return; 405 } 406 407 const isActive = this.classList.contains(CLASS_NAME_SHOW); 408 409 if (!isActive && event.key === ESCAPE_KEY) { 410 return; 411 } 412 413 event.preventDefault(); 414 event.stopPropagation(); 415 416 if (isDisabled(this)) { 417 return; 418 } 419 420 const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0]; 421 const instance = Dropdown.getOrCreateInstance(getToggleButton); 422 423 if (event.key === ESCAPE_KEY) { 424 instance.hide(); 425 return; 426 } 427 428 if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) { 429 if (!isActive) { 430 instance.show(); 431 } 432 433 instance._selectMenuItem(event); 434 435 return; 436 } 437 438 if (!isActive || event.key === SPACE_KEY) { 439 Dropdown.clearMenus(); 440 } 441 } 442 443 } 444 /** 445 * ------------------------------------------------------------------------ 446 * Data Api implementation 447 * ------------------------------------------------------------------------ 448 */ 449 450 451 EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler); 452 EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler); 453 EventHandler.on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus); 454 EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus); 455 EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { 456 event.preventDefault(); 457 Dropdown.getOrCreateInstance(this).toggle(); 458 }); 459 /** 460 * ------------------------------------------------------------------------ 461 * jQuery 462 * ------------------------------------------------------------------------ 463 * add .Dropdown to jQuery only if jQuery is present 464 */ 465 466 defineJQueryPlugin(Dropdown); 467 468 window.bootstrap = window.bootstrap || {}; 469 window.bootstrap.Dropdown = Dropdown; 470 471 if (Joomla && Joomla.getOptions) { 472 // Get the elements/configurations from the PHP 473 const dropdowns = Joomla.getOptions('bootstrap.dropdown'); // Initialise the elements 474 475 if (typeof dropdowns === 'object' && dropdowns !== null) { 476 Object.keys(dropdowns).forEach(dropdown => { 477 const opt = dropdowns[dropdown]; 478 const options = { 479 interval: opt.interval ? opt.interval : 5000, 480 pause: opt.pause ? opt.pause : 'hover' 481 }; 482 const elements = Array.from(document.querySelectorAll(dropdown)); 483 484 if (elements.length) { 485 elements.map(el => new window.bootstrap.Dropdown(el, options)); 486 } 487 }); 488 } 489 } 490 491 export { Dropdown as D };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |