carousel.js 25.4 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap carousel.js v4.3.1 (https://getbootstrap.com/)
Mark Otto's avatar
Mark Otto committed
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
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
10
  (global = global || self, global.Carousel = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
}(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
  Data = Data && Data.hasOwnProperty('default') ? Data['default'] : Data;
  EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Manipulator.hasOwnProperty('default') ? Manipulator['default'] : Manipulator;
  SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

  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;
  }

  function _defineProperty(obj, key, value) {
    if (key in obj) {
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
      });
    } else {
      obj[key] = value;
    }
Mark Otto's avatar
dist    
Mark Otto committed
44

Mark Otto's avatar
dist    
Mark Otto committed
45
46
    return obj;
  }
Mark Otto's avatar
dist    
Mark Otto committed
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);

    if (Object.getOwnPropertySymbols) {
      var symbols = Object.getOwnPropertySymbols(object);
      if (enumerableOnly) symbols = symbols.filter(function (sym) {
        return Object.getOwnPropertyDescriptor(object, sym).enumerable;
      });
      keys.push.apply(keys, symbols);
    }

    return keys;
  }

  function _objectSpread2(target) {
Mark Otto's avatar
dist    
Mark Otto committed
63
64
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
Mark Otto's avatar
dist    
Mark Otto committed
65

66
67
68
69
70
71
72
73
74
75
      if (i % 2) {
        ownKeys(source, true).forEach(function (key) {
          _defineProperty(target, key, source[key]);
        });
      } else if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
      } else {
        ownKeys(source).forEach(function (key) {
          Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
Mark Otto's avatar
dist    
Mark Otto committed
76
77
78
79
80
      }
    }

    return target;
  }
fat's avatar
fat committed
81

XhmikosR's avatar
XhmikosR committed
82
83
84
85
86
87
88
89
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.3.1): util/index.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
  var TRANSITION_END = 'transitionend';
XhmikosR's avatar
Dist.    
XhmikosR committed
90
91
  var _window = window,
      jQuery = _window.jQuery; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

  var toType = function toType(obj) {
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

  var getSelectorFromElement = function getSelectorFromElement(element) {
    var selector = element.getAttribute('data-target');

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
    }

    try {
      return document.querySelector(selector) ? selector : null;
XhmikosR's avatar
Dist.    
XhmikosR committed
107
    } catch (error) {
XhmikosR's avatar
XhmikosR committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
      return null;
    }
  };

  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;

    var floatTransitionDuration = parseFloat(transitionDuration);
    var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found

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


    transitionDuration = transitionDuration.split(',')[0];
    transitionDelay = transitionDelay.split(',')[0];
    return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  };

  var triggerTransitionEnd = function triggerTransitionEnd(element) {
XhmikosR's avatar
XhmikosR committed
136
137
138
    var evt = document.createEvent('HTMLEvents');
    evt.initEvent(TRANSITION_END, true, true);
    element.dispatchEvent(evt);
XhmikosR's avatar
XhmikosR committed
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
  };

  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 makeArray = function makeArray(nodeList) {
    if (!nodeList) {
      return [];
    }

    return [].slice.call(nodeList);
  };

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

    if (element.style && element.parentNode && element.parentNode.style) {
      return element.style.display !== 'none' && element.parentNode.style.display !== 'none' && element.style.visibility !== 'hidden';
    }

    return false;
  };

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

fat's avatar
fat committed
199
  /**
XhmikosR's avatar
Dist    
XhmikosR committed
200
201
202
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
fat's avatar
fat committed
203
   */
Mark Otto's avatar
dist    
Mark Otto committed
204

XhmikosR's avatar
Dist    
XhmikosR committed
205
  var NAME = 'carousel';
XhmikosR's avatar
XhmikosR committed
206
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
  var DATA_KEY = 'bs.carousel';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key

  var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key

  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'
  };
  var Direction = {
    NEXT: 'next',
    PREV: 'prev',
    LEFT: 'left',
    RIGHT: 'right'
  };
XhmikosR's avatar
XhmikosR committed
239
  var Event = {
XhmikosR's avatar
Dist    
XhmikosR committed
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    SLIDE: "slide" + EVENT_KEY,
    SLID: "slid" + EVENT_KEY,
    KEYDOWN: "keydown" + EVENT_KEY,
    MOUSEENTER: "mouseenter" + EVENT_KEY,
    MOUSELEAVE: "mouseleave" + EVENT_KEY,
    TOUCHSTART: "touchstart" + EVENT_KEY,
    TOUCHMOVE: "touchmove" + EVENT_KEY,
    TOUCHEND: "touchend" + EVENT_KEY,
    POINTERDOWN: "pointerdown" + EVENT_KEY,
    POINTERUP: "pointerup" + EVENT_KEY,
    DRAG_START: "dragstart" + EVENT_KEY,
    LOAD_DATA_API: "load" + EVENT_KEY + DATA_API_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
  };
  var ClassName = {
    CAROUSEL: 'carousel',
    ACTIVE: 'active',
    SLIDE: 'slide',
    RIGHT: 'carousel-item-right',
    LEFT: 'carousel-item-left',
    NEXT: 'carousel-item-next',
    PREV: 'carousel-item-prev',
    ITEM: 'carousel-item',
    POINTER_EVENT: 'pointer-event'
  };
  var Selector = {
    ACTIVE: '.active',
    ACTIVE_ITEM: '.active.carousel-item',
    ITEM: '.carousel-item',
    ITEM_IMG: '.carousel-item img',
    NEXT_PREV: '.carousel-item-next, .carousel-item-prev',
    INDICATORS: '.carousel-indicators',
    DATA_SLIDE: '[data-slide], [data-slide-to]',
    DATA_RIDE: '[data-ride="carousel"]'
  };
  var PointerType = {
    TOUCH: 'touch',
    PEN: 'pen'
Mark Otto's avatar
dist    
Mark Otto committed
278
279
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
280
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
281
282
     * ------------------------------------------------------------------------
     */
XhmikosR's avatar
Dist    
XhmikosR committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299

  };

  var Carousel =
  /*#__PURE__*/
  function () {
    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
300
      this._indicatorsElement = SelectorEngine.findOne(Selector.INDICATORS, this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
301
302
303
304
      this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
      this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent);

      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
305
306

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
307
308
309
310
311
312
313
314
315
316
    } // Getters


    var _proto = Carousel.prototype;

    // Public
    _proto.next = function next() {
      if (!this._isSliding) {
        this._slide(Direction.NEXT);
      }
Mark Otto's avatar
dist    
Mark Otto committed
317
    };
XhmikosR's avatar
Dist    
XhmikosR committed
318
319
320
321

    _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
322
      if (!document.hidden && isVisible(this._element)) {
XhmikosR's avatar
Dist    
XhmikosR committed
323
324
        this.next();
      }
Mark Otto's avatar
dist    
Mark Otto committed
325
    };
XhmikosR's avatar
Dist    
XhmikosR committed
326
327
328
329
330

    _proto.prev = function prev() {
      if (!this._isSliding) {
        this._slide(Direction.PREV);
      }
Mark Otto's avatar
dist    
Mark Otto committed
331
    };
fat's avatar
fat committed
332

XhmikosR's avatar
Dist    
XhmikosR committed
333
334
335
336
337
    _proto.pause = function pause(event) {
      if (!event) {
        this._isPaused = true;
      }

XhmikosR's avatar
XhmikosR committed
338
339
      if (SelectorEngine.findOne(Selector.NEXT_PREV, this._element)) {
        triggerTransitionEnd(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
340
341
342
343
344
        this.cycle(true);
      }

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

XhmikosR's avatar
Dist    
XhmikosR committed
347
348
    _proto.cycle = function cycle(event) {
      if (!event) {
Mark Otto's avatar
dist    
Mark Otto committed
349
        this._isPaused = false;
XhmikosR's avatar
Dist    
XhmikosR committed
350
      }
fat's avatar
fat committed
351

XhmikosR's avatar
Dist    
XhmikosR committed
352
353
354
355
      if (this._interval) {
        clearInterval(this._interval);
        this._interval = null;
      }
fat's avatar
fat committed
356

XhmikosR's avatar
XhmikosR committed
357
      if (this._config && this._config.interval && !this._isPaused) {
XhmikosR's avatar
Dist    
XhmikosR committed
358
359
360
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
361

XhmikosR's avatar
Dist    
XhmikosR committed
362
363
    _proto.to = function to(index) {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
364

XhmikosR's avatar
XhmikosR committed
365
      this._activeElement = SelectorEngine.findOne(Selector.ACTIVE_ITEM, this._element);
Mark Otto's avatar
dist    
Mark Otto committed
366

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

XhmikosR's avatar
Dist    
XhmikosR committed
369
370
371
      if (index > this._items.length - 1 || index < 0) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
372

XhmikosR's avatar
Dist    
XhmikosR committed
373
      if (this._isSliding) {
XhmikosR's avatar
XhmikosR committed
374
        EventHandler.one(this._element, Event.SLID, function () {
XhmikosR's avatar
Dist    
XhmikosR committed
375
376
377
378
          return _this.to(index);
        });
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
379

XhmikosR's avatar
Dist    
XhmikosR committed
380
381
382
383
384
      if (activeIndex === index) {
        this.pause();
        this.cycle();
        return;
      }
fat's avatar
fat committed
385

XhmikosR's avatar
Dist    
XhmikosR committed
386
      var direction = index > activeIndex ? Direction.NEXT : Direction.PREV;
fat's avatar
fat committed
387

XhmikosR's avatar
Dist    
XhmikosR committed
388
389
      this._slide(direction, this._items[index]);
    };
Mark Otto's avatar
dist    
Mark Otto committed
390

XhmikosR's avatar
Dist    
XhmikosR committed
391
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
392
393
      EventHandler.off(this._element, EVENT_KEY);
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
394
395
396
397
398
399
400
401
      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
402
403
    } // Private
    ;
XhmikosR's avatar
Dist    
XhmikosR committed
404
405

    _proto._getConfig = function _getConfig(config) {
406
      config = _objectSpread2({}, Default, {}, config);
XhmikosR's avatar
XhmikosR committed
407
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
408
409
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
410

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

XhmikosR's avatar
Dist    
XhmikosR committed
414
415
416
      if (absDeltax <= SWIPE_THRESHOLD) {
        return;
      }
fat's avatar
fat committed
417

XhmikosR's avatar
XhmikosR committed
418
419
      var direction = absDeltax / this.touchDeltaX;
      this.touchDeltaX = 0; // swipe left
fat's avatar
fat committed
420

XhmikosR's avatar
Dist    
XhmikosR committed
421
422
423
      if (direction > 0) {
        this.prev();
      } // swipe right
fat's avatar
fat committed
424
425


XhmikosR's avatar
Dist    
XhmikosR committed
426
427
428
429
      if (direction < 0) {
        this.next();
      }
    };
fat's avatar
fat committed
430

XhmikosR's avatar
Dist    
XhmikosR committed
431
432
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
fat's avatar
fat committed
433

XhmikosR's avatar
Dist    
XhmikosR committed
434
      if (this._config.keyboard) {
XhmikosR's avatar
XhmikosR committed
435
        EventHandler.on(this._element, Event.KEYDOWN, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
436
437
438
          return _this2._keydown(event);
        });
      }
Mark Otto's avatar
grunt    
Mark Otto committed
439

XhmikosR's avatar
Dist    
XhmikosR committed
440
      if (this._config.pause === 'hover') {
XhmikosR's avatar
XhmikosR committed
441
        EventHandler.on(this._element, Event.MOUSEENTER, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
442
          return _this2.pause(event);
XhmikosR's avatar
XhmikosR committed
443
        });
XhmikosR's avatar
XhmikosR committed
444
        EventHandler.on(this._element, Event.MOUSELEAVE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
445
446
447
          return _this2.cycle(event);
        });
      }
fat's avatar
fat committed
448

449
      if (this._config.touch && this._touchSupported) {
Mark Otto's avatar
Mark Otto committed
450
451
        this._addTouchEventListeners();
      }
XhmikosR's avatar
Dist    
XhmikosR committed
452
    };
Mark Otto's avatar
dist    
Mark Otto committed
453

XhmikosR's avatar
Dist    
XhmikosR committed
454
455
    _proto._addTouchEventListeners = function _addTouchEventListeners() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
456

XhmikosR's avatar
Dist    
XhmikosR committed
457
      var start = function start(event) {
XhmikosR's avatar
XhmikosR committed
458
459
        if (_this3._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
          _this3.touchStartX = event.clientX;
XhmikosR's avatar
Dist    
XhmikosR committed
460
        } else if (!_this3._pointerEvent) {
XhmikosR's avatar
XhmikosR committed
461
          _this3.touchStartX = event.touches[0].clientX;
Mark Otto's avatar
dist    
Mark Otto committed
462
        }
XhmikosR's avatar
Dist    
XhmikosR committed
463
      };
Mark Otto's avatar
dist    
Mark Otto committed
464

XhmikosR's avatar
Dist    
XhmikosR committed
465
466
      var move = function move(event) {
        // ensure swiping with one touch and not pinching
XhmikosR's avatar
XhmikosR committed
467
        if (event.touches && event.touches.length > 1) {
XhmikosR's avatar
Dist    
XhmikosR committed
468
469
          _this3.touchDeltaX = 0;
        } else {
XhmikosR's avatar
XhmikosR committed
470
          _this3.touchDeltaX = event.touches[0].clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
471
472
        }
      };
fat's avatar
fat committed
473

XhmikosR's avatar
Dist    
XhmikosR committed
474
      var end = function end(event) {
XhmikosR's avatar
XhmikosR committed
475
476
        if (_this3._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
          _this3.touchDeltaX = event.clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
477
        }
Mark Otto's avatar
dist    
Mark Otto committed
478

XhmikosR's avatar
Dist    
XhmikosR committed
479
480
481
482
483
484
485
486
487
488
489
        _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
490

XhmikosR's avatar
Dist    
XhmikosR committed
491
492
493
          if (_this3.touchTimeout) {
            clearTimeout(_this3.touchTimeout);
          }
fat's avatar
fat committed
494

XhmikosR's avatar
Dist    
XhmikosR committed
495
496
497
          _this3.touchTimeout = setTimeout(function (event) {
            return _this3.cycle(event);
          }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval);
Mark Otto's avatar
dist    
Mark Otto committed
498
499
        }
      };
Mark Otto's avatar
grunt    
Mark Otto committed
500

XhmikosR's avatar
XhmikosR committed
501
      makeArray(SelectorEngine.find(Selector.ITEM_IMG, this._element)).forEach(function (itemImg) {
XhmikosR's avatar
XhmikosR committed
502
        EventHandler.on(itemImg, Event.DRAG_START, function (e) {
XhmikosR's avatar
XhmikosR committed
503
504
          return e.preventDefault();
        });
XhmikosR's avatar
Dist    
XhmikosR committed
505
      });
Mark Otto's avatar
grunt    
Mark Otto committed
506

XhmikosR's avatar
Dist    
XhmikosR committed
507
      if (this._pointerEvent) {
XhmikosR's avatar
XhmikosR committed
508
        EventHandler.on(this._element, Event.POINTERDOWN, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
509
510
          return start(event);
        });
XhmikosR's avatar
XhmikosR committed
511
        EventHandler.on(this._element, Event.POINTERUP, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
512
513
          return end(event);
        });
Mark Otto's avatar
dist    
Mark Otto committed
514

XhmikosR's avatar
Dist    
XhmikosR committed
515
516
        this._element.classList.add(ClassName.POINTER_EVENT);
      } else {
XhmikosR's avatar
XhmikosR committed
517
        EventHandler.on(this._element, Event.TOUCHSTART, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
518
519
          return start(event);
        });
XhmikosR's avatar
XhmikosR committed
520
        EventHandler.on(this._element, Event.TOUCHMOVE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
521
522
          return move(event);
        });
XhmikosR's avatar
XhmikosR committed
523
        EventHandler.on(this._element, Event.TOUCHEND, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
524
525
526
527
          return end(event);
        });
      }
    };
fat's avatar
fat committed
528

XhmikosR's avatar
Dist    
XhmikosR committed
529
530
531
532
    _proto._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
      }
fat's avatar
fat committed
533

XhmikosR's avatar
Dist    
XhmikosR committed
534
535
536
537
538
      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
          event.preventDefault();
          this.prev();
          break;
fat's avatar
fat committed
539

XhmikosR's avatar
Dist    
XhmikosR committed
540
541
542
543
        case ARROW_RIGHT_KEYCODE:
          event.preventDefault();
          this.next();
          break;
fat's avatar
fat committed
544

XhmikosR's avatar
Dist    
XhmikosR committed
545
546
547
        default:
      }
    };
fat's avatar
fat committed
548

XhmikosR's avatar
Dist    
XhmikosR committed
549
    _proto._getItemIndex = function _getItemIndex(element) {
XhmikosR's avatar
XhmikosR committed
550
      this._items = element && element.parentNode ? makeArray(SelectorEngine.find(Selector.ITEM, element.parentNode)) : [];
XhmikosR's avatar
Dist    
XhmikosR committed
551
552
      return this._items.indexOf(element);
    };
fat's avatar
fat committed
553

XhmikosR's avatar
Dist    
XhmikosR committed
554
555
556
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
      var isNextDirection = direction === Direction.NEXT;
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
dist    
Mark Otto committed
557

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
563
564
565
      if (isGoingToWrap && !this._config.wrap) {
        return activeElement;
      }
fat's avatar
fat committed
566

XhmikosR's avatar
Dist    
XhmikosR committed
567
568
569
570
      var delta = direction === Direction.PREV ? -1 : 1;
      var itemIndex = (activeIndex + delta) % this._items.length;
      return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
    };
fat's avatar
fat committed
571

XhmikosR's avatar
Dist    
XhmikosR committed
572
573
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
      var targetIndex = this._getItemIndex(relatedTarget);
fat's avatar
fat committed
574

XhmikosR's avatar
XhmikosR committed
575
      var fromIndex = this._getItemIndex(SelectorEngine.findOne(Selector.ACTIVE_ITEM, this._element));
fat's avatar
fat committed
576

XhmikosR's avatar
XhmikosR committed
577
      return EventHandler.trigger(this._element, Event.SLIDE, {
XhmikosR's avatar
Dist    
XhmikosR committed
578
579
580
581
582
583
        relatedTarget: relatedTarget,
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
      });
    };
fat's avatar
fat committed
584

XhmikosR's avatar
Dist    
XhmikosR committed
585
586
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
XhmikosR's avatar
XhmikosR committed
587
588
589
590
591
        var indicators = SelectorEngine.find(Selector.ACTIVE, this._indicatorsElement);

        for (var i = 0; i < indicators.length; i++) {
          indicators[i].classList.remove(ClassName.ACTIVE);
        }
fat's avatar
fat committed
592

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

XhmikosR's avatar
Dist    
XhmikosR committed
595
        if (nextIndicator) {
XhmikosR's avatar
XhmikosR committed
596
          nextIndicator.classList.add(ClassName.ACTIVE);
Mark Otto's avatar
dist    
Mark Otto committed
597
        }
XhmikosR's avatar
Dist    
XhmikosR committed
598
599
      }
    };
fat's avatar
fat committed
600

XhmikosR's avatar
Dist    
XhmikosR committed
601
602
    _proto._slide = function _slide(direction, element) {
      var _this4 = this;
fat's avatar
fat committed
603

XhmikosR's avatar
XhmikosR committed
604
      var activeElement = SelectorEngine.findOne(Selector.ACTIVE_ITEM, this._element);
fat's avatar
fat committed
605

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
612
613
614
615
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
616

XhmikosR's avatar
Dist    
XhmikosR committed
617
618
619
620
621
622
623
624
625
      if (direction === Direction.NEXT) {
        directionalClassName = ClassName.LEFT;
        orderClassName = ClassName.NEXT;
        eventDirectionName = Direction.LEFT;
      } else {
        directionalClassName = ClassName.RIGHT;
        orderClassName = ClassName.PREV;
        eventDirectionName = Direction.RIGHT;
      }
Mark Otto's avatar
dist    
Mark Otto committed
626

XhmikosR's avatar
XhmikosR committed
627
      if (nextElement && nextElement.classList.contains(ClassName.ACTIVE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
628
629
630
        this._isSliding = false;
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
631

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

XhmikosR's avatar
XhmikosR committed
634
      if (slideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
635
636
        return;
      }
fat's avatar
fat committed
637

XhmikosR's avatar
Dist    
XhmikosR committed
638
639
640
641
      if (!activeElement || !nextElement) {
        // Some weirdness is happening, so we bail
        return;
      }
fat's avatar
fat committed
642

XhmikosR's avatar
Dist    
XhmikosR committed
643
      this._isSliding = true;
Mark Otto's avatar
Mark Otto committed
644

XhmikosR's avatar
Dist    
XhmikosR committed
645
646
647
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
648

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

XhmikosR's avatar
XhmikosR committed
651
652
653
654
655
      if (this._element.classList.contains(ClassName.SLIDE)) {
        nextElement.classList.add(orderClassName);
        reflow(nextElement);
        activeElement.classList.add(directionalClassName);
        nextElement.classList.add(directionalClassName);
XhmikosR's avatar
Dist    
XhmikosR committed
656
        var nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10);
fat's avatar
fat committed
657

XhmikosR's avatar
Dist    
XhmikosR committed
658
659
660
661
662
663
        if (nextElementInterval) {
          this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
          this._config.interval = nextElementInterval;
        } else {
          this._config.interval = this._config.defaultInterval || this._config.interval;
        }
Mark Otto's avatar
dist    
Mark Otto committed
664

XhmikosR's avatar
XhmikosR committed
665
666
667
668
669
670
671
672
        var transitionDuration = getTransitionDurationFromElement(activeElement);
        EventHandler.one(activeElement, TRANSITION_END, function () {
          nextElement.classList.remove(directionalClassName);
          nextElement.classList.remove(orderClassName);
          nextElement.classList.add(ClassName.ACTIVE);
          activeElement.classList.remove(ClassName.ACTIVE);
          activeElement.classList.remove(orderClassName);
          activeElement.classList.remove(directionalClassName);
XhmikosR's avatar
Dist    
XhmikosR committed
673
674
          _this4._isSliding = false;
          setTimeout(function () {
XhmikosR's avatar
XhmikosR committed
675
            EventHandler.trigger(_this4._element, Event.SLID, {
XhmikosR's avatar
XhmikosR committed
676
677
678
679
680
              relatedTarget: nextElement,
              direction: eventDirectionName,
              from: activeElementIndex,
              to: nextElementIndex
            });
XhmikosR's avatar
Dist    
XhmikosR committed
681
          }, 0);
XhmikosR's avatar
XhmikosR committed
682
683
        });
        emulateTransitionEnd(activeElement, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
684
      } else {
XhmikosR's avatar
XhmikosR committed
685
686
        activeElement.classList.remove(ClassName.ACTIVE);
        nextElement.classList.add(ClassName.ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
687
        this._isSliding = false;
XhmikosR's avatar
XhmikosR committed
688
        EventHandler.trigger(this._element, Event.SLID, {
XhmikosR's avatar
XhmikosR committed
689
690
691
692
693
          relatedTarget: nextElement,
          direction: eventDirectionName,
          from: activeElementIndex,
          to: nextElementIndex
        });
XhmikosR's avatar
Dist    
XhmikosR committed
694
      }
Mark Otto's avatar
dist    
Mark Otto committed
695

XhmikosR's avatar
Dist    
XhmikosR committed
696
697
698
      if (isCycling) {
        this.cycle();
      }
Mark Otto's avatar
Mark Otto committed
699
700
    } // Static
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
701

XhmikosR's avatar
XhmikosR committed
702
703
    Carousel._carouselInterface = function _carouselInterface(element, config) {
      var data = Data.getData(element, DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
704

705
      var _config = _objectSpread2({}, Default, {}, Manipulator.getDataAttributes(element));
Mark Otto's avatar
dist    
Mark Otto committed
706

XhmikosR's avatar
XhmikosR committed
707
      if (typeof config === 'object') {
708
        _config = _objectSpread2({}, _config, {}, config);
XhmikosR's avatar
XhmikosR committed
709
      }
Mark Otto's avatar
dist    
Mark Otto committed
710

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

XhmikosR's avatar
XhmikosR committed
713
714
715
716
717
718
719
720
      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
721
          throw new TypeError("No method named \"" + action + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
722
        }
Mark Otto's avatar
dist    
Mark Otto committed
723

XhmikosR's avatar
XhmikosR committed
724
725
726
727
728
729
        data[action]();
      } else if (_config.interval && _config.ride) {
        data.pause();
        data.cycle();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
730

XhmikosR's avatar
XhmikosR committed
731
732
733
    Carousel._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        Carousel._carouselInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
734
735
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
736

XhmikosR's avatar
Dist    
XhmikosR committed
737
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
XhmikosR's avatar
XhmikosR committed
738
      var selector = getSelectorFromElement(this);
Mark Otto's avatar
dist    
Mark Otto committed
739

XhmikosR's avatar
Dist    
XhmikosR committed
740
741
742
      if (!selector) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
743

XhmikosR's avatar
XhmikosR committed
744
      var target = SelectorEngine.findOne(selector);
fat's avatar
fat committed
745

XhmikosR's avatar
XhmikosR committed
746
      if (!target || !target.classList.contains(ClassName.CAROUSEL)) {
XhmikosR's avatar
Dist    
XhmikosR committed
747
748
        return;
      }
fat's avatar
fat committed
749

750
      var config = _objectSpread2({}, Manipulator.getDataAttributes(target), {}, Manipulator.getDataAttributes(this));
fat's avatar
fat committed
751

XhmikosR's avatar
Dist    
XhmikosR committed
752
      var slideIndex = this.getAttribute('data-slide-to');
Mark Otto's avatar
dist    
Mark Otto committed
753

XhmikosR's avatar
Dist    
XhmikosR committed
754
755
      if (slideIndex) {
        config.interval = false;
Mark Otto's avatar
dist    
Mark Otto committed
756
      }
Mark Otto's avatar
dist    
Mark Otto committed
757

XhmikosR's avatar
XhmikosR committed
758
      Carousel._carouselInterface(target, config);
XhmikosR's avatar
Dist    
XhmikosR committed
759
760

      if (slideIndex) {
XhmikosR's avatar
XhmikosR committed
761
        Data.getData(target, DATA_KEY).to(slideIndex);
XhmikosR's avatar
Dist    
XhmikosR committed
762
      }
fat's avatar
fat committed
763

XhmikosR's avatar
Dist    
XhmikosR committed
764
      event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
765
    };
Mark Otto's avatar
dist    
Mark Otto committed
766

XhmikosR's avatar
XhmikosR committed
767
768
769
770
    Carousel._getInstance = function _getInstance(element) {
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
771
772
773
774
775
776
777
778
779
780
781
782
    _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
783
    return Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
784
785
786
787
788
789
790
791
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
792
793
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
  EventHandler.on(window, Event.LOAD_DATA_API, function () {
XhmikosR's avatar
XhmikosR committed
794
    var carousels = makeArray(SelectorEngine.find(Selector.DATA_RIDE));
XhmikosR's avatar
Dist    
XhmikosR committed
795
796

    for (var i = 0, len = carousels.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
797
      Carousel._carouselInterface(carousels[i], Data.getData(carousels[i], DATA_KEY));
XhmikosR's avatar
Dist    
XhmikosR committed
798
799
800
801
802
803
    }
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
804
   * add .carousel to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
805
806
   */

807
808
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
809
810
811
812
  if (typeof jQuery !== 'undefined') {
    var JQUERY_NO_CONFLICT = jQuery.fn[NAME];
    jQuery.fn[NAME] = Carousel._jQueryInterface;
    jQuery.fn[NAME].Constructor = Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
813

XhmikosR's avatar
XhmikosR committed
814
815
816
817
818
    jQuery.fn[NAME].noConflict = function () {
      jQuery.fn[NAME] = JQUERY_NO_CONFLICT;
      return Carousel._jQueryInterface;
    };
  }
fat's avatar
fat committed
819
820

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

Mark Otto's avatar
Mark Otto committed
822
}));
Mark Otto's avatar
dist    
Mark Otto committed
823
//# sourceMappingURL=carousel.js.map