carousel.js 25.7 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap carousel.js v5.0.0-alpha3 (https://getbootstrap.com/)
XhmikosR's avatar
XhmikosR committed
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
XhmikosR committed
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
Dist    
XhmikosR committed
5
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
XhmikosR's avatar
XhmikosR committed
7
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js')) :
  typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/event-handler.js', './dom/manipulator.js', './dom/selector-engine.js'], factory) :
XhmikosR's avatar
XhmikosR committed
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
XhmikosR's avatar
XhmikosR committed
10
}(this, (function (Data, EventHandler, Manipulator, SelectorEngine) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11

XhmikosR's avatar
XhmikosR committed
12
13
14
15
16
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

  var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
  var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
  var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
  var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
Mark Otto's avatar
dist    
Mark Otto committed
18

XhmikosR's avatar
XhmikosR committed
19
20
  /**
   * --------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
21
   * Bootstrap (v5.0.0-alpha3): util/index.js
XhmikosR's avatar
XhmikosR committed
22
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
XhmikosR's avatar
XhmikosR committed
23
24
25
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
XhmikosR's avatar
XhmikosR committed
26
  var TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
27
28

  var toType = function toType(obj) {
XhmikosR's avatar
XhmikosR committed
29
30
31
32
    if (obj === null || obj === undefined) {
      return "" + obj;
    }

XhmikosR's avatar
XhmikosR committed
33
34
35
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

XhmikosR's avatar
XhmikosR committed
36
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
37
    var selector = element.getAttribute('data-bs-target');
XhmikosR's avatar
XhmikosR committed
38
39
40

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
XhmikosR's avatar
XhmikosR committed
41
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
XhmikosR's avatar
XhmikosR committed
42
43
    }

XhmikosR's avatar
XhmikosR committed
44
45
46
47
48
49
    return selector;
  };

  var getElementFromSelector = function getElementFromSelector(element) {
    var selector = getSelector(element);
    return selector ? document.querySelector(selector) : null;
XhmikosR's avatar
XhmikosR committed
50
51
52
53
54
55
56
57
58
59
60
61
  };

  var getTransitionDurationFromElement = function getTransitionDurationFromElement(element) {
    if (!element) {
      return 0;
    } // Get transition-duration of the element


    var _window$getComputedSt = window.getComputedStyle(element),
        transitionDuration = _window$getComputedSt.transitionDuration,
        transitionDelay = _window$getComputedSt.transitionDelay;

XhmikosR's avatar
XhmikosR committed
62
63
    var floatTransitionDuration = Number.parseFloat(transitionDuration);
    var floatTransitionDelay = Number.parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
XhmikosR's avatar
XhmikosR committed
64
65
66
67
68
69
70
71

    if (!floatTransitionDuration && !floatTransitionDelay) {
      return 0;
    } // If multiple durations are defined, take the first


    transitionDuration = transitionDuration.split(',')[0];
    transitionDelay = transitionDelay.split(',')[0];
XhmikosR's avatar
XhmikosR committed
72
    return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
XhmikosR's avatar
XhmikosR committed
73
74
75
  };

  var triggerTransitionEnd = function triggerTransitionEnd(element) {
XhmikosR's avatar
XhmikosR committed
76
    element.dispatchEvent(new Event(TRANSITION_END));
XhmikosR's avatar
XhmikosR committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  };

  var isElement = function isElement(obj) {
    return (obj[0] || obj).nodeType;
  };

  var emulateTransitionEnd = function emulateTransitionEnd(element, duration) {
    var called = false;
    var durationPadding = 5;
    var emulatedDuration = duration + durationPadding;

    function listener() {
      called = true;
      element.removeEventListener(TRANSITION_END, listener);
    }

    element.addEventListener(TRANSITION_END, listener);
    setTimeout(function () {
      if (!called) {
        triggerTransitionEnd(element);
      }
    }, emulatedDuration);
  };

  var typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) {
    Object.keys(configTypes).forEach(function (property) {
      var expectedTypes = configTypes[property];
      var value = config[property];
      var valueType = value && isElement(value) ? 'element' : toType(value);

      if (!new RegExp(expectedTypes).test(valueType)) {
        throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
      }
    });
  };

  var isVisible = function isVisible(element) {
    if (!element) {
      return false;
    }

    if (element.style && element.parentNode && element.parentNode.style) {
XhmikosR's avatar
XhmikosR committed
119
120
121
      var elementStyle = getComputedStyle(element);
      var parentNodeStyle = getComputedStyle(element.parentNode);
      return elementStyle.display !== 'none' && parentNodeStyle.display !== 'none' && elementStyle.visibility !== 'hidden';
XhmikosR's avatar
XhmikosR committed
122
123
124
125
126
127
128
129
130
    }

    return false;
  };

  var reflow = function reflow(element) {
    return element.offsetHeight;
  };

XhmikosR's avatar
XhmikosR committed
131
132
133
134
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

XhmikosR's avatar
XhmikosR committed
135
    if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
XhmikosR's avatar
XhmikosR committed
136
137
138
139
140
141
      return jQuery;
    }

    return null;
  };

XhmikosR's avatar
XhmikosR committed
142
143
144
145
146
147
148
149
  var onDOMContentLoaded = function onDOMContentLoaded(callback) {
    if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', callback);
    } else {
      callback();
    }
  };

XhmikosR's avatar
XhmikosR committed
150
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
Mark Otto's avatar
Mark Otto committed
151
152
153
154

  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
fat's avatar
fat committed
155
  /**
XhmikosR's avatar
Dist    
XhmikosR committed
156
157
158
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
fat's avatar
fat committed
159
   */
Mark Otto's avatar
dist    
Mark Otto committed
160

XhmikosR's avatar
Dist    
XhmikosR committed
161
  var NAME = 'carousel';
XhmikosR's avatar
XhmikosR committed
162
  var VERSION = '5.0.0-alpha3';
XhmikosR's avatar
Dist    
XhmikosR committed
163
164
165
  var DATA_KEY = 'bs.carousel';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
XhmikosR's avatar
XhmikosR committed
166
167
  var ARROW_LEFT_KEY = 'ArrowLeft';
  var ARROW_RIGHT_KEY = 'ArrowRight';
XhmikosR's avatar
Dist    
XhmikosR committed
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
  var TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch

  var SWIPE_THRESHOLD = 40;
  var Default = {
    interval: 5000,
    keyboard: true,
    slide: false,
    pause: 'hover',
    wrap: true,
    touch: true
  };
  var DefaultType = {
    interval: '(number|boolean)',
    keyboard: 'boolean',
    slide: '(boolean|string)',
    pause: '(string|boolean)',
    wrap: 'boolean',
    touch: 'boolean'
  };
XhmikosR's avatar
XhmikosR committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
  var DIRECTION_NEXT = 'next';
  var DIRECTION_PREV = 'prev';
  var DIRECTION_LEFT = 'left';
  var DIRECTION_RIGHT = 'right';
  var EVENT_SLIDE = "slide" + EVENT_KEY;
  var EVENT_SLID = "slid" + EVENT_KEY;
  var EVENT_KEYDOWN = "keydown" + EVENT_KEY;
  var EVENT_MOUSEENTER = "mouseenter" + EVENT_KEY;
  var EVENT_MOUSELEAVE = "mouseleave" + EVENT_KEY;
  var EVENT_TOUCHSTART = "touchstart" + EVENT_KEY;
  var EVENT_TOUCHMOVE = "touchmove" + EVENT_KEY;
  var EVENT_TOUCHEND = "touchend" + EVENT_KEY;
  var EVENT_POINTERDOWN = "pointerdown" + EVENT_KEY;
  var EVENT_POINTERUP = "pointerup" + EVENT_KEY;
  var EVENT_DRAG_START = "dragstart" + EVENT_KEY;
  var EVENT_LOAD_DATA_API = "load" + EVENT_KEY + DATA_API_KEY;
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
  var CLASS_NAME_CAROUSEL = 'carousel';
  var CLASS_NAME_ACTIVE = 'active';
  var CLASS_NAME_SLIDE = 'slide';
  var CLASS_NAME_RIGHT = 'carousel-item-right';
  var CLASS_NAME_LEFT = 'carousel-item-left';
  var CLASS_NAME_NEXT = 'carousel-item-next';
  var CLASS_NAME_PREV = 'carousel-item-prev';
  var CLASS_NAME_POINTER_EVENT = 'pointer-event';
  var SELECTOR_ACTIVE = '.active';
  var SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
  var SELECTOR_ITEM = '.carousel-item';
  var SELECTOR_ITEM_IMG = '.carousel-item img';
  var SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
  var SELECTOR_INDICATORS = '.carousel-indicators';
XhmikosR's avatar
XhmikosR committed
218
219
  var SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]';
  var SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]';
XhmikosR's avatar
Dist    
XhmikosR committed
220
221
222
223
  var PointerType = {
    TOUCH: 'touch',
    PEN: 'pen'
  };
XhmikosR's avatar
XhmikosR committed
224
225
226
227
228
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
Dist    
XhmikosR committed
229

XhmikosR's avatar
XhmikosR committed
230
  var Carousel = /*#__PURE__*/function () {
XhmikosR's avatar
Dist    
XhmikosR committed
231
232
233
234
235
236
237
238
239
240
241
    function Carousel(element, config) {
      this._items = null;
      this._interval = null;
      this._activeElement = null;
      this._isPaused = false;
      this._isSliding = false;
      this.touchTimeout = null;
      this.touchStartX = 0;
      this.touchDeltaX = 0;
      this._config = this._getConfig(config);
      this._element = element;
XhmikosR's avatar
XhmikosR committed
242
      this._indicatorsElement = SelectorEngine__default['default'].findOne(SELECTOR_INDICATORS, this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
243
      this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
XhmikosR's avatar
XhmikosR committed
244
      this._pointerEvent = Boolean(window.PointerEvent);
XhmikosR's avatar
Dist    
XhmikosR committed
245
246

      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
247

XhmikosR's avatar
XhmikosR committed
248
      Data__default['default'].setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
249
250
251
252
253
254
255
256
    } // Getters


    var _proto = Carousel.prototype;

    // Public
    _proto.next = function next() {
      if (!this._isSliding) {
XhmikosR's avatar
XhmikosR committed
257
        this._slide(DIRECTION_NEXT);
XhmikosR's avatar
Dist    
XhmikosR committed
258
      }
Mark Otto's avatar
dist    
Mark Otto committed
259
    };
XhmikosR's avatar
Dist    
XhmikosR committed
260
261
262
263

    _proto.nextWhenVisible = function nextWhenVisible() {
      // Don't call next when the page isn't visible
      // or the carousel or its parent isn't visible
XhmikosR's avatar
XhmikosR committed
264
      if (!document.hidden && isVisible(this._element)) {
XhmikosR's avatar
Dist    
XhmikosR committed
265
266
        this.next();
      }
Mark Otto's avatar
dist    
Mark Otto committed
267
    };
XhmikosR's avatar
Dist    
XhmikosR committed
268
269
270

    _proto.prev = function prev() {
      if (!this._isSliding) {
XhmikosR's avatar
XhmikosR committed
271
        this._slide(DIRECTION_PREV);
XhmikosR's avatar
Dist    
XhmikosR committed
272
      }
Mark Otto's avatar
dist    
Mark Otto committed
273
    };
fat's avatar
fat committed
274

XhmikosR's avatar
Dist    
XhmikosR committed
275
276
277
278
279
    _proto.pause = function pause(event) {
      if (!event) {
        this._isPaused = true;
      }

XhmikosR's avatar
XhmikosR committed
280
      if (SelectorEngine__default['default'].findOne(SELECTOR_NEXT_PREV, this._element)) {
XhmikosR's avatar
XhmikosR committed
281
        triggerTransitionEnd(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
282
283
284
285
286
        this.cycle(true);
      }

      clearInterval(this._interval);
      this._interval = null;
Mark Otto's avatar
dist    
Mark Otto committed
287
    };
fat's avatar
fat committed
288

XhmikosR's avatar
Dist    
XhmikosR committed
289
290
    _proto.cycle = function cycle(event) {
      if (!event) {
Mark Otto's avatar
dist    
Mark Otto committed
291
        this._isPaused = false;
XhmikosR's avatar
Dist    
XhmikosR committed
292
      }
fat's avatar
fat committed
293

XhmikosR's avatar
Dist    
XhmikosR committed
294
295
296
297
      if (this._interval) {
        clearInterval(this._interval);
        this._interval = null;
      }
fat's avatar
fat committed
298

XhmikosR's avatar
XhmikosR committed
299
      if (this._config && this._config.interval && !this._isPaused) {
XhmikosR's avatar
XhmikosR committed
300
301
        this._updateInterval();

XhmikosR's avatar
Dist    
XhmikosR committed
302
303
304
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
305

XhmikosR's avatar
Dist    
XhmikosR committed
306
307
    _proto.to = function to(index) {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
308

XhmikosR's avatar
XhmikosR committed
309
      this._activeElement = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
Mark Otto's avatar
dist    
Mark Otto committed
310

XhmikosR's avatar
Dist    
XhmikosR committed
311
      var activeIndex = this._getItemIndex(this._activeElement);
fat's avatar
fat committed
312

XhmikosR's avatar
Dist    
XhmikosR committed
313
314
315
      if (index > this._items.length - 1 || index < 0) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
316

XhmikosR's avatar
Dist    
XhmikosR committed
317
      if (this._isSliding) {
XhmikosR's avatar
XhmikosR committed
318
        EventHandler__default['default'].one(this._element, EVENT_SLID, function () {
XhmikosR's avatar
Dist    
XhmikosR committed
319
320
321
322
          return _this.to(index);
        });
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
323

XhmikosR's avatar
Dist    
XhmikosR committed
324
325
326
327
328
      if (activeIndex === index) {
        this.pause();
        this.cycle();
        return;
      }
fat's avatar
fat committed
329

XhmikosR's avatar
XhmikosR committed
330
      var direction = index > activeIndex ? DIRECTION_NEXT : DIRECTION_PREV;
fat's avatar
fat committed
331

XhmikosR's avatar
Dist    
XhmikosR committed
332
333
      this._slide(direction, this._items[index]);
    };
Mark Otto's avatar
dist    
Mark Otto committed
334

XhmikosR's avatar
Dist    
XhmikosR committed
335
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
336
337
      EventHandler__default['default'].off(this._element, EVENT_KEY);
      Data__default['default'].removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
338
339
340
341
342
343
344
345
      this._items = null;
      this._config = null;
      this._element = null;
      this._interval = null;
      this._isPaused = null;
      this._isSliding = null;
      this._activeElement = null;
      this._indicatorsElement = null;
Mark Otto's avatar
Mark Otto committed
346
347
    } // Private
    ;
XhmikosR's avatar
Dist    
XhmikosR committed
348
349

    _proto._getConfig = function _getConfig(config) {
XhmikosR's avatar
XhmikosR committed
350
      config = _extends({}, Default, config);
XhmikosR's avatar
XhmikosR committed
351
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
352
353
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
354

XhmikosR's avatar
Dist    
XhmikosR committed
355
356
    _proto._handleSwipe = function _handleSwipe() {
      var absDeltax = Math.abs(this.touchDeltaX);
Mark Otto's avatar
dist    
Mark Otto committed
357

XhmikosR's avatar
Dist    
XhmikosR committed
358
359
360
      if (absDeltax <= SWIPE_THRESHOLD) {
        return;
      }
fat's avatar
fat committed
361

XhmikosR's avatar
XhmikosR committed
362
363
      var direction = absDeltax / this.touchDeltaX;
      this.touchDeltaX = 0; // swipe left
fat's avatar
fat committed
364

XhmikosR's avatar
Dist    
XhmikosR committed
365
366
367
      if (direction > 0) {
        this.prev();
      } // swipe right
fat's avatar
fat committed
368
369


XhmikosR's avatar
Dist    
XhmikosR committed
370
371
372
373
      if (direction < 0) {
        this.next();
      }
    };
fat's avatar
fat committed
374

XhmikosR's avatar
Dist    
XhmikosR committed
375
376
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
fat's avatar
fat committed
377

XhmikosR's avatar
Dist    
XhmikosR committed
378
      if (this._config.keyboard) {
XhmikosR's avatar
XhmikosR committed
379
        EventHandler__default['default'].on(this._element, EVENT_KEYDOWN, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
380
381
382
          return _this2._keydown(event);
        });
      }
Mark Otto's avatar
grunt    
Mark Otto committed
383

XhmikosR's avatar
Dist    
XhmikosR committed
384
      if (this._config.pause === 'hover') {
XhmikosR's avatar
XhmikosR committed
385
        EventHandler__default['default'].on(this._element, EVENT_MOUSEENTER, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
386
          return _this2.pause(event);
XhmikosR's avatar
XhmikosR committed
387
        });
XhmikosR's avatar
XhmikosR committed
388
        EventHandler__default['default'].on(this._element, EVENT_MOUSELEAVE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
389
390
391
          return _this2.cycle(event);
        });
      }
fat's avatar
fat committed
392

393
      if (this._config.touch && this._touchSupported) {
Mark Otto's avatar
Mark Otto committed
394
395
        this._addTouchEventListeners();
      }
XhmikosR's avatar
Dist    
XhmikosR committed
396
    };
Mark Otto's avatar
dist    
Mark Otto committed
397

XhmikosR's avatar
Dist    
XhmikosR committed
398
399
    _proto._addTouchEventListeners = function _addTouchEventListeners() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
400

XhmikosR's avatar
Dist    
XhmikosR committed
401
      var start = function start(event) {
XhmikosR's avatar
XhmikosR committed
402
403
        if (_this3._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
          _this3.touchStartX = event.clientX;
XhmikosR's avatar
Dist    
XhmikosR committed
404
        } else if (!_this3._pointerEvent) {
XhmikosR's avatar
XhmikosR committed
405
          _this3.touchStartX = event.touches[0].clientX;
Mark Otto's avatar
dist    
Mark Otto committed
406
        }
XhmikosR's avatar
Dist    
XhmikosR committed
407
      };
Mark Otto's avatar
dist    
Mark Otto committed
408

XhmikosR's avatar
Dist    
XhmikosR committed
409
410
      var move = function move(event) {
        // ensure swiping with one touch and not pinching
XhmikosR's avatar
XhmikosR committed
411
        if (event.touches && event.touches.length > 1) {
XhmikosR's avatar
Dist    
XhmikosR committed
412
413
          _this3.touchDeltaX = 0;
        } else {
XhmikosR's avatar
XhmikosR committed
414
          _this3.touchDeltaX = event.touches[0].clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
415
416
        }
      };
fat's avatar
fat committed
417

XhmikosR's avatar
Dist    
XhmikosR committed
418
      var end = function end(event) {
XhmikosR's avatar
XhmikosR committed
419
420
        if (_this3._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
          _this3.touchDeltaX = event.clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
421
        }
Mark Otto's avatar
dist    
Mark Otto committed
422

XhmikosR's avatar
Dist    
XhmikosR committed
423
424
425
426
427
428
429
430
431
432
433
        _this3._handleSwipe();

        if (_this3._config.pause === 'hover') {
          // If it's a touch-enabled device, mouseenter/leave are fired as
          // part of the mouse compatibility events on first tap - the carousel
          // would stop cycling until user tapped out of it;
          // here, we listen for touchend, explicitly pause the carousel
          // (as if it's the second time we tap on it, mouseenter compat event
          // is NOT fired) and after a timeout (to allow for mouse compatibility
          // events to fire) we explicitly restart cycling
          _this3.pause();
fat's avatar
fat committed
434

XhmikosR's avatar
Dist    
XhmikosR committed
435
436
437
          if (_this3.touchTimeout) {
            clearTimeout(_this3.touchTimeout);
          }
fat's avatar
fat committed
438

XhmikosR's avatar
Dist    
XhmikosR committed
439
440
441
          _this3.touchTimeout = setTimeout(function (event) {
            return _this3.cycle(event);
          }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval);
Mark Otto's avatar
dist    
Mark Otto committed
442
443
        }
      };
Mark Otto's avatar
grunt    
Mark Otto committed
444

XhmikosR's avatar
XhmikosR committed
445
446
      SelectorEngine__default['default'].find(SELECTOR_ITEM_IMG, this._element).forEach(function (itemImg) {
        EventHandler__default['default'].on(itemImg, EVENT_DRAG_START, function (e) {
XhmikosR's avatar
XhmikosR committed
447
448
          return e.preventDefault();
        });
XhmikosR's avatar
Dist    
XhmikosR committed
449
      });
Mark Otto's avatar
grunt    
Mark Otto committed
450

XhmikosR's avatar
Dist    
XhmikosR committed
451
      if (this._pointerEvent) {
XhmikosR's avatar
XhmikosR committed
452
        EventHandler__default['default'].on(this._element, EVENT_POINTERDOWN, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
453
454
          return start(event);
        });
XhmikosR's avatar
XhmikosR committed
455
        EventHandler__default['default'].on(this._element, EVENT_POINTERUP, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
456
457
          return end(event);
        });
Mark Otto's avatar
dist    
Mark Otto committed
458

XhmikosR's avatar
XhmikosR committed
459
        this._element.classList.add(CLASS_NAME_POINTER_EVENT);
XhmikosR's avatar
Dist    
XhmikosR committed
460
      } else {
XhmikosR's avatar
XhmikosR committed
461
        EventHandler__default['default'].on(this._element, EVENT_TOUCHSTART, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
462
463
          return start(event);
        });
XhmikosR's avatar
XhmikosR committed
464
        EventHandler__default['default'].on(this._element, EVENT_TOUCHMOVE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
465
466
          return move(event);
        });
XhmikosR's avatar
XhmikosR committed
467
        EventHandler__default['default'].on(this._element, EVENT_TOUCHEND, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
468
469
470
471
          return end(event);
        });
      }
    };
fat's avatar
fat committed
472

XhmikosR's avatar
Dist    
XhmikosR committed
473
474
475
476
    _proto._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
      }
fat's avatar
fat committed
477

XhmikosR's avatar
XhmikosR committed
478
479
      switch (event.key) {
        case ARROW_LEFT_KEY:
XhmikosR's avatar
Dist    
XhmikosR committed
480
481
482
          event.preventDefault();
          this.prev();
          break;
fat's avatar
fat committed
483

XhmikosR's avatar
XhmikosR committed
484
        case ARROW_RIGHT_KEY:
XhmikosR's avatar
Dist    
XhmikosR committed
485
486
487
488
489
          event.preventDefault();
          this.next();
          break;
      }
    };
fat's avatar
fat committed
490

XhmikosR's avatar
Dist    
XhmikosR committed
491
    _proto._getItemIndex = function _getItemIndex(element) {
XhmikosR's avatar
XhmikosR committed
492
      this._items = element && element.parentNode ? SelectorEngine__default['default'].find(SELECTOR_ITEM, element.parentNode) : [];
XhmikosR's avatar
Dist    
XhmikosR committed
493
494
      return this._items.indexOf(element);
    };
fat's avatar
fat committed
495

XhmikosR's avatar
Dist    
XhmikosR committed
496
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
XhmikosR's avatar
XhmikosR committed
497
498
      var isNextDirection = direction === DIRECTION_NEXT;
      var isPrevDirection = direction === DIRECTION_PREV;
Mark Otto's avatar
dist    
Mark Otto committed
499

XhmikosR's avatar
Dist    
XhmikosR committed
500
      var activeIndex = this._getItemIndex(activeElement);
fat's avatar
fat committed
501

XhmikosR's avatar
Dist    
XhmikosR committed
502
503
      var lastItemIndex = this._items.length - 1;
      var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
Mark Otto's avatar
dist    
Mark Otto committed
504

XhmikosR's avatar
Dist    
XhmikosR committed
505
506
507
      if (isGoingToWrap && !this._config.wrap) {
        return activeElement;
      }
fat's avatar
fat committed
508

XhmikosR's avatar
XhmikosR committed
509
      var delta = direction === DIRECTION_PREV ? -1 : 1;
XhmikosR's avatar
Dist    
XhmikosR committed
510
511
512
      var itemIndex = (activeIndex + delta) % this._items.length;
      return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
    };
fat's avatar
fat committed
513

XhmikosR's avatar
Dist    
XhmikosR committed
514
515
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
      var targetIndex = this._getItemIndex(relatedTarget);
fat's avatar
fat committed
516

XhmikosR's avatar
XhmikosR committed
517
      var fromIndex = this._getItemIndex(SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element));
fat's avatar
fat committed
518

XhmikosR's avatar
XhmikosR committed
519
      return EventHandler__default['default'].trigger(this._element, EVENT_SLIDE, {
XhmikosR's avatar
Dist    
XhmikosR committed
520
521
522
523
524
525
        relatedTarget: relatedTarget,
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
      });
    };
fat's avatar
fat committed
526

XhmikosR's avatar
Dist    
XhmikosR committed
527
528
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
XhmikosR's avatar
XhmikosR committed
529
        var indicators = SelectorEngine__default['default'].find(SELECTOR_ACTIVE, this._indicatorsElement);
XhmikosR's avatar
XhmikosR committed
530
531

        for (var i = 0; i < indicators.length; i++) {
XhmikosR's avatar
XhmikosR committed
532
          indicators[i].classList.remove(CLASS_NAME_ACTIVE);
XhmikosR's avatar
XhmikosR committed
533
        }
fat's avatar
fat committed
534

XhmikosR's avatar
Dist    
XhmikosR committed
535
        var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
fat's avatar
fat committed
536

XhmikosR's avatar
Dist    
XhmikosR committed
537
        if (nextIndicator) {
XhmikosR's avatar
XhmikosR committed
538
          nextIndicator.classList.add(CLASS_NAME_ACTIVE);
Mark Otto's avatar
dist    
Mark Otto committed
539
        }
XhmikosR's avatar
Dist    
XhmikosR committed
540
541
      }
    };
fat's avatar
fat committed
542

XhmikosR's avatar
XhmikosR committed
543
544
545
546
547
548
549
    _proto._updateInterval = function _updateInterval() {
      var element = this._activeElement || SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);

      if (!element) {
        return;
      }

XhmikosR's avatar
XhmikosR committed
550
      var elementInterval = Number.parseInt(element.getAttribute('data-bs-interval'), 10);
XhmikosR's avatar
XhmikosR committed
551
552
553
554
555
556
557
558
559

      if (elementInterval) {
        this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
        this._config.interval = elementInterval;
      } else {
        this._config.interval = this._config.defaultInterval || this._config.interval;
      }
    };

XhmikosR's avatar
Dist    
XhmikosR committed
560
561
    _proto._slide = function _slide(direction, element) {
      var _this4 = this;
fat's avatar
fat committed
562

XhmikosR's avatar
XhmikosR committed
563
      var activeElement = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
fat's avatar
fat committed
564

XhmikosR's avatar
Dist    
XhmikosR committed
565
      var activeElementIndex = this._getItemIndex(activeElement);
fat's avatar
fat committed
566

XhmikosR's avatar
Dist    
XhmikosR committed
567
      var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
fat's avatar
fat committed
568

XhmikosR's avatar
Dist    
XhmikosR committed
569
      var nextElementIndex = this._getItemIndex(nextElement);
fat's avatar
fat committed
570

XhmikosR's avatar
Dist    
XhmikosR committed
571
572
573
574
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
575

XhmikosR's avatar
XhmikosR committed
576
577
578
579
      if (direction === DIRECTION_NEXT) {
        directionalClassName = CLASS_NAME_LEFT;
        orderClassName = CLASS_NAME_NEXT;
        eventDirectionName = DIRECTION_LEFT;
XhmikosR's avatar
Dist    
XhmikosR committed
580
      } else {
XhmikosR's avatar
XhmikosR committed
581
582
583
        directionalClassName = CLASS_NAME_RIGHT;
        orderClassName = CLASS_NAME_PREV;
        eventDirectionName = DIRECTION_RIGHT;
XhmikosR's avatar
Dist    
XhmikosR committed
584
      }
Mark Otto's avatar
dist    
Mark Otto committed
585

XhmikosR's avatar
XhmikosR committed
586
      if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
587
588
589
        this._isSliding = false;
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
590

XhmikosR's avatar
Dist    
XhmikosR committed
591
      var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
Mark Otto's avatar
dist    
Mark Otto committed
592

XhmikosR's avatar
XhmikosR committed
593
      if (slideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
594
595
        return;
      }
fat's avatar
fat committed
596

XhmikosR's avatar
Dist    
XhmikosR committed
597
598
599
600
      if (!activeElement || !nextElement) {
        // Some weirdness is happening, so we bail
        return;
      }
fat's avatar
fat committed
601

XhmikosR's avatar
Dist    
XhmikosR committed
602
      this._isSliding = true;
Mark Otto's avatar
Mark Otto committed
603

XhmikosR's avatar
Dist    
XhmikosR committed
604
605
606
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
607

XhmikosR's avatar
Dist    
XhmikosR committed
608
      this._setActiveIndicatorElement(nextElement);
Mark Otto's avatar
dist    
Mark Otto committed
609

XhmikosR's avatar
XhmikosR committed
610
611
      this._activeElement = nextElement;

XhmikosR's avatar
XhmikosR committed
612
      if (this._element.classList.contains(CLASS_NAME_SLIDE)) {
XhmikosR's avatar
XhmikosR committed
613
614
615
616
617
        nextElement.classList.add(orderClassName);
        reflow(nextElement);
        activeElement.classList.add(directionalClassName);
        nextElement.classList.add(directionalClassName);
        var transitionDuration = getTransitionDurationFromElement(activeElement);
XhmikosR's avatar
XhmikosR committed
618
        EventHandler__default['default'].one(activeElement, TRANSITION_END, function () {
XhmikosR's avatar
XhmikosR committed
619
          nextElement.classList.remove(directionalClassName, orderClassName);
XhmikosR's avatar
XhmikosR committed
620
          nextElement.classList.add(CLASS_NAME_ACTIVE);
XhmikosR's avatar
XhmikosR committed
621
          activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName);
XhmikosR's avatar
Dist    
XhmikosR committed
622
623
          _this4._isSliding = false;
          setTimeout(function () {
XhmikosR's avatar
XhmikosR committed
624
            EventHandler__default['default'].trigger(_this4._element, EVENT_SLID, {
XhmikosR's avatar
XhmikosR committed
625
626
627
628
629
              relatedTarget: nextElement,
              direction: eventDirectionName,
              from: activeElementIndex,
              to: nextElementIndex
            });
XhmikosR's avatar
Dist    
XhmikosR committed
630
          }, 0);
XhmikosR's avatar
XhmikosR committed
631
632
        });
        emulateTransitionEnd(activeElement, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
633
      } else {
XhmikosR's avatar
XhmikosR committed
634
635
        activeElement.classList.remove(CLASS_NAME_ACTIVE);
        nextElement.classList.add(CLASS_NAME_ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
636
        this._isSliding = false;
XhmikosR's avatar
XhmikosR committed
637
        EventHandler__default['default'].trigger(this._element, EVENT_SLID, {
XhmikosR's avatar
XhmikosR committed
638
639
640
641
642
          relatedTarget: nextElement,
          direction: eventDirectionName,
          from: activeElementIndex,
          to: nextElementIndex
        });
XhmikosR's avatar
Dist    
XhmikosR committed
643
      }
Mark Otto's avatar
dist    
Mark Otto committed
644

XhmikosR's avatar
Dist    
XhmikosR committed
645
646
647
      if (isCycling) {
        this.cycle();
      }
Mark Otto's avatar
Mark Otto committed
648
649
    } // Static
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
650

XhmikosR's avatar
XhmikosR committed
651
    Carousel.carouselInterface = function carouselInterface(element, config) {
XhmikosR's avatar
XhmikosR committed
652
      var data = Data__default['default'].getData(element, DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
653

XhmikosR's avatar
XhmikosR committed
654
      var _config = _extends({}, Default, Manipulator__default['default'].getDataAttributes(element));
Mark Otto's avatar
dist    
Mark Otto committed
655

XhmikosR's avatar
XhmikosR committed
656
      if (typeof config === 'object') {
XhmikosR's avatar
XhmikosR committed
657
        _config = _extends({}, _config, config);
XhmikosR's avatar
XhmikosR committed
658
      }
Mark Otto's avatar
dist    
Mark Otto committed
659

XhmikosR's avatar
XhmikosR committed
660
      var action = typeof config === 'string' ? config : _config.slide;
Mark Otto's avatar
dist    
Mark Otto committed
661

XhmikosR's avatar
XhmikosR committed
662
663
664
665
666
667
668
669
      if (!data) {
        data = new Carousel(element, _config);
      }

      if (typeof config === 'number') {
        data.to(config);
      } else if (typeof action === 'string') {
        if (typeof data[action] === 'undefined') {
XhmikosR's avatar
Dist.    
XhmikosR committed
670
          throw new TypeError("No method named \"" + action + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
671
        }
Mark Otto's avatar
dist    
Mark Otto committed
672

XhmikosR's avatar
XhmikosR committed
673
674
675
676
677
678
        data[action]();
      } else if (_config.interval && _config.ride) {
        data.pause();
        data.cycle();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
679

XhmikosR's avatar
XhmikosR committed
680
    Carousel.jQueryInterface = function jQueryInterface(config) {
XhmikosR's avatar
XhmikosR committed
681
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
682
        Carousel.carouselInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
683
684
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
685

XhmikosR's avatar
XhmikosR committed
686
687
    Carousel.dataApiClickHandler = function dataApiClickHandler(event) {
      var target = getElementFromSelector(this);
fat's avatar
fat committed
688

XhmikosR's avatar
XhmikosR committed
689
      if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
XhmikosR's avatar
Dist    
XhmikosR committed
690
691
        return;
      }
fat's avatar
fat committed
692

XhmikosR's avatar
XhmikosR committed
693
      var config = _extends({}, Manipulator__default['default'].getDataAttributes(target), Manipulator__default['default'].getDataAttributes(this));
fat's avatar
fat committed
694

XhmikosR's avatar
XhmikosR committed
695
      var slideIndex = this.getAttribute('data-bs-slide-to');
Mark Otto's avatar
dist    
Mark Otto committed
696

XhmikosR's avatar
Dist    
XhmikosR committed
697
698
      if (slideIndex) {
        config.interval = false;
Mark Otto's avatar
dist    
Mark Otto committed
699
      }
Mark Otto's avatar
dist    
Mark Otto committed
700

XhmikosR's avatar
XhmikosR committed
701
      Carousel.carouselInterface(target, config);
XhmikosR's avatar
Dist    
XhmikosR committed
702
703

      if (slideIndex) {
XhmikosR's avatar
XhmikosR committed
704
        Data__default['default'].getData(target, DATA_KEY).to(slideIndex);
XhmikosR's avatar
Dist    
XhmikosR committed
705
      }
fat's avatar
fat committed
706

XhmikosR's avatar
Dist    
XhmikosR committed
707
      event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
708
    };
Mark Otto's avatar
dist    
Mark Otto committed
709

XhmikosR's avatar
XhmikosR committed
710
    Carousel.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
711
      return Data__default['default'].getData(element, DATA_KEY);
XhmikosR's avatar
XhmikosR committed
712
713
    };

XhmikosR's avatar
Dist    
XhmikosR committed
714
715
716
717
718
719
720
721
722
723
724
725
    _createClass(Carousel, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);

Mark Otto's avatar
dist    
Mark Otto committed
726
    return Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
727
728
729
730
731
732
733
734
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
735
736
737
  EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler);
  EventHandler__default['default'].on(window, EVENT_LOAD_DATA_API, function () {
    var carousels = SelectorEngine__default['default'].find(SELECTOR_DATA_RIDE);
XhmikosR's avatar
Dist    
XhmikosR committed
738
739

    for (var i = 0, len = carousels.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
740
      Carousel.carouselInterface(carousels[i], Data__default['default'].getData(carousels[i], DATA_KEY));
XhmikosR's avatar
Dist    
XhmikosR committed
741
742
743
744
745
746
    }
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
747
   * add .Carousel to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
748
749
   */

XhmikosR's avatar
XhmikosR committed
750
751
752
  onDOMContentLoaded(function () {
    var $ = getjQuery();
    /* istanbul ignore if */
753

XhmikosR's avatar
XhmikosR committed
754
755
756
757
    if ($) {
      var JQUERY_NO_CONFLICT = $.fn[NAME];
      $.fn[NAME] = Carousel.jQueryInterface;
      $.fn[NAME].Constructor = Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
758

XhmikosR's avatar
XhmikosR committed
759
760
761
762
763
764
      $.fn[NAME].noConflict = function () {
        $.fn[NAME] = JQUERY_NO_CONFLICT;
        return Carousel.jQueryInterface;
      };
    }
  });
fat's avatar
fat committed
765
766

  return Carousel;
Mark Otto's avatar
dist    
Mark Otto committed
767

XhmikosR's avatar
XhmikosR committed
768
})));
Mark Otto's avatar
dist    
Mark Otto committed
769
//# sourceMappingURL=carousel.js.map