vendor: 11,899 bytes, lines 1-312
1/*! 2 * Bootstrap dropdown.js v5.3.3 (https://getbootstrap.com/) 3 * Copyright 2011-2024 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) 4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 5 */ 6(function (global, factory) { 7 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./base-component.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js'), require('./util/index.js')) : 8 typeof define === 'function' && define.amd ? define(['@popperjs/core', './base-component', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './util/index'], factory) : 9 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global.Popper, global.BaseComponent, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Index)); 10})(this, (function (Popper, BaseComponent, EventHandler, Manipulator, SelectorEngine, index_js) { 'use strict'; 11 12 function _interopNamespaceDefault(e) { 13 const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } }); 14 if (e) { 15 for (const k in e) { 16 if (k !== 'default') { 17 const d = Object.getOwnPropertyDescriptor(e, k); 18 Object.defineProperty(n, k, d.get ? d : { 19 enumerable: true, 20 get: () => e[k] 21 }); 22 } 23 } 24 } 25 n.default = e; 26 return Object.freeze(n); 27 } 28 29 const Popper__namespace = /*#__PURE__*/_interopNamespaceDefault(Popper); 30 31 /** 32 * -------------------------------------------------------------------------- 33 * Bootstrap dropdown.js 34 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 35 * -------------------------------------------------------------------------- 36 */ 37 38 39 /** 40 * Constants 41 */ 42 43 const NAME = 'dropdown'; 44 const DATA_KEY = 'bs.dropdown'; 45 const EVENT_KEY = `.${DATA_KEY}`; 46 const DATA_API_KEY = '.data-api'; 47 const ESCAPE_KEY = 'Escape'; 48 const TAB_KEY = 'Tab'; 49 const ARROW_UP_KEY = 'ArrowUp'; 50 const ARROW_DOWN_KEY = 'ArrowDown'; 51 const RIGHT_MOUSE_BUTTON = 2; // MouseEvent.button value for the secondary button, usually the right button 52 53 const EVENT_HIDE = `hide${EVENT_KEY}`; 54 const EVENT_HIDDEN = `hidden${EVENT_KEY}`; 55 const EVENT_SHOW = `show${EVENT_KEY}`; 56 const EVENT_SHOWN = `shown${EVENT_KEY}`; 57 const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`; 58 const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY}${DATA_API_KEY}`; 59 const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY}${DATA_API_KEY}`; 60 const CLASS_NAME_SHOW = 'show'; 61 const CLASS_NAME_DROPUP = 'dropup'; 62 const CLASS_NAME_DROPEND = 'dropend'; 63 const CLASS_NAME_DROPSTART = 'dropstart'; 64 const CLASS_NAME_DROPUP_CENTER = 'dropup-center'; 65 const CLASS_NAME_DROPDOWN_CENTER = 'dropdown-center'; 66 const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]:not(.disabled):not(:disabled)'; 67 const SELECTOR_DATA_TOGGLE_SHOWN = `${SELECTOR_DATA_TOGGLE}.${CLASS_NAME_SHOW}`; 68 const SELECTOR_MENU = '.dropdown-menu'; 69 const SELECTOR_NAVBAR = '.navbar'; 70 const SELECTOR_NAVBAR_NAV = '.navbar-nav'; 71 const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)'; 72 const PLACEMENT_TOP = index_js.isRTL() ? 'top-end' : 'top-start'; 73 const PLACEMENT_TOPEND = index_js.isRTL() ? 'top-start' : 'top-end'; 74 const PLACEMENT_BOTTOM = index_js.isRTL() ? 'bottom-end' : 'bottom-start'; 75 const PLACEMENT_BOTTOMEND = index_js.isRTL() ? 'bottom-start' : 'bottom-end'; 76 const PLACEMENT_RIGHT = index_js.isRTL() ? 'left-start' : 'right-start'; 77 const PLACEMENT_LEFT = index_js.isRTL() ? 'right-start' : 'left-start'; 78 const PLACEMENT_TOPCENTER = 'top'; 79 const PLACEMENT_BOTTOMCENTER = 'bottom'; 80 const Default = { 81 autoClose: true, 82 boundary: 'clippingParents', 83 display: 'dynamic', 84 offset: [0, 2], 85 popperConfig: null, 86 reference: 'toggle' 87 }; 88 const DefaultType = { 89 autoClose: '(boolean|string)', 90 boundary: '(string|element)', 91 display: 'string', 92 offset: '(array|string|function)', 93 popperConfig: '(null|object|function)', 94 reference: '(string|element|object)' 95 }; 96 97 /** 98 * Class definition 99 */ 100 101 class Dropdown extends BaseComponent { 102 constructor(element, config) { 103 super(element, config); 104 this._popper = null; 105 this._parent = this._element.parentNode; // dropdown wrapper 106 // TODO: v6 revert #37011 & change markup https://getbootstrap.com/docs/5.3/forms/input-group/ 107 this._menu = SelectorEngine.next(this._element, SELECTOR_MENU)[0] || SelectorEngine.prev(this._element, SELECTOR_MENU)[0] || SelectorEngine.findOne(SELECTOR_MENU, this._parent); 108 this._inNavbar = this._detectNavbar(); 109 } 110 111 // Getters 112 static get Default() { 113 return Default; 114 } 115 static get DefaultType() { 116 return DefaultType; 117 } 118 static get NAME() { 119 return NAME; 120 } 121 122 // Public 123 toggle() { 124 return this._isShown() ? this.hide() : this.show(); 125 } 126 show() { 127 if (index_js.isDisabled(this._element) || this._isShown()) { 128 return; 129 } 130 const relatedTarget = { 131 relatedTarget: this._element 132 }; 133 const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, relatedTarget); 134 if (showEvent.defaultPrevented) { 135 return; 136 } 137 this._createPopper(); 138 139 // If this is a touch-enabled device we add extra 140 // empty mouseover listeners to the body's immediate children; 141 // only needed because of broken event delegation on iOS 142 // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html 143 if ('ontouchstart' in document.documentElement && !this._parent.closest(SELECTOR_NAVBAR_NAV)) { 144 for (const element of [].concat(...document.body.children)) { 145 EventHandler.on(element, 'mouseover', index_js.noop); 146 } 147 } 148 this._element.focus(); 149 this._element.setAttribute('aria-expanded', true); 150 this._menu.classList.add(CLASS_NAME_SHOW); 151 this._element.classList.add(CLASS_NAME_SHOW); 152 EventHandler.trigger(this._element, EVENT_SHOWN, relatedTarget); 153 } 154 hide() { 155 if (index_js.isDisabled(this._element) || !this._isShown()) { 156 return; 157 } 158 const relatedTarget = { 159 relatedTarget: this._element 160 }; 161 this._completeHide(relatedTarget); 162 } 163 dispose() { 164 if (this._popper) { 165 this._popper.destroy(); 166 } 167 super.dispose(); 168 } 169 update() { 170 this._inNavbar = this._detectNavbar(); 171 if (this._popper) { 172 this._popper.update(); 173 } 174 } 175 176 // Private 177 _completeHide(relatedTarget) { 178 const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE, relatedTarget); 179 if (hideEvent.defaultPrevented) { 180 return; 181 } 182 183 // If this is a touch-enabled device we remove the extra 184 // empty mouseover listeners we added for iOS support 185 if ('ontouchstart' in document.documentElement) { 186 for (const element of [].concat(...document.body.children)) { 187 EventHandler.off(element, 'mouseover', index_js.noop); 188 } 189 } 190 if (this._popper) { 191 this._popper.destroy(); 192 } 193 this._menu.classList.remove(CLASS_NAME_SHOW); 194 this._element.classList.remove(CLASS_NAME_SHOW); 195 this._element.setAttribute('aria-expanded', 'false'); 196 Manipulator.removeDataAttribute(this._menu, 'popper'); 197 EventHandler.trigger(this._element, EVENT_HIDDEN, relatedTarget); 198 } 199 _getConfig(config) { 200 config = super._getConfig(config); 201 if (typeof config.reference === 'object' && !index_js.isElement(config.reference) && typeof config.reference.getBoundingClientRect !== 'function') { 202 // Popper virtual elements require a getBoundingClientRect method 203 throw new TypeError(`${NAME.toUpperCase()}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`); 204 } 205 return config; 206 } 207 _createPopper() { 208 if (typeof Popper__namespace === 'undefined') { 209 throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)'); 210 } 211 let referenceElement = this._element; 212 if (this._config.reference === 'parent') { 213 referenceElement = this._parent; 214 } else if (index_js.isElement(this._config.reference)) { 215 referenceElement = index_js.getElement(this._config.reference); 216 } else if (typeof this._config.reference === 'object') { 217 referenceElement = this._config.reference; 218 } 219 const popperConfig = this._getPopperConfig(); 220 this._popper = Popper__namespace.createPopper(referenceElement, this._menu, popperConfig); 221 } 222 _isShown() { 223 return this._menu.classList.contains(CLASS_NAME_SHOW); 224 } 225 _getPlacement() { 226 const parentDropdown = this._parent; 227 if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) { 228 return PLACEMENT_RIGHT; 229 } 230 if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) { 231 return PLACEMENT_LEFT; 232 } 233 if (parentDropdown.classList.contains(CLASS_NAME_DROPUP_CENTER)) { 234 return PLACEMENT_TOPCENTER; 235 } 236 if (parentDropdown.classList.contains(CLASS_NAME_DROPDOWN_CENTER)) { 237 return PLACEMENT_BOTTOMCENTER; 238 } 239 240 // We need to trim the value because custom properties can also include spaces 241 const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end'; 242 if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) { 243 return isEnd ? PLACEMENT_TOPEND : PLACEMENT_TOP; 244 } 245 return isEnd ? PLACEMENT_BOTTOMEND : PLACEMENT_BOTTOM; 246 } 247 _detectNavbar() { 248 return this._element.closest(SELECTOR_NAVBAR) !== null; 249 } 250 _getOffset() { 251 const { 252 offset 253 } = this._config; 254 if (typeof offset === 'string') { 255 return offset.split(',').map(value => Number.parseInt(value, 10)); 256 } 257 if (typeof offset === 'function') { 258 return popperData => offset(popperData, this._element); 259 } 260 return offset; 261 } 262 _getPopperConfig() { 263 const defaultBsPopperConfig = { 264 placement: this._getPlacement(), 265 modifiers: [{ 266 name: 'preventOverflow', 267 options: { 268 boundary: this._config.boundary 269 } 270 }, { 271 name: 'offset', 272 options: { 273 offset: this._getOffset() 274 } 275 }] 276 }; 277 278 // Disable Popper if we have a static display or Dropdown is in Navbar 279 if (this._inNavbar || this._config.display === 'static') { 280 Manipulator.setDataAttribute(this._menu, 'popper', 'static'); // TODO: v6 remove 281 defaultBsPopperConfig.modifiers = [{ 282 name: 'applyStyles', 283 enabled: false 284 }]; 285 } 286 return { 287 ...defaultBsPopperConfig, 288 ...index_js.execute(this._config.popperConfig, [defaultBsPopperConfig]) 289 }; 290 } 291 _selectMenuItem({ 292 key, 293 target 294 }) { 295 const items = SelectorEngine.find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(element => index_js.isVisible(element)); 296 if (!items.length) { 297 return; 298 } 299 300 // if target isn't included in items (e.g. when expanding the dropdown) 301 // allow cycling to get the last item in case key equals ARROW_UP_KEY 302 index_js.getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus(); 303 } 304 305 // Static 306 static jQueryInterface(config) { 307 return this.each(function () { 308 const data = Dropdown.getOrCreateInstance(this, config); 309 if (typeof config !== 'string') { 310 return; 311 } 312 if (typeof data[config] === 'undefined') {
vendor: 1,596 bytes, lines 313-350
313 throw new TypeError(`No method named "${config}"`); 314 } 315 data[config](); 316 }); 317 } 318 static clearMenus(event) { 319 if (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY) { 320 return; 321 } 322 const openToggles = SelectorEngine.find(SELECTOR_DATA_TOGGLE_SHOWN); 323 for (const toggle of openToggles) { 324 const context = Dropdown.getInstance(toggle); 325 if (!context || context._config.autoClose === false) { 326 continue; 327 } 328 const composedPath = event.composedPath(); 329 const isMenuTarget = composedPath.includes(context._menu); 330 if (composedPath.includes(context._element) || context._config.autoClose === 'inside' && !isMenuTarget || context._config.autoClose === 'outside' && isMenuTarget) { 331 continue; 332 } 333 334 // Tab navigation through the dropdown menu or events from contained inputs shouldn't close the menu 335 if (context._menu.contains(event.target) && (event.type === 'keyup' && event.key === TAB_KEY || /input|select|option|textarea|form/i.test(event.target.tagName))) { 336 continue; 337 } 338 const relatedTarget = { 339 relatedTarget: context._element 340 }; 341 if (event.type === 'click') { 342 relatedTarget.clickEvent = event; 343 } 344 context._completeHide(relatedTarget); 345 } 346 } 347 static dataApiKeydownHandler(event) { 348 // If not an UP | DOWN | ESCAPE key => not a dropdown command 349 // If input/textarea && if key is other than ESCAPE => not a dropdown command 350
vendor: 1,848 bytes, lines 351-402
351 const isInput = /input|textarea/i.test(event.target.tagName); 352 const isEscapeEvent = event.key === ESCAPE_KEY; 353 const isUpOrDownEvent = [ARROW_UP_KEY, ARROW_DOWN_KEY].includes(event.key); 354 if (!isUpOrDownEvent && !isEscapeEvent) { 355 return; 356 } 357 if (isInput && !isEscapeEvent) { 358 return; 359 } 360 event.preventDefault(); 361 362 // TODO: v6 revert #37011 & change markup https://getbootstrap.com/docs/5.3/forms/input-group/ 363 const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine.prev(this, SELECTOR_DATA_TOGGLE)[0] || SelectorEngine.next(this, SELECTOR_DATA_TOGGLE)[0] || SelectorEngine.findOne(SELECTOR_DATA_TOGGLE, event.delegateTarget.parentNode); 364 const instance = Dropdown.getOrCreateInstance(getToggleButton); 365 if (isUpOrDownEvent) { 366 event.stopPropagation(); 367 instance.show(); 368 instance._selectMenuItem(event); 369 return; 370 } 371 if (instance._isShown()) { 372 // else is escape and we check if it is shown 373 event.stopPropagation(); 374 instance.hide(); 375 getToggleButton.focus(); 376 } 377 } 378 } 379 380 /** 381 * Data API implementation 382 */ 383 384 EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler); 385 EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler); 386 EventHandler.on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus); 387 EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus); 388 EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) { 389 event.preventDefault(); 390 Dropdown.getOrCreateInstance(this).toggle(); 391 }); 392 393 /** 394 * jQuery 395 */ 396 397 index_js.defineJQueryPlugin(Dropdown); 398 399 return Dropdown; 400 401})); 402//# sourceMappingURL=dropdown.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.