@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.
- package/bin/build-plugins.js +77 -160
- package/bootstrap-icons.js +211 -1
- package/js/dist/alert.js +6 -137
- package/js/dist/alert.js.map +1 -1
- package/js/dist/base-component.js +7 -109
- package/js/dist/base-component.js.map +1 -1
- package/js/dist/button.js +5 -65
- package/js/dist/button.js.map +1 -1
- package/js/dist/carousel.js +13 -190
- package/js/dist/carousel.js.map +1 -1
- package/js/dist/collapse.js +12 -170
- package/js/dist/collapse.js.map +1 -1
- package/js/dist/dom/data.js +0 -5
- package/js/dist/dom/data.js.map +1 -1
- package/js/dist/dom/event-handler.js +5 -29
- package/js/dist/dom/event-handler.js.map +1 -1
- package/js/dist/dom/manipulator.js +0 -5
- package/js/dist/dom/manipulator.js.map +1 -1
- package/js/dist/dom/selector-engine.js +5 -53
- package/js/dist/dom/selector-engine.js.map +1 -1
- package/js/dist/dropdown.js +23 -212
- package/js/dist/dropdown.js.map +1 -1
- package/js/dist/modal.js +18 -611
- package/js/dist/modal.js.map +1 -1
- package/js/dist/offcanvas.js +19 -610
- package/js/dist/offcanvas.js.map +1 -1
- package/js/dist/popover.js +5 -65
- package/js/dist/popover.js.map +1 -1
- package/js/dist/scrollspy.js +8 -147
- package/js/dist/scrollspy.js.map +1 -1
- package/js/dist/tab.js +8 -127
- package/js/dist/tab.js.map +1 -1
- package/js/dist/toast.js +8 -185
- package/js/dist/toast.js.map +1 -1
- package/js/dist/tooltip.js +18 -277
- package/js/dist/tooltip.js.map +1 -1
- package/js/dist/util/backdrop.js +138 -0
- package/js/dist/util/backdrop.js.map +1 -0
- package/js/dist/util/component-functions.js +42 -0
- package/js/dist/util/component-functions.js.map +1 -0
- package/js/dist/util/focustrap.js +118 -0
- package/js/dist/util/focustrap.js.map +1 -0
- package/js/dist/util/index.js +342 -0
- package/js/dist/util/index.js.map +1 -0
- package/js/dist/util/sanitizer.js +125 -0
- package/js/dist/util/sanitizer.js.map +1 -0
- package/js/dist/util/scrollbar.js +119 -0
- package/js/dist/util/scrollbar.js.map +1 -0
- package/package.json +4 -3
- package/plugins/alert.js +0 -230
- package/plugins/alert.js.map +0 -1
- package/plugins/base-component.js +0 -178
- package/plugins/base-component.js.map +0 -1
- package/plugins/button.js +0 -141
- package/plugins/button.js.map +0 -1
- package/plugins/carousel.js +0 -738
- package/plugins/carousel.js.map +0 -1
- package/plugins/collapse.js +0 -490
- package/plugins/collapse.js.map +0 -1
- package/plugins/dom/data.js +0 -64
- package/plugins/dom/data.js.map +0 -1
- package/plugins/dom/event-handler.js +0 -317
- package/plugins/dom/event-handler.js.map +0 -1
- package/plugins/dom/manipulator.js +0 -84
- package/plugins/dom/manipulator.js.map +0 -1
- package/plugins/dom/selector-engine.js +0 -123
- package/plugins/dom/selector-engine.js.map +0 -1
- package/plugins/dropdown.js +0 -682
- package/plugins/dropdown.js.map +0 -1
- package/plugins/modal.js +0 -1037
- package/plugins/modal.js.map +0 -1
- package/plugins/popover.js +0 -179
- package/plugins/popover.js.map +0 -1
- package/plugins/scrollspy.js +0 -386
- package/plugins/scrollspy.js.map +0 -1
- package/plugins/tab.js +0 -328
- package/plugins/tab.js.map +0 -1
- package/plugins/toast.js +0 -418
- package/plugins/toast.js.map +0 -1
- package/plugins/tooltip.js +0 -1001
- package/plugins/tooltip.js.map +0 -1
package/plugins/carousel.js
DELETED
|
@@ -1,738 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(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(['./dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base));
|
|
5
|
-
})(this, (function (EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
|
10
|
-
var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
|
|
11
|
-
var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
|
12
|
-
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* --------------------------------------------------------------------------
|
|
16
|
-
* Bootstrap (v5.1.3): util/index.js
|
|
17
|
-
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
18
|
-
* --------------------------------------------------------------------------
|
|
19
|
-
*/
|
|
20
|
-
const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
|
21
|
-
|
|
22
|
-
const toType = obj => {
|
|
23
|
-
if (obj === null || obj === undefined) {
|
|
24
|
-
return `${obj}`;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const getSelector = element => {
|
|
31
|
-
let selector = element.getAttribute('data-bs-target');
|
|
32
|
-
|
|
33
|
-
if (!selector || selector === '#') {
|
|
34
|
-
let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
|
|
35
|
-
// so everything starting with `#` or `.`. If a "real" URL is used as the selector,
|
|
36
|
-
// `document.querySelector` will rightfully complain it is invalid.
|
|
37
|
-
// See https://github.com/twbs/bootstrap/issues/32273
|
|
38
|
-
|
|
39
|
-
if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
|
|
40
|
-
return null;
|
|
41
|
-
} // Just in case some CMS puts out a full URL with the anchor appended
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
|
|
45
|
-
hrefAttr = `#${hrefAttr.split('#')[1]}`;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return selector;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const getElementFromSelector = element => {
|
|
55
|
-
const selector = getSelector(element);
|
|
56
|
-
return selector ? document.querySelector(selector) : null;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const triggerTransitionEnd = element => {
|
|
60
|
-
element.dispatchEvent(new Event(TRANSITION_END));
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const isElement = obj => {
|
|
64
|
-
if (!obj || typeof obj !== 'object') {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (typeof obj.jquery !== 'undefined') {
|
|
69
|
-
obj = obj[0];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return typeof obj.nodeType !== 'undefined';
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const typeCheckConfig = (componentName, config, configTypes) => {
|
|
76
|
-
Object.keys(configTypes).forEach(property => {
|
|
77
|
-
const expectedTypes = configTypes[property];
|
|
78
|
-
const value = config[property];
|
|
79
|
-
const valueType = value && isElement(value) ? 'element' : toType(value);
|
|
80
|
-
|
|
81
|
-
if (!new RegExp(expectedTypes).test(valueType)) {
|
|
82
|
-
throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const isVisible = element => {
|
|
88
|
-
if (!isElement(element) || element.getClientRects().length === 0) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Trick to restart an element's animation
|
|
96
|
-
*
|
|
97
|
-
* @param {HTMLElement} element
|
|
98
|
-
* @return void
|
|
99
|
-
*
|
|
100
|
-
* @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const reflow = element => {
|
|
105
|
-
// eslint-disable-next-line no-unused-expressions
|
|
106
|
-
element.offsetHeight;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const getjQuery = () => {
|
|
110
|
-
const {
|
|
111
|
-
jQuery
|
|
112
|
-
} = window;
|
|
113
|
-
|
|
114
|
-
if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
|
|
115
|
-
return jQuery;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return null;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const DOMContentLoadedCallbacks = [];
|
|
122
|
-
|
|
123
|
-
const onDOMContentLoaded = callback => {
|
|
124
|
-
if (document.readyState === 'loading') {
|
|
125
|
-
// add listener on the first call when the document is in loading state
|
|
126
|
-
if (!DOMContentLoadedCallbacks.length) {
|
|
127
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
128
|
-
DOMContentLoadedCallbacks.forEach(callback => callback());
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
DOMContentLoadedCallbacks.push(callback);
|
|
133
|
-
} else {
|
|
134
|
-
callback();
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const isRTL = () => document.documentElement.dir === 'rtl';
|
|
139
|
-
|
|
140
|
-
const defineJQueryPlugin = plugin => {
|
|
141
|
-
onDOMContentLoaded(() => {
|
|
142
|
-
const $ = getjQuery();
|
|
143
|
-
/* istanbul ignore if */
|
|
144
|
-
|
|
145
|
-
if ($) {
|
|
146
|
-
const name = plugin.NAME;
|
|
147
|
-
const JQUERY_NO_CONFLICT = $.fn[name];
|
|
148
|
-
$.fn[name] = plugin.jQueryInterface;
|
|
149
|
-
$.fn[name].Constructor = plugin;
|
|
150
|
-
|
|
151
|
-
$.fn[name].noConflict = () => {
|
|
152
|
-
$.fn[name] = JQUERY_NO_CONFLICT;
|
|
153
|
-
return plugin.jQueryInterface;
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Return the previous/next element of a list.
|
|
160
|
-
*
|
|
161
|
-
* @param {array} list The list of elements
|
|
162
|
-
* @param activeElement The active element
|
|
163
|
-
* @param shouldGetNext Choose to get next or previous element
|
|
164
|
-
* @param isCycleAllowed
|
|
165
|
-
* @return {Element|elem} The proper element
|
|
166
|
-
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
|
|
170
|
-
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
|
|
171
|
-
|
|
172
|
-
if (index === -1) {
|
|
173
|
-
return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const listLength = list.length;
|
|
177
|
-
index += shouldGetNext ? 1 : -1;
|
|
178
|
-
|
|
179
|
-
if (isCycleAllowed) {
|
|
180
|
-
index = (index + listLength) % listLength;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return list[Math.max(0, Math.min(index, listLength - 1))];
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* --------------------------------------------------------------------------
|
|
188
|
-
* Bootstrap (v5.1.3): carousel.js
|
|
189
|
-
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
190
|
-
* --------------------------------------------------------------------------
|
|
191
|
-
*/
|
|
192
|
-
/**
|
|
193
|
-
* ------------------------------------------------------------------------
|
|
194
|
-
* Constants
|
|
195
|
-
* ------------------------------------------------------------------------
|
|
196
|
-
*/
|
|
197
|
-
|
|
198
|
-
const NAME = 'carousel';
|
|
199
|
-
const DATA_KEY = 'bs.carousel';
|
|
200
|
-
const EVENT_KEY = `.${DATA_KEY}`;
|
|
201
|
-
const DATA_API_KEY = '.data-api';
|
|
202
|
-
const ARROW_LEFT_KEY = 'ArrowLeft';
|
|
203
|
-
const ARROW_RIGHT_KEY = 'ArrowRight';
|
|
204
|
-
const TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch
|
|
205
|
-
|
|
206
|
-
const SWIPE_THRESHOLD = 40;
|
|
207
|
-
const Default = {
|
|
208
|
-
interval: 5000,
|
|
209
|
-
keyboard: true,
|
|
210
|
-
slide: false,
|
|
211
|
-
pause: 'hover',
|
|
212
|
-
wrap: true,
|
|
213
|
-
touch: true
|
|
214
|
-
};
|
|
215
|
-
const DefaultType = {
|
|
216
|
-
interval: '(number|boolean)',
|
|
217
|
-
keyboard: 'boolean',
|
|
218
|
-
slide: '(boolean|string)',
|
|
219
|
-
pause: '(string|boolean)',
|
|
220
|
-
wrap: 'boolean',
|
|
221
|
-
touch: 'boolean'
|
|
222
|
-
};
|
|
223
|
-
const ORDER_NEXT = 'next';
|
|
224
|
-
const ORDER_PREV = 'prev';
|
|
225
|
-
const DIRECTION_LEFT = 'left';
|
|
226
|
-
const DIRECTION_RIGHT = 'right';
|
|
227
|
-
const KEY_TO_DIRECTION = {
|
|
228
|
-
[ARROW_LEFT_KEY]: DIRECTION_RIGHT,
|
|
229
|
-
[ARROW_RIGHT_KEY]: DIRECTION_LEFT
|
|
230
|
-
};
|
|
231
|
-
const EVENT_SLIDE = `slide${EVENT_KEY}`;
|
|
232
|
-
const EVENT_SLID = `slid${EVENT_KEY}`;
|
|
233
|
-
const EVENT_KEYDOWN = `keydown${EVENT_KEY}`;
|
|
234
|
-
const EVENT_MOUSEENTER = `mouseenter${EVENT_KEY}`;
|
|
235
|
-
const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY}`;
|
|
236
|
-
const EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`;
|
|
237
|
-
const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`;
|
|
238
|
-
const EVENT_TOUCHEND = `touchend${EVENT_KEY}`;
|
|
239
|
-
const EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`;
|
|
240
|
-
const EVENT_POINTERUP = `pointerup${EVENT_KEY}`;
|
|
241
|
-
const EVENT_DRAG_START = `dragstart${EVENT_KEY}`;
|
|
242
|
-
const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}`;
|
|
243
|
-
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
|
|
244
|
-
const CLASS_NAME_CAROUSEL = 'carousel';
|
|
245
|
-
const CLASS_NAME_ACTIVE = 'active';
|
|
246
|
-
const CLASS_NAME_SLIDE = 'slide';
|
|
247
|
-
const CLASS_NAME_END = 'carousel-item-end';
|
|
248
|
-
const CLASS_NAME_START = 'carousel-item-start';
|
|
249
|
-
const CLASS_NAME_NEXT = 'carousel-item-next';
|
|
250
|
-
const CLASS_NAME_PREV = 'carousel-item-prev';
|
|
251
|
-
const CLASS_NAME_POINTER_EVENT = 'pointer-event';
|
|
252
|
-
const SELECTOR_ACTIVE = '.active';
|
|
253
|
-
const SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
|
|
254
|
-
const SELECTOR_ITEM = '.carousel-item';
|
|
255
|
-
const SELECTOR_ITEM_IMG = '.carousel-item img';
|
|
256
|
-
const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
|
|
257
|
-
const SELECTOR_INDICATORS = '.carousel-indicators';
|
|
258
|
-
const SELECTOR_INDICATOR = '[data-bs-target]';
|
|
259
|
-
const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]';
|
|
260
|
-
const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]';
|
|
261
|
-
const POINTER_TYPE_TOUCH = 'touch';
|
|
262
|
-
const POINTER_TYPE_PEN = 'pen';
|
|
263
|
-
/**
|
|
264
|
-
* ------------------------------------------------------------------------
|
|
265
|
-
* Class Definition
|
|
266
|
-
* ------------------------------------------------------------------------
|
|
267
|
-
*/
|
|
268
|
-
|
|
269
|
-
class Carousel extends BaseComponent__default["default"] {
|
|
270
|
-
constructor(element, config) {
|
|
271
|
-
super(element);
|
|
272
|
-
this._items = null;
|
|
273
|
-
this._interval = null;
|
|
274
|
-
this._activeElement = null;
|
|
275
|
-
this._isPaused = false;
|
|
276
|
-
this._isSliding = false;
|
|
277
|
-
this.touchTimeout = null;
|
|
278
|
-
this.touchStartX = 0;
|
|
279
|
-
this.touchDeltaX = 0;
|
|
280
|
-
this._config = this._getConfig(config);
|
|
281
|
-
this._indicatorsElement = SelectorEngine__default["default"].findOne(SELECTOR_INDICATORS, this._element);
|
|
282
|
-
this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
|
|
283
|
-
this._pointerEvent = Boolean(window.PointerEvent);
|
|
284
|
-
|
|
285
|
-
this._addEventListeners();
|
|
286
|
-
} // Getters
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
static get Default() {
|
|
290
|
-
return Default;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
static get NAME() {
|
|
294
|
-
return NAME;
|
|
295
|
-
} // Public
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
next() {
|
|
299
|
-
this._slide(ORDER_NEXT);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
nextWhenVisible() {
|
|
303
|
-
// Don't call next when the page isn't visible
|
|
304
|
-
// or the carousel or its parent isn't visible
|
|
305
|
-
if (!document.hidden && isVisible(this._element)) {
|
|
306
|
-
this.next();
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
prev() {
|
|
311
|
-
this._slide(ORDER_PREV);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
pause(event) {
|
|
315
|
-
if (!event) {
|
|
316
|
-
this._isPaused = true;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
if (SelectorEngine__default["default"].findOne(SELECTOR_NEXT_PREV, this._element)) {
|
|
320
|
-
triggerTransitionEnd(this._element);
|
|
321
|
-
this.cycle(true);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
clearInterval(this._interval);
|
|
325
|
-
this._interval = null;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
cycle(event) {
|
|
329
|
-
if (!event) {
|
|
330
|
-
this._isPaused = false;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (this._interval) {
|
|
334
|
-
clearInterval(this._interval);
|
|
335
|
-
this._interval = null;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (this._config && this._config.interval && !this._isPaused) {
|
|
339
|
-
this._updateInterval();
|
|
340
|
-
|
|
341
|
-
this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
to(index) {
|
|
346
|
-
this._activeElement = SelectorEngine__default["default"].findOne(SELECTOR_ACTIVE_ITEM, this._element);
|
|
347
|
-
|
|
348
|
-
const activeIndex = this._getItemIndex(this._activeElement);
|
|
349
|
-
|
|
350
|
-
if (index > this._items.length - 1 || index < 0) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
if (this._isSliding) {
|
|
355
|
-
EventHandler__default["default"].one(this._element, EVENT_SLID, () => this.to(index));
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
if (activeIndex === index) {
|
|
360
|
-
this.pause();
|
|
361
|
-
this.cycle();
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV;
|
|
366
|
-
|
|
367
|
-
this._slide(order, this._items[index]);
|
|
368
|
-
} // Private
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
_getConfig(config) {
|
|
372
|
-
config = { ...Default,
|
|
373
|
-
...Manipulator__default["default"].getDataAttributes(this._element),
|
|
374
|
-
...(typeof config === 'object' ? config : {})
|
|
375
|
-
};
|
|
376
|
-
typeCheckConfig(NAME, config, DefaultType);
|
|
377
|
-
return config;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
_handleSwipe() {
|
|
381
|
-
const absDeltax = Math.abs(this.touchDeltaX);
|
|
382
|
-
|
|
383
|
-
if (absDeltax <= SWIPE_THRESHOLD) {
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
const direction = absDeltax / this.touchDeltaX;
|
|
388
|
-
this.touchDeltaX = 0;
|
|
389
|
-
|
|
390
|
-
if (!direction) {
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
this._slide(direction > 0 ? DIRECTION_RIGHT : DIRECTION_LEFT);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
_addEventListeners() {
|
|
398
|
-
if (this._config.keyboard) {
|
|
399
|
-
EventHandler__default["default"].on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
if (this._config.pause === 'hover') {
|
|
403
|
-
EventHandler__default["default"].on(this._element, EVENT_MOUSEENTER, event => this.pause(event));
|
|
404
|
-
EventHandler__default["default"].on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event));
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
if (this._config.touch && this._touchSupported) {
|
|
408
|
-
this._addTouchEventListeners();
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
_addTouchEventListeners() {
|
|
413
|
-
const hasPointerPenTouch = event => {
|
|
414
|
-
return this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH);
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
const start = event => {
|
|
418
|
-
if (hasPointerPenTouch(event)) {
|
|
419
|
-
this.touchStartX = event.clientX;
|
|
420
|
-
} else if (!this._pointerEvent) {
|
|
421
|
-
this.touchStartX = event.touches[0].clientX;
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
|
|
425
|
-
const move = event => {
|
|
426
|
-
// ensure swiping with one touch and not pinching
|
|
427
|
-
this.touchDeltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this.touchStartX;
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
const end = event => {
|
|
431
|
-
if (hasPointerPenTouch(event)) {
|
|
432
|
-
this.touchDeltaX = event.clientX - this.touchStartX;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
this._handleSwipe();
|
|
436
|
-
|
|
437
|
-
if (this._config.pause === 'hover') {
|
|
438
|
-
// If it's a touch-enabled device, mouseenter/leave are fired as
|
|
439
|
-
// part of the mouse compatibility events on first tap - the carousel
|
|
440
|
-
// would stop cycling until user tapped out of it;
|
|
441
|
-
// here, we listen for touchend, explicitly pause the carousel
|
|
442
|
-
// (as if it's the second time we tap on it, mouseenter compat event
|
|
443
|
-
// is NOT fired) and after a timeout (to allow for mouse compatibility
|
|
444
|
-
// events to fire) we explicitly restart cycling
|
|
445
|
-
this.pause();
|
|
446
|
-
|
|
447
|
-
if (this.touchTimeout) {
|
|
448
|
-
clearTimeout(this.touchTimeout);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
this.touchTimeout = setTimeout(event => this.cycle(event), TOUCHEVENT_COMPAT_WAIT + this._config.interval);
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
SelectorEngine__default["default"].find(SELECTOR_ITEM_IMG, this._element).forEach(itemImg => {
|
|
456
|
-
EventHandler__default["default"].on(itemImg, EVENT_DRAG_START, event => event.preventDefault());
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
if (this._pointerEvent) {
|
|
460
|
-
EventHandler__default["default"].on(this._element, EVENT_POINTERDOWN, event => start(event));
|
|
461
|
-
EventHandler__default["default"].on(this._element, EVENT_POINTERUP, event => end(event));
|
|
462
|
-
|
|
463
|
-
this._element.classList.add(CLASS_NAME_POINTER_EVENT);
|
|
464
|
-
} else {
|
|
465
|
-
EventHandler__default["default"].on(this._element, EVENT_TOUCHSTART, event => start(event));
|
|
466
|
-
EventHandler__default["default"].on(this._element, EVENT_TOUCHMOVE, event => move(event));
|
|
467
|
-
EventHandler__default["default"].on(this._element, EVENT_TOUCHEND, event => end(event));
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
_keydown(event) {
|
|
472
|
-
if (/input|textarea/i.test(event.target.tagName)) {
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
const direction = KEY_TO_DIRECTION[event.key];
|
|
477
|
-
|
|
478
|
-
if (direction) {
|
|
479
|
-
event.preventDefault();
|
|
480
|
-
|
|
481
|
-
this._slide(direction);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
_getItemIndex(element) {
|
|
486
|
-
this._items = element && element.parentNode ? SelectorEngine__default["default"].find(SELECTOR_ITEM, element.parentNode) : [];
|
|
487
|
-
return this._items.indexOf(element);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
_getItemByOrder(order, activeElement) {
|
|
491
|
-
const isNext = order === ORDER_NEXT;
|
|
492
|
-
return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
_triggerSlideEvent(relatedTarget, eventDirectionName) {
|
|
496
|
-
const targetIndex = this._getItemIndex(relatedTarget);
|
|
497
|
-
|
|
498
|
-
const fromIndex = this._getItemIndex(SelectorEngine__default["default"].findOne(SELECTOR_ACTIVE_ITEM, this._element));
|
|
499
|
-
|
|
500
|
-
return EventHandler__default["default"].trigger(this._element, EVENT_SLIDE, {
|
|
501
|
-
relatedTarget,
|
|
502
|
-
direction: eventDirectionName,
|
|
503
|
-
from: fromIndex,
|
|
504
|
-
to: targetIndex
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
_setActiveIndicatorElement(element) {
|
|
509
|
-
if (this._indicatorsElement) {
|
|
510
|
-
const activeIndicator = SelectorEngine__default["default"].findOne(SELECTOR_ACTIVE, this._indicatorsElement);
|
|
511
|
-
activeIndicator.classList.remove(CLASS_NAME_ACTIVE);
|
|
512
|
-
activeIndicator.removeAttribute('aria-current');
|
|
513
|
-
const indicators = SelectorEngine__default["default"].find(SELECTOR_INDICATOR, this._indicatorsElement);
|
|
514
|
-
|
|
515
|
-
for (let i = 0; i < indicators.length; i++) {
|
|
516
|
-
if (Number.parseInt(indicators[i].getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) {
|
|
517
|
-
indicators[i].classList.add(CLASS_NAME_ACTIVE);
|
|
518
|
-
indicators[i].setAttribute('aria-current', 'true');
|
|
519
|
-
break;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
_updateInterval() {
|
|
526
|
-
const element = this._activeElement || SelectorEngine__default["default"].findOne(SELECTOR_ACTIVE_ITEM, this._element);
|
|
527
|
-
|
|
528
|
-
if (!element) {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
const elementInterval = Number.parseInt(element.getAttribute('data-bs-interval'), 10);
|
|
533
|
-
|
|
534
|
-
if (elementInterval) {
|
|
535
|
-
this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
|
|
536
|
-
this._config.interval = elementInterval;
|
|
537
|
-
} else {
|
|
538
|
-
this._config.interval = this._config.defaultInterval || this._config.interval;
|
|
539
|
-
}
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
_slide(directionOrOrder, element) {
|
|
543
|
-
const order = this._directionToOrder(directionOrOrder);
|
|
544
|
-
|
|
545
|
-
const activeElement = SelectorEngine__default["default"].findOne(SELECTOR_ACTIVE_ITEM, this._element);
|
|
546
|
-
|
|
547
|
-
const activeElementIndex = this._getItemIndex(activeElement);
|
|
548
|
-
|
|
549
|
-
const nextElement = element || this._getItemByOrder(order, activeElement);
|
|
550
|
-
|
|
551
|
-
const nextElementIndex = this._getItemIndex(nextElement);
|
|
552
|
-
|
|
553
|
-
const isCycling = Boolean(this._interval);
|
|
554
|
-
const isNext = order === ORDER_NEXT;
|
|
555
|
-
const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END;
|
|
556
|
-
const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV;
|
|
557
|
-
|
|
558
|
-
const eventDirectionName = this._orderToDirection(order);
|
|
559
|
-
|
|
560
|
-
if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
|
|
561
|
-
this._isSliding = false;
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (this._isSliding) {
|
|
566
|
-
return;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
|
|
570
|
-
|
|
571
|
-
if (slideEvent.defaultPrevented) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
if (!activeElement || !nextElement) {
|
|
576
|
-
// Some weirdness is happening, so we bail
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
this._isSliding = true;
|
|
581
|
-
|
|
582
|
-
if (isCycling) {
|
|
583
|
-
this.pause();
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
this._setActiveIndicatorElement(nextElement);
|
|
587
|
-
|
|
588
|
-
this._activeElement = nextElement;
|
|
589
|
-
|
|
590
|
-
const triggerSlidEvent = () => {
|
|
591
|
-
EventHandler__default["default"].trigger(this._element, EVENT_SLID, {
|
|
592
|
-
relatedTarget: nextElement,
|
|
593
|
-
direction: eventDirectionName,
|
|
594
|
-
from: activeElementIndex,
|
|
595
|
-
to: nextElementIndex
|
|
596
|
-
});
|
|
597
|
-
};
|
|
598
|
-
|
|
599
|
-
if (this._element.classList.contains(CLASS_NAME_SLIDE)) {
|
|
600
|
-
nextElement.classList.add(orderClassName);
|
|
601
|
-
reflow(nextElement);
|
|
602
|
-
activeElement.classList.add(directionalClassName);
|
|
603
|
-
nextElement.classList.add(directionalClassName);
|
|
604
|
-
|
|
605
|
-
const completeCallBack = () => {
|
|
606
|
-
nextElement.classList.remove(directionalClassName, orderClassName);
|
|
607
|
-
nextElement.classList.add(CLASS_NAME_ACTIVE);
|
|
608
|
-
activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName);
|
|
609
|
-
this._isSliding = false;
|
|
610
|
-
setTimeout(triggerSlidEvent, 0);
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
this._queueCallback(completeCallBack, activeElement, true);
|
|
614
|
-
} else {
|
|
615
|
-
activeElement.classList.remove(CLASS_NAME_ACTIVE);
|
|
616
|
-
nextElement.classList.add(CLASS_NAME_ACTIVE);
|
|
617
|
-
this._isSliding = false;
|
|
618
|
-
triggerSlidEvent();
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
if (isCycling) {
|
|
622
|
-
this.cycle();
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
_directionToOrder(direction) {
|
|
627
|
-
if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
|
|
628
|
-
return direction;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
if (isRTL()) {
|
|
632
|
-
return direction === DIRECTION_LEFT ? ORDER_PREV : ORDER_NEXT;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
return direction === DIRECTION_LEFT ? ORDER_NEXT : ORDER_PREV;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
_orderToDirection(order) {
|
|
639
|
-
if (![ORDER_NEXT, ORDER_PREV].includes(order)) {
|
|
640
|
-
return order;
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
if (isRTL()) {
|
|
644
|
-
return order === ORDER_PREV ? DIRECTION_LEFT : DIRECTION_RIGHT;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
return order === ORDER_PREV ? DIRECTION_RIGHT : DIRECTION_LEFT;
|
|
648
|
-
} // Static
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
static carouselInterface(element, config) {
|
|
652
|
-
const data = Carousel.getOrCreateInstance(element, config);
|
|
653
|
-
let {
|
|
654
|
-
_config
|
|
655
|
-
} = data;
|
|
656
|
-
|
|
657
|
-
if (typeof config === 'object') {
|
|
658
|
-
_config = { ..._config,
|
|
659
|
-
...config
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
const action = typeof config === 'string' ? config : _config.slide;
|
|
664
|
-
|
|
665
|
-
if (typeof config === 'number') {
|
|
666
|
-
data.to(config);
|
|
667
|
-
} else if (typeof action === 'string') {
|
|
668
|
-
if (typeof data[action] === 'undefined') {
|
|
669
|
-
throw new TypeError(`No method named "${action}"`);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
data[action]();
|
|
673
|
-
} else if (_config.interval && _config.ride) {
|
|
674
|
-
data.pause();
|
|
675
|
-
data.cycle();
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
static jQueryInterface(config) {
|
|
680
|
-
return this.each(function () {
|
|
681
|
-
Carousel.carouselInterface(this, config);
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
static dataApiClickHandler(event) {
|
|
686
|
-
const target = getElementFromSelector(this);
|
|
687
|
-
|
|
688
|
-
if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
const config = { ...Manipulator__default["default"].getDataAttributes(target),
|
|
693
|
-
...Manipulator__default["default"].getDataAttributes(this)
|
|
694
|
-
};
|
|
695
|
-
const slideIndex = this.getAttribute('data-bs-slide-to');
|
|
696
|
-
|
|
697
|
-
if (slideIndex) {
|
|
698
|
-
config.interval = false;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
Carousel.carouselInterface(target, config);
|
|
702
|
-
|
|
703
|
-
if (slideIndex) {
|
|
704
|
-
Carousel.getInstance(target).to(slideIndex);
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
event.preventDefault();
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* ------------------------------------------------------------------------
|
|
713
|
-
* Data Api implementation
|
|
714
|
-
* ------------------------------------------------------------------------
|
|
715
|
-
*/
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
EventHandler__default["default"].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler);
|
|
719
|
-
EventHandler__default["default"].on(window, EVENT_LOAD_DATA_API, () => {
|
|
720
|
-
const carousels = SelectorEngine__default["default"].find(SELECTOR_DATA_RIDE);
|
|
721
|
-
|
|
722
|
-
for (let i = 0, len = carousels.length; i < len; i++) {
|
|
723
|
-
Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i]));
|
|
724
|
-
}
|
|
725
|
-
});
|
|
726
|
-
/**
|
|
727
|
-
* ------------------------------------------------------------------------
|
|
728
|
-
* jQuery
|
|
729
|
-
* ------------------------------------------------------------------------
|
|
730
|
-
* add .Carousel to jQuery only if jQuery is present
|
|
731
|
-
*/
|
|
732
|
-
|
|
733
|
-
defineJQueryPlugin(Carousel);
|
|
734
|
-
|
|
735
|
-
return Carousel;
|
|
736
|
-
|
|
737
|
-
}));
|
|
738
|
-
//# sourceMappingURL=carousel.js.map
|