@openeuropa/bcl-bootstrap 0.14.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/bin/build-plugins.js +77 -160
  2. package/bootstrap-icons.js +211 -1
  3. package/js/dist/alert.js +6 -137
  4. package/js/dist/alert.js.map +1 -1
  5. package/js/dist/base-component.js +7 -109
  6. package/js/dist/base-component.js.map +1 -1
  7. package/js/dist/button.js +5 -65
  8. package/js/dist/button.js.map +1 -1
  9. package/js/dist/carousel.js +13 -190
  10. package/js/dist/carousel.js.map +1 -1
  11. package/js/dist/collapse.js +12 -170
  12. package/js/dist/collapse.js.map +1 -1
  13. package/js/dist/dom/data.js +0 -5
  14. package/js/dist/dom/data.js.map +1 -1
  15. package/js/dist/dom/event-handler.js +5 -29
  16. package/js/dist/dom/event-handler.js.map +1 -1
  17. package/js/dist/dom/manipulator.js +0 -5
  18. package/js/dist/dom/manipulator.js.map +1 -1
  19. package/js/dist/dom/selector-engine.js +5 -53
  20. package/js/dist/dom/selector-engine.js.map +1 -1
  21. package/js/dist/dropdown.js +23 -212
  22. package/js/dist/dropdown.js.map +1 -1
  23. package/js/dist/modal.js +18 -611
  24. package/js/dist/modal.js.map +1 -1
  25. package/js/dist/offcanvas.js +19 -610
  26. package/js/dist/offcanvas.js.map +1 -1
  27. package/js/dist/popover.js +5 -65
  28. package/js/dist/popover.js.map +1 -1
  29. package/js/dist/scrollspy.js +8 -147
  30. package/js/dist/scrollspy.js.map +1 -1
  31. package/js/dist/tab.js +8 -127
  32. package/js/dist/tab.js.map +1 -1
  33. package/js/dist/toast.js +8 -185
  34. package/js/dist/toast.js.map +1 -1
  35. package/js/dist/tooltip.js +18 -277
  36. package/js/dist/tooltip.js.map +1 -1
  37. package/js/dist/util/backdrop.js +138 -0
  38. package/js/dist/util/backdrop.js.map +1 -0
  39. package/js/dist/util/component-functions.js +42 -0
  40. package/js/dist/util/component-functions.js.map +1 -0
  41. package/js/dist/util/focustrap.js +118 -0
  42. package/js/dist/util/focustrap.js.map +1 -0
  43. package/js/dist/util/index.js +342 -0
  44. package/js/dist/util/index.js.map +1 -0
  45. package/js/dist/util/sanitizer.js +125 -0
  46. package/js/dist/util/sanitizer.js.map +1 -0
  47. package/js/dist/util/scrollbar.js +119 -0
  48. package/js/dist/util/scrollbar.js.map +1 -0
  49. package/package.json +4 -3
  50. package/plugins/alert.js +0 -230
  51. package/plugins/alert.js.map +0 -1
  52. package/plugins/base-component.js +0 -178
  53. package/plugins/base-component.js.map +0 -1
  54. package/plugins/button.js +0 -141
  55. package/plugins/button.js.map +0 -1
  56. package/plugins/carousel.js +0 -738
  57. package/plugins/carousel.js.map +0 -1
  58. package/plugins/collapse.js +0 -490
  59. package/plugins/collapse.js.map +0 -1
  60. package/plugins/dom/data.js +0 -64
  61. package/plugins/dom/data.js.map +0 -1
  62. package/plugins/dom/event-handler.js +0 -317
  63. package/plugins/dom/event-handler.js.map +0 -1
  64. package/plugins/dom/manipulator.js +0 -84
  65. package/plugins/dom/manipulator.js.map +0 -1
  66. package/plugins/dom/selector-engine.js +0 -123
  67. package/plugins/dom/selector-engine.js.map +0 -1
  68. package/plugins/dropdown.js +0 -682
  69. package/plugins/dropdown.js.map +0 -1
  70. package/plugins/modal.js +0 -1037
  71. package/plugins/modal.js.map +0 -1
  72. package/plugins/popover.js +0 -179
  73. package/plugins/popover.js.map +0 -1
  74. package/plugins/scrollspy.js +0 -386
  75. package/plugins/scrollspy.js.map +0 -1
  76. package/plugins/tab.js +0 -328
  77. package/plugins/tab.js.map +0 -1
  78. package/plugins/toast.js +0 -418
  79. package/plugins/toast.js.map +0 -1
  80. package/plugins/tooltip.js +0 -1001
  81. package/plugins/tooltip.js.map +0 -1
@@ -1,682 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('@popperjs/core'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js'), require('./base-component.js')) :
3
- typeof define === 'function' && define.amd ? define(['@popperjs/core', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Dropdown = factory(global.Popper, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base));
5
- })(this, (function (Popper, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- function _interopNamespace(e) {
10
- if (e && e.__esModule) return e;
11
- var n = Object.create(null);
12
- if (e) {
13
- Object.keys(e).forEach(function (k) {
14
- if (k !== 'default') {
15
- var d = Object.getOwnPropertyDescriptor(e, k);
16
- Object.defineProperty(n, k, d.get ? d : {
17
- enumerable: true,
18
- get: function () { return e[k]; }
19
- });
20
- }
21
- });
22
- }
23
- n["default"] = e;
24
- return Object.freeze(n);
25
- }
26
-
27
- var Popper__namespace = /*#__PURE__*/_interopNamespace(Popper);
28
- var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
29
- var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
30
- var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
31
- var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
32
-
33
- /**
34
- * --------------------------------------------------------------------------
35
- * Bootstrap (v5.1.3): util/index.js
36
- * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
37
- * --------------------------------------------------------------------------
38
- */
39
-
40
- const toType = obj => {
41
- if (obj === null || obj === undefined) {
42
- return `${obj}`;
43
- }
44
-
45
- return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
46
- };
47
-
48
- const getSelector = element => {
49
- let selector = element.getAttribute('data-bs-target');
50
-
51
- if (!selector || selector === '#') {
52
- let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
53
- // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
54
- // `document.querySelector` will rightfully complain it is invalid.
55
- // See https://github.com/twbs/bootstrap/issues/32273
56
-
57
- if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
58
- return null;
59
- } // Just in case some CMS puts out a full URL with the anchor appended
60
-
61
-
62
- if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
63
- hrefAttr = `#${hrefAttr.split('#')[1]}`;
64
- }
65
-
66
- selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
67
- }
68
-
69
- return selector;
70
- };
71
-
72
- const getElementFromSelector = element => {
73
- const selector = getSelector(element);
74
- return selector ? document.querySelector(selector) : null;
75
- };
76
-
77
- const isElement = obj => {
78
- if (!obj || typeof obj !== 'object') {
79
- return false;
80
- }
81
-
82
- if (typeof obj.jquery !== 'undefined') {
83
- obj = obj[0];
84
- }
85
-
86
- return typeof obj.nodeType !== 'undefined';
87
- };
88
-
89
- const getElement = obj => {
90
- if (isElement(obj)) {
91
- // it's a jQuery object or a node element
92
- return obj.jquery ? obj[0] : obj;
93
- }
94
-
95
- if (typeof obj === 'string' && obj.length > 0) {
96
- return document.querySelector(obj);
97
- }
98
-
99
- return null;
100
- };
101
-
102
- const typeCheckConfig = (componentName, config, configTypes) => {
103
- Object.keys(configTypes).forEach(property => {
104
- const expectedTypes = configTypes[property];
105
- const value = config[property];
106
- const valueType = value && isElement(value) ? 'element' : toType(value);
107
-
108
- if (!new RegExp(expectedTypes).test(valueType)) {
109
- throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
110
- }
111
- });
112
- };
113
-
114
- const isVisible = element => {
115
- if (!isElement(element) || element.getClientRects().length === 0) {
116
- return false;
117
- }
118
-
119
- return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
120
- };
121
-
122
- const isDisabled = element => {
123
- if (!element || element.nodeType !== Node.ELEMENT_NODE) {
124
- return true;
125
- }
126
-
127
- if (element.classList.contains('disabled')) {
128
- return true;
129
- }
130
-
131
- if (typeof element.disabled !== 'undefined') {
132
- return element.disabled;
133
- }
134
-
135
- return element.hasAttribute('disabled') && element.getAttribute('disabled') !== 'false';
136
- };
137
-
138
- const noop = () => {};
139
-
140
- const getjQuery = () => {
141
- const {
142
- jQuery
143
- } = window;
144
-
145
- if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
146
- return jQuery;
147
- }
148
-
149
- return null;
150
- };
151
-
152
- const DOMContentLoadedCallbacks = [];
153
-
154
- const onDOMContentLoaded = callback => {
155
- if (document.readyState === 'loading') {
156
- // add listener on the first call when the document is in loading state
157
- if (!DOMContentLoadedCallbacks.length) {
158
- document.addEventListener('DOMContentLoaded', () => {
159
- DOMContentLoadedCallbacks.forEach(callback => callback());
160
- });
161
- }
162
-
163
- DOMContentLoadedCallbacks.push(callback);
164
- } else {
165
- callback();
166
- }
167
- };
168
-
169
- const isRTL = () => document.documentElement.dir === 'rtl';
170
-
171
- const defineJQueryPlugin = plugin => {
172
- onDOMContentLoaded(() => {
173
- const $ = getjQuery();
174
- /* istanbul ignore if */
175
-
176
- if ($) {
177
- const name = plugin.NAME;
178
- const JQUERY_NO_CONFLICT = $.fn[name];
179
- $.fn[name] = plugin.jQueryInterface;
180
- $.fn[name].Constructor = plugin;
181
-
182
- $.fn[name].noConflict = () => {
183
- $.fn[name] = JQUERY_NO_CONFLICT;
184
- return plugin.jQueryInterface;
185
- };
186
- }
187
- });
188
- };
189
- /**
190
- * Return the previous/next element of a list.
191
- *
192
- * @param {array} list The list of elements
193
- * @param activeElement The active element
194
- * @param shouldGetNext Choose to get next or previous element
195
- * @param isCycleAllowed
196
- * @return {Element|elem} The proper element
197
- */
198
-
199
-
200
- const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
201
- let index = list.indexOf(activeElement); // if the element does not exist in the list return an element depending on the direction and if cycle is allowed
202
-
203
- if (index === -1) {
204
- return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0];
205
- }
206
-
207
- const listLength = list.length;
208
- index += shouldGetNext ? 1 : -1;
209
-
210
- if (isCycleAllowed) {
211
- index = (index + listLength) % listLength;
212
- }
213
-
214
- return list[Math.max(0, Math.min(index, listLength - 1))];
215
- };
216
-
217
- /**
218
- * --------------------------------------------------------------------------
219
- * Bootstrap (v5.1.3): dropdown.js
220
- * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
221
- * --------------------------------------------------------------------------
222
- */
223
- /**
224
- * ------------------------------------------------------------------------
225
- * Constants
226
- * ------------------------------------------------------------------------
227
- */
228
-
229
- const NAME = 'dropdown';
230
- const DATA_KEY = 'bs.dropdown';
231
- const EVENT_KEY = `.${DATA_KEY}`;
232
- const DATA_API_KEY = '.data-api';
233
- const ESCAPE_KEY = 'Escape';
234
- const SPACE_KEY = 'Space';
235
- const TAB_KEY = 'Tab';
236
- const ARROW_UP_KEY = 'ArrowUp';
237
- const ARROW_DOWN_KEY = 'ArrowDown';
238
- const RIGHT_MOUSE_BUTTON = 2; // MouseEvent.button value for the secondary button, usually the right button
239
-
240
- const REGEXP_KEYDOWN = new RegExp(`${ARROW_UP_KEY}|${ARROW_DOWN_KEY}|${ESCAPE_KEY}`);
241
- const EVENT_HIDE = `hide${EVENT_KEY}`;
242
- const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
243
- const EVENT_SHOW = `show${EVENT_KEY}`;
244
- const EVENT_SHOWN = `shown${EVENT_KEY}`;
245
- const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
246
- const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY}${DATA_API_KEY}`;
247
- const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY}${DATA_API_KEY}`;
248
- const CLASS_NAME_SHOW = 'show';
249
- const CLASS_NAME_DROPUP = 'dropup';
250
- const CLASS_NAME_DROPEND = 'dropend';
251
- const CLASS_NAME_DROPSTART = 'dropstart';
252
- const CLASS_NAME_NAVBAR = 'navbar';
253
- const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="dropdown"]';
254
- const SELECTOR_MENU = '.dropdown-menu';
255
- const SELECTOR_NAVBAR_NAV = '.navbar-nav';
256
- const SELECTOR_VISIBLE_ITEMS = '.dropdown-menu .dropdown-item:not(.disabled):not(:disabled)';
257
- const PLACEMENT_TOP = isRTL() ? 'top-end' : 'top-start';
258
- const PLACEMENT_TOPEND = isRTL() ? 'top-start' : 'top-end';
259
- const PLACEMENT_BOTTOM = isRTL() ? 'bottom-end' : 'bottom-start';
260
- const PLACEMENT_BOTTOMEND = isRTL() ? 'bottom-start' : 'bottom-end';
261
- const PLACEMENT_RIGHT = isRTL() ? 'left-start' : 'right-start';
262
- const PLACEMENT_LEFT = isRTL() ? 'right-start' : 'left-start';
263
- const Default = {
264
- offset: [0, 2],
265
- boundary: 'clippingParents',
266
- reference: 'toggle',
267
- display: 'dynamic',
268
- popperConfig: null,
269
- autoClose: true
270
- };
271
- const DefaultType = {
272
- offset: '(array|string|function)',
273
- boundary: '(string|element)',
274
- reference: '(string|element|object)',
275
- display: 'string',
276
- popperConfig: '(null|object|function)',
277
- autoClose: '(boolean|string)'
278
- };
279
- /**
280
- * ------------------------------------------------------------------------
281
- * Class Definition
282
- * ------------------------------------------------------------------------
283
- */
284
-
285
- class Dropdown extends BaseComponent__default["default"] {
286
- constructor(element, config) {
287
- super(element);
288
- this._popper = null;
289
- this._config = this._getConfig(config);
290
- this._menu = this._getMenuElement();
291
- this._inNavbar = this._detectNavbar();
292
- } // Getters
293
-
294
-
295
- static get Default() {
296
- return Default;
297
- }
298
-
299
- static get DefaultType() {
300
- return DefaultType;
301
- }
302
-
303
- static get NAME() {
304
- return NAME;
305
- } // Public
306
-
307
-
308
- toggle() {
309
- return this._isShown() ? this.hide() : this.show();
310
- }
311
-
312
- show() {
313
- if (isDisabled(this._element) || this._isShown(this._menu)) {
314
- return;
315
- }
316
-
317
- const relatedTarget = {
318
- relatedTarget: this._element
319
- };
320
- const showEvent = EventHandler__default["default"].trigger(this._element, EVENT_SHOW, relatedTarget);
321
-
322
- if (showEvent.defaultPrevented) {
323
- return;
324
- }
325
-
326
- const parent = Dropdown.getParentFromElement(this._element); // Totally disable Popper for Dropdowns in Navbar
327
-
328
- if (this._inNavbar) {
329
- Manipulator__default["default"].setDataAttribute(this._menu, 'popper', 'none');
330
- } else {
331
- this._createPopper(parent);
332
- } // If this is a touch-enabled device we add extra
333
- // empty mouseover listeners to the body's immediate children;
334
- // only needed because of broken event delegation on iOS
335
- // https://www.quirksmode.org/blog/archives/2014/02/mouse_event_bub.html
336
-
337
-
338
- if ('ontouchstart' in document.documentElement && !parent.closest(SELECTOR_NAVBAR_NAV)) {
339
- [].concat(...document.body.children).forEach(elem => EventHandler__default["default"].on(elem, 'mouseover', noop));
340
- }
341
-
342
- this._element.focus();
343
-
344
- this._element.setAttribute('aria-expanded', true);
345
-
346
- this._menu.classList.add(CLASS_NAME_SHOW);
347
-
348
- this._element.classList.add(CLASS_NAME_SHOW);
349
-
350
- EventHandler__default["default"].trigger(this._element, EVENT_SHOWN, relatedTarget);
351
- }
352
-
353
- hide() {
354
- if (isDisabled(this._element) || !this._isShown(this._menu)) {
355
- return;
356
- }
357
-
358
- const relatedTarget = {
359
- relatedTarget: this._element
360
- };
361
-
362
- this._completeHide(relatedTarget);
363
- }
364
-
365
- dispose() {
366
- if (this._popper) {
367
- this._popper.destroy();
368
- }
369
-
370
- super.dispose();
371
- }
372
-
373
- update() {
374
- this._inNavbar = this._detectNavbar();
375
-
376
- if (this._popper) {
377
- this._popper.update();
378
- }
379
- } // Private
380
-
381
-
382
- _completeHide(relatedTarget) {
383
- const hideEvent = EventHandler__default["default"].trigger(this._element, EVENT_HIDE, relatedTarget);
384
-
385
- if (hideEvent.defaultPrevented) {
386
- return;
387
- } // If this is a touch-enabled device we remove the extra
388
- // empty mouseover listeners we added for iOS support
389
-
390
-
391
- if ('ontouchstart' in document.documentElement) {
392
- [].concat(...document.body.children).forEach(elem => EventHandler__default["default"].off(elem, 'mouseover', noop));
393
- }
394
-
395
- if (this._popper) {
396
- this._popper.destroy();
397
- }
398
-
399
- this._menu.classList.remove(CLASS_NAME_SHOW);
400
-
401
- this._element.classList.remove(CLASS_NAME_SHOW);
402
-
403
- this._element.setAttribute('aria-expanded', 'false');
404
-
405
- Manipulator__default["default"].removeDataAttribute(this._menu, 'popper');
406
- EventHandler__default["default"].trigger(this._element, EVENT_HIDDEN, relatedTarget);
407
- }
408
-
409
- _getConfig(config) {
410
- config = { ...this.constructor.Default,
411
- ...Manipulator__default["default"].getDataAttributes(this._element),
412
- ...config
413
- };
414
- typeCheckConfig(NAME, config, this.constructor.DefaultType);
415
-
416
- if (typeof config.reference === 'object' && !isElement(config.reference) && typeof config.reference.getBoundingClientRect !== 'function') {
417
- // Popper virtual elements require a getBoundingClientRect method
418
- throw new TypeError(`${NAME.toUpperCase()}: Option "reference" provided type "object" without a required "getBoundingClientRect" method.`);
419
- }
420
-
421
- return config;
422
- }
423
-
424
- _createPopper(parent) {
425
- if (typeof Popper__namespace === 'undefined') {
426
- throw new TypeError('Bootstrap\'s dropdowns require Popper (https://popper.js.org)');
427
- }
428
-
429
- let referenceElement = this._element;
430
-
431
- if (this._config.reference === 'parent') {
432
- referenceElement = parent;
433
- } else if (isElement(this._config.reference)) {
434
- referenceElement = getElement(this._config.reference);
435
- } else if (typeof this._config.reference === 'object') {
436
- referenceElement = this._config.reference;
437
- }
438
-
439
- const popperConfig = this._getPopperConfig();
440
-
441
- const isDisplayStatic = popperConfig.modifiers.find(modifier => modifier.name === 'applyStyles' && modifier.enabled === false);
442
- this._popper = Popper__namespace.createPopper(referenceElement, this._menu, popperConfig);
443
-
444
- if (isDisplayStatic) {
445
- Manipulator__default["default"].setDataAttribute(this._menu, 'popper', 'static');
446
- }
447
- }
448
-
449
- _isShown(element = this._element) {
450
- return element.classList.contains(CLASS_NAME_SHOW);
451
- }
452
-
453
- _getMenuElement() {
454
- return SelectorEngine__default["default"].next(this._element, SELECTOR_MENU)[0];
455
- }
456
-
457
- _getPlacement() {
458
- const parentDropdown = this._element.parentNode;
459
-
460
- if (parentDropdown.classList.contains(CLASS_NAME_DROPEND)) {
461
- return PLACEMENT_RIGHT;
462
- }
463
-
464
- if (parentDropdown.classList.contains(CLASS_NAME_DROPSTART)) {
465
- return PLACEMENT_LEFT;
466
- } // We need to trim the value because custom properties can also include spaces
467
-
468
-
469
- const isEnd = getComputedStyle(this._menu).getPropertyValue('--bs-position').trim() === 'end';
470
-
471
- if (parentDropdown.classList.contains(CLASS_NAME_DROPUP)) {
472
- return isEnd ? PLACEMENT_TOPEND : PLACEMENT_TOP;
473
- }
474
-
475
- return isEnd ? PLACEMENT_BOTTOMEND : PLACEMENT_BOTTOM;
476
- }
477
-
478
- _detectNavbar() {
479
- return this._element.closest(`.${CLASS_NAME_NAVBAR}`) !== null;
480
- }
481
-
482
- _getOffset() {
483
- const {
484
- offset
485
- } = this._config;
486
-
487
- if (typeof offset === 'string') {
488
- return offset.split(',').map(val => Number.parseInt(val, 10));
489
- }
490
-
491
- if (typeof offset === 'function') {
492
- return popperData => offset(popperData, this._element);
493
- }
494
-
495
- return offset;
496
- }
497
-
498
- _getPopperConfig() {
499
- const defaultBsPopperConfig = {
500
- placement: this._getPlacement(),
501
- modifiers: [{
502
- name: 'preventOverflow',
503
- options: {
504
- boundary: this._config.boundary
505
- }
506
- }, {
507
- name: 'offset',
508
- options: {
509
- offset: this._getOffset()
510
- }
511
- }]
512
- }; // Disable Popper if we have a static display
513
-
514
- if (this._config.display === 'static') {
515
- defaultBsPopperConfig.modifiers = [{
516
- name: 'applyStyles',
517
- enabled: false
518
- }];
519
- }
520
-
521
- return { ...defaultBsPopperConfig,
522
- ...(typeof this._config.popperConfig === 'function' ? this._config.popperConfig(defaultBsPopperConfig) : this._config.popperConfig)
523
- };
524
- }
525
-
526
- _selectMenuItem({
527
- key,
528
- target
529
- }) {
530
- const items = SelectorEngine__default["default"].find(SELECTOR_VISIBLE_ITEMS, this._menu).filter(isVisible);
531
-
532
- if (!items.length) {
533
- return;
534
- } // if target isn't included in items (e.g. when expanding the dropdown)
535
- // allow cycling to get the last item in case key equals ARROW_UP_KEY
536
-
537
-
538
- getNextActiveElement(items, target, key === ARROW_DOWN_KEY, !items.includes(target)).focus();
539
- } // Static
540
-
541
-
542
- static jQueryInterface(config) {
543
- return this.each(function () {
544
- const data = Dropdown.getOrCreateInstance(this, config);
545
-
546
- if (typeof config !== 'string') {
547
- return;
548
- }
549
-
550
- if (typeof data[config] === 'undefined') {
551
- throw new TypeError(`No method named "${config}"`);
552
- }
553
-
554
- data[config]();
555
- });
556
- }
557
-
558
- static clearMenus(event) {
559
- if (event && (event.button === RIGHT_MOUSE_BUTTON || event.type === 'keyup' && event.key !== TAB_KEY)) {
560
- return;
561
- }
562
-
563
- const toggles = SelectorEngine__default["default"].find(SELECTOR_DATA_TOGGLE);
564
-
565
- for (let i = 0, len = toggles.length; i < len; i++) {
566
- const context = Dropdown.getInstance(toggles[i]);
567
-
568
- if (!context || context._config.autoClose === false) {
569
- continue;
570
- }
571
-
572
- if (!context._isShown()) {
573
- continue;
574
- }
575
-
576
- const relatedTarget = {
577
- relatedTarget: context._element
578
- };
579
-
580
- if (event) {
581
- const composedPath = event.composedPath();
582
- const isMenuTarget = composedPath.includes(context._menu);
583
-
584
- if (composedPath.includes(context._element) || context._config.autoClose === 'inside' && !isMenuTarget || context._config.autoClose === 'outside' && isMenuTarget) {
585
- continue;
586
- } // Tab navigation through the dropdown menu or events from contained inputs shouldn't close the menu
587
-
588
-
589
- if (context._menu.contains(event.target) && (event.type === 'keyup' && event.key === TAB_KEY || /input|select|option|textarea|form/i.test(event.target.tagName))) {
590
- continue;
591
- }
592
-
593
- if (event.type === 'click') {
594
- relatedTarget.clickEvent = event;
595
- }
596
- }
597
-
598
- context._completeHide(relatedTarget);
599
- }
600
- }
601
-
602
- static getParentFromElement(element) {
603
- return getElementFromSelector(element) || element.parentNode;
604
- }
605
-
606
- static dataApiKeydownHandler(event) {
607
- // If not input/textarea:
608
- // - And not a key in REGEXP_KEYDOWN => not a dropdown command
609
- // If input/textarea:
610
- // - If space key => not a dropdown command
611
- // - If key is other than escape
612
- // - If key is not up or down => not a dropdown command
613
- // - If trigger inside the menu => not a dropdown command
614
- 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)) {
615
- return;
616
- }
617
-
618
- const isActive = this.classList.contains(CLASS_NAME_SHOW);
619
-
620
- if (!isActive && event.key === ESCAPE_KEY) {
621
- return;
622
- }
623
-
624
- event.preventDefault();
625
- event.stopPropagation();
626
-
627
- if (isDisabled(this)) {
628
- return;
629
- }
630
-
631
- const getToggleButton = this.matches(SELECTOR_DATA_TOGGLE) ? this : SelectorEngine__default["default"].prev(this, SELECTOR_DATA_TOGGLE)[0];
632
- const instance = Dropdown.getOrCreateInstance(getToggleButton);
633
-
634
- if (event.key === ESCAPE_KEY) {
635
- instance.hide();
636
- return;
637
- }
638
-
639
- if (event.key === ARROW_UP_KEY || event.key === ARROW_DOWN_KEY) {
640
- if (!isActive) {
641
- instance.show();
642
- }
643
-
644
- instance._selectMenuItem(event);
645
-
646
- return;
647
- }
648
-
649
- if (!isActive || event.key === SPACE_KEY) {
650
- Dropdown.clearMenus();
651
- }
652
- }
653
-
654
- }
655
- /**
656
- * ------------------------------------------------------------------------
657
- * Data Api implementation
658
- * ------------------------------------------------------------------------
659
- */
660
-
661
-
662
- EventHandler__default["default"].on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE, Dropdown.dataApiKeydownHandler);
663
- EventHandler__default["default"].on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
664
- EventHandler__default["default"].on(document, EVENT_CLICK_DATA_API, Dropdown.clearMenus);
665
- EventHandler__default["default"].on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
666
- EventHandler__default["default"].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
667
- event.preventDefault();
668
- Dropdown.getOrCreateInstance(this).toggle();
669
- });
670
- /**
671
- * ------------------------------------------------------------------------
672
- * jQuery
673
- * ------------------------------------------------------------------------
674
- * add .Dropdown to jQuery only if jQuery is present
675
- */
676
-
677
- defineJQueryPlugin(Dropdown);
678
-
679
- return Dropdown;
680
-
681
- }));
682
- //# sourceMappingURL=dropdown.js.map