carousel.js 19.7 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
Mark Otto's avatar
Mark Otto committed
2
  * Bootstrap carousel.js v4.2.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
7
8
(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
  typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
Mark Otto's avatar
Mark Otto committed
9
10
  (global = global || self, global.Carousel = factory(global.jQuery, global.Util));
}(this, function ($, Util) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11
12
13
14
15
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

  $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util;

  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
42

Mark Otto's avatar
dist    
Mark Otto committed
43
44
    return obj;
  }
Mark Otto's avatar
dist    
Mark Otto committed
45

Mark Otto's avatar
dist    
Mark Otto committed
46
47
48
49
  function _objectSpread(target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
      var ownKeys = Object.keys(source);
Mark Otto's avatar
dist    
Mark Otto committed
50

Mark Otto's avatar
dist    
Mark Otto committed
51
52
53
54
55
56
57
58
59
60
61
62
63
      if (typeof Object.getOwnPropertySymbols === 'function') {
        ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
          return Object.getOwnPropertyDescriptor(source, sym).enumerable;
        }));
      }

      ownKeys.forEach(function (key) {
        _defineProperty(target, key, source[key]);
      });
    }

    return target;
  }
fat's avatar
fat committed
64
65

  /**
XhmikosR's avatar
Dist    
XhmikosR committed
66
67
68
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
fat's avatar
fat committed
69
   */
Mark Otto's avatar
dist    
Mark Otto committed
70

XhmikosR's avatar
Dist    
XhmikosR committed
71
  var NAME = 'carousel';
Mark Otto's avatar
Mark Otto committed
72
  var VERSION = '4.2.1';
XhmikosR's avatar
Dist    
XhmikosR committed
73
74
75
76
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  var DATA_KEY = 'bs.carousel';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  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'
  };
  var Event = {
    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
145
146
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
147
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
148
149
     * ------------------------------------------------------------------------
     */
XhmikosR's avatar
Dist    
XhmikosR committed
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

  };

  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;
      this._indicatorsElement = this._element.querySelector(Selector.INDICATORS);
      this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
      this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent);

      this._addEventListeners();
    } // 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
182
    };
XhmikosR's avatar
Dist    
XhmikosR committed
183
184
185
186
187
188
189

    _proto.nextWhenVisible = function nextWhenVisible() {
      // Don't call next when the page isn't visible
      // or the carousel or its parent isn't visible
      if (!document.hidden && $(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden') {
        this.next();
      }
Mark Otto's avatar
dist    
Mark Otto committed
190
    };
XhmikosR's avatar
Dist    
XhmikosR committed
191
192
193
194
195

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

XhmikosR's avatar
Dist    
XhmikosR committed
198
199
200
201
202
203
204
205
206
207
208
209
    _proto.pause = function pause(event) {
      if (!event) {
        this._isPaused = true;
      }

      if (this._element.querySelector(Selector.NEXT_PREV)) {
        Util.triggerTransitionEnd(this._element);
        this.cycle(true);
      }

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

XhmikosR's avatar
Dist    
XhmikosR committed
212
213
    _proto.cycle = function cycle(event) {
      if (!event) {
Mark Otto's avatar
dist    
Mark Otto committed
214
        this._isPaused = false;
XhmikosR's avatar
Dist    
XhmikosR committed
215
      }
fat's avatar
fat committed
216

XhmikosR's avatar
Dist    
XhmikosR committed
217
218
219
220
      if (this._interval) {
        clearInterval(this._interval);
        this._interval = null;
      }
fat's avatar
fat committed
221

XhmikosR's avatar
Dist    
XhmikosR committed
222
223
224
225
      if (this._config.interval && !this._isPaused) {
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
226

XhmikosR's avatar
Dist    
XhmikosR committed
227
228
    _proto.to = function to(index) {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
229

XhmikosR's avatar
Dist    
XhmikosR committed
230
      this._activeElement = this._element.querySelector(Selector.ACTIVE_ITEM);
Mark Otto's avatar
dist    
Mark Otto committed
231

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

XhmikosR's avatar
Dist    
XhmikosR committed
234
235
236
      if (index > this._items.length - 1 || index < 0) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
237

XhmikosR's avatar
Dist    
XhmikosR committed
238
239
240
241
242
243
      if (this._isSliding) {
        $(this._element).one(Event.SLID, function () {
          return _this.to(index);
        });
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
244

XhmikosR's avatar
Dist    
XhmikosR committed
245
246
247
248
249
      if (activeIndex === index) {
        this.pause();
        this.cycle();
        return;
      }
fat's avatar
fat committed
250

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

XhmikosR's avatar
Dist    
XhmikosR committed
253
254
      this._slide(direction, this._items[index]);
    };
Mark Otto's avatar
dist    
Mark Otto committed
255

XhmikosR's avatar
Dist    
XhmikosR committed
256
257
258
259
260
261
262
263
264
265
266
    _proto.dispose = function dispose() {
      $(this._element).off(EVENT_KEY);
      $.removeData(this._element, DATA_KEY);
      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
267
268
    } // Private
    ;
XhmikosR's avatar
Dist    
XhmikosR committed
269
270
271
272
273
274

    _proto._getConfig = function _getConfig(config) {
      config = _objectSpread({}, Default, config);
      Util.typeCheckConfig(NAME, config, DefaultType);
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
275

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

XhmikosR's avatar
Dist    
XhmikosR committed
279
280
281
      if (absDeltax <= SWIPE_THRESHOLD) {
        return;
      }
fat's avatar
fat committed
282

XhmikosR's avatar
Dist    
XhmikosR committed
283
      var direction = absDeltax / this.touchDeltaX; // swipe left
fat's avatar
fat committed
284

XhmikosR's avatar
Dist    
XhmikosR committed
285
286
287
      if (direction > 0) {
        this.prev();
      } // swipe right
fat's avatar
fat committed
288
289


XhmikosR's avatar
Dist    
XhmikosR committed
290
291
292
293
      if (direction < 0) {
        this.next();
      }
    };
fat's avatar
fat committed
294

XhmikosR's avatar
Dist    
XhmikosR committed
295
296
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
fat's avatar
fat committed
297

XhmikosR's avatar
Dist    
XhmikosR committed
298
299
300
301
302
      if (this._config.keyboard) {
        $(this._element).on(Event.KEYDOWN, function (event) {
          return _this2._keydown(event);
        });
      }
Mark Otto's avatar
grunt    
Mark Otto committed
303

XhmikosR's avatar
Dist    
XhmikosR committed
304
305
306
307
308
309
310
      if (this._config.pause === 'hover') {
        $(this._element).on(Event.MOUSEENTER, function (event) {
          return _this2.pause(event);
        }).on(Event.MOUSELEAVE, function (event) {
          return _this2.cycle(event);
        });
      }
fat's avatar
fat committed
311

XhmikosR's avatar
Dist    
XhmikosR committed
312
313
      this._addTouchEventListeners();
    };
Mark Otto's avatar
dist    
Mark Otto committed
314

XhmikosR's avatar
Dist    
XhmikosR committed
315
316
    _proto._addTouchEventListeners = function _addTouchEventListeners() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
317

XhmikosR's avatar
Dist    
XhmikosR committed
318
319
320
      if (!this._touchSupported) {
        return;
      }
fat's avatar
fat committed
321

XhmikosR's avatar
Dist    
XhmikosR committed
322
      var start = function start(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
323
        if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
XhmikosR's avatar
Dist    
XhmikosR committed
324
325
326
          _this3.touchStartX = event.originalEvent.clientX;
        } else if (!_this3._pointerEvent) {
          _this3.touchStartX = event.originalEvent.touches[0].clientX;
Mark Otto's avatar
dist    
Mark Otto committed
327
        }
XhmikosR's avatar
Dist    
XhmikosR committed
328
      };
Mark Otto's avatar
dist    
Mark Otto committed
329

XhmikosR's avatar
Dist    
XhmikosR committed
330
331
332
333
334
335
      var move = function move(event) {
        // ensure swiping with one touch and not pinching
        if (event.originalEvent.touches && event.originalEvent.touches.length > 1) {
          _this3.touchDeltaX = 0;
        } else {
          _this3.touchDeltaX = event.originalEvent.touches[0].clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
336
337
        }
      };
fat's avatar
fat committed
338

XhmikosR's avatar
Dist    
XhmikosR committed
339
      var end = function end(event) {
XhmikosR's avatar
Dist    
XhmikosR committed
340
        if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
XhmikosR's avatar
Dist    
XhmikosR committed
341
          _this3.touchDeltaX = event.originalEvent.clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
342
        }
Mark Otto's avatar
dist    
Mark Otto committed
343

XhmikosR's avatar
Dist    
XhmikosR committed
344
345
346
347
348
349
350
351
352
353
354
        _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
355

XhmikosR's avatar
Dist    
XhmikosR committed
356
357
358
          if (_this3.touchTimeout) {
            clearTimeout(_this3.touchTimeout);
          }
fat's avatar
fat committed
359

XhmikosR's avatar
Dist    
XhmikosR committed
360
361
362
          _this3.touchTimeout = setTimeout(function (event) {
            return _this3.cycle(event);
          }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval);
Mark Otto's avatar
dist    
Mark Otto committed
363
364
        }
      };
Mark Otto's avatar
grunt    
Mark Otto committed
365

XhmikosR's avatar
Dist    
XhmikosR committed
366
367
368
      $(this._element.querySelectorAll(Selector.ITEM_IMG)).on(Event.DRAG_START, function (e) {
        return e.preventDefault();
      });
Mark Otto's avatar
grunt    
Mark Otto committed
369

XhmikosR's avatar
Dist    
XhmikosR committed
370
371
372
373
374
375
376
      if (this._pointerEvent) {
        $(this._element).on(Event.POINTERDOWN, function (event) {
          return start(event);
        });
        $(this._element).on(Event.POINTERUP, function (event) {
          return end(event);
        });
Mark Otto's avatar
dist    
Mark Otto committed
377

XhmikosR's avatar
Dist    
XhmikosR committed
378
379
380
381
382
383
384
385
386
387
388
389
390
        this._element.classList.add(ClassName.POINTER_EVENT);
      } else {
        $(this._element).on(Event.TOUCHSTART, function (event) {
          return start(event);
        });
        $(this._element).on(Event.TOUCHMOVE, function (event) {
          return move(event);
        });
        $(this._element).on(Event.TOUCHEND, function (event) {
          return end(event);
        });
      }
    };
fat's avatar
fat committed
391

XhmikosR's avatar
Dist    
XhmikosR committed
392
393
394
395
    _proto._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
      }
fat's avatar
fat committed
396

XhmikosR's avatar
Dist    
XhmikosR committed
397
398
399
400
401
      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
          event.preventDefault();
          this.prev();
          break;
fat's avatar
fat committed
402

XhmikosR's avatar
Dist    
XhmikosR committed
403
404
405
406
        case ARROW_RIGHT_KEYCODE:
          event.preventDefault();
          this.next();
          break;
fat's avatar
fat committed
407

XhmikosR's avatar
Dist    
XhmikosR committed
408
409
410
        default:
      }
    };
fat's avatar
fat committed
411

XhmikosR's avatar
Dist    
XhmikosR committed
412
413
414
415
    _proto._getItemIndex = function _getItemIndex(element) {
      this._items = element && element.parentNode ? [].slice.call(element.parentNode.querySelectorAll(Selector.ITEM)) : [];
      return this._items.indexOf(element);
    };
fat's avatar
fat committed
416

XhmikosR's avatar
Dist    
XhmikosR committed
417
418
419
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
      var isNextDirection = direction === Direction.NEXT;
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
dist    
Mark Otto committed
420

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
426
427
428
      if (isGoingToWrap && !this._config.wrap) {
        return activeElement;
      }
fat's avatar
fat committed
429

XhmikosR's avatar
Dist    
XhmikosR committed
430
431
432
433
      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
434

XhmikosR's avatar
Dist    
XhmikosR committed
435
436
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
      var targetIndex = this._getItemIndex(relatedTarget);
fat's avatar
fat committed
437

XhmikosR's avatar
Dist    
XhmikosR committed
438
      var fromIndex = this._getItemIndex(this._element.querySelector(Selector.ACTIVE_ITEM));
fat's avatar
fat committed
439

XhmikosR's avatar
Dist    
XhmikosR committed
440
441
442
443
444
445
446
447
448
      var slideEvent = $.Event(Event.SLIDE, {
        relatedTarget: relatedTarget,
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
      });
      $(this._element).trigger(slideEvent);
      return slideEvent;
    };
fat's avatar
fat committed
449

XhmikosR's avatar
Dist    
XhmikosR committed
450
451
452
453
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
        var indicators = [].slice.call(this._indicatorsElement.querySelectorAll(Selector.ACTIVE));
        $(indicators).removeClass(ClassName.ACTIVE);
fat's avatar
fat committed
454

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

XhmikosR's avatar
Dist    
XhmikosR committed
457
458
        if (nextIndicator) {
          $(nextIndicator).addClass(ClassName.ACTIVE);
Mark Otto's avatar
dist    
Mark Otto committed
459
        }
XhmikosR's avatar
Dist    
XhmikosR committed
460
461
      }
    };
fat's avatar
fat committed
462

XhmikosR's avatar
Dist    
XhmikosR committed
463
464
    _proto._slide = function _slide(direction, element) {
      var _this4 = this;
fat's avatar
fat committed
465

XhmikosR's avatar
Dist    
XhmikosR committed
466
      var activeElement = this._element.querySelector(Selector.ACTIVE_ITEM);
fat's avatar
fat committed
467

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
474
475
476
477
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
478

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

XhmikosR's avatar
Dist    
XhmikosR committed
489
490
491
492
      if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
        this._isSliding = false;
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
493

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

XhmikosR's avatar
Dist    
XhmikosR committed
496
497
498
      if (slideEvent.isDefaultPrevented()) {
        return;
      }
fat's avatar
fat committed
499

XhmikosR's avatar
Dist    
XhmikosR committed
500
501
502
503
      if (!activeElement || !nextElement) {
        // Some weirdness is happening, so we bail
        return;
      }
fat's avatar
fat committed
504

XhmikosR's avatar
Dist    
XhmikosR committed
505
      this._isSliding = true;
Mark Otto's avatar
Mark Otto committed
506

XhmikosR's avatar
Dist    
XhmikosR committed
507
508
509
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
510

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

XhmikosR's avatar
Dist    
XhmikosR committed
513
514
515
516
517
518
      var slidEvent = $.Event(Event.SLID, {
        relatedTarget: nextElement,
        direction: eventDirectionName,
        from: activeElementIndex,
        to: nextElementIndex
      });
fat's avatar
fat committed
519

XhmikosR's avatar
Dist    
XhmikosR committed
520
521
522
523
524
525
      if ($(this._element).hasClass(ClassName.SLIDE)) {
        $(nextElement).addClass(orderClassName);
        Util.reflow(nextElement);
        $(activeElement).addClass(directionalClassName);
        $(nextElement).addClass(directionalClassName);
        var nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10);
fat's avatar
fat committed
526

XhmikosR's avatar
Dist    
XhmikosR committed
527
528
529
530
531
532
        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
533

XhmikosR's avatar
Dist    
XhmikosR committed
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
        var transitionDuration = Util.getTransitionDurationFromElement(activeElement);
        $(activeElement).one(Util.TRANSITION_END, function () {
          $(nextElement).removeClass(directionalClassName + " " + orderClassName).addClass(ClassName.ACTIVE);
          $(activeElement).removeClass(ClassName.ACTIVE + " " + orderClassName + " " + directionalClassName);
          _this4._isSliding = false;
          setTimeout(function () {
            return $(_this4._element).trigger(slidEvent);
          }, 0);
        }).emulateTransitionEnd(transitionDuration);
      } else {
        $(activeElement).removeClass(ClassName.ACTIVE);
        $(nextElement).addClass(ClassName.ACTIVE);
        this._isSliding = false;
        $(this._element).trigger(slidEvent);
      }
Mark Otto's avatar
dist    
Mark Otto committed
549

XhmikosR's avatar
Dist    
XhmikosR committed
550
551
552
      if (isCycling) {
        this.cycle();
      }
Mark Otto's avatar
Mark Otto committed
553
554
    } // Static
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
555

XhmikosR's avatar
Dist    
XhmikosR committed
556
557
558
    Carousel._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
559

XhmikosR's avatar
Dist    
XhmikosR committed
560
        var _config = _objectSpread({}, Default, $(this).data());
Mark Otto's avatar
dist    
Mark Otto committed
561

XhmikosR's avatar
Dist    
XhmikosR committed
562
563
564
        if (typeof config === 'object') {
          _config = _objectSpread({}, _config, config);
        }
Mark Otto's avatar
dist    
Mark Otto committed
565

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

XhmikosR's avatar
Dist    
XhmikosR committed
568
569
570
        if (!data) {
          data = new Carousel(this, _config);
          $(this).data(DATA_KEY, data);
Mark Otto's avatar
dist    
Mark Otto committed
571
        }
Mark Otto's avatar
dist    
Mark Otto committed
572

XhmikosR's avatar
Dist    
XhmikosR committed
573
574
575
576
577
578
        if (typeof config === 'number') {
          data.to(config);
        } else if (typeof action === 'string') {
          if (typeof data[action] === 'undefined') {
            throw new TypeError("No method named \"" + action + "\"");
          }
Mark Otto's avatar
dist    
Mark Otto committed
579

XhmikosR's avatar
Dist    
XhmikosR committed
580
          data[action]();
Mark Otto's avatar
Mark Otto committed
581
        } else if (_config.interval && _config.ride) {
XhmikosR's avatar
Dist    
XhmikosR committed
582
583
          data.pause();
          data.cycle();
Mark Otto's avatar
dist    
Mark Otto committed
584
        }
XhmikosR's avatar
Dist    
XhmikosR committed
585
586
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
587

XhmikosR's avatar
Dist    
XhmikosR committed
588
589
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
      var selector = Util.getSelectorFromElement(this);
Mark Otto's avatar
dist    
Mark Otto committed
590

XhmikosR's avatar
Dist    
XhmikosR committed
591
592
593
      if (!selector) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
594

XhmikosR's avatar
Dist    
XhmikosR committed
595
      var target = $(selector)[0];
fat's avatar
fat committed
596

XhmikosR's avatar
Dist    
XhmikosR committed
597
598
599
      if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
        return;
      }
fat's avatar
fat committed
600

XhmikosR's avatar
Dist    
XhmikosR committed
601
      var config = _objectSpread({}, $(target).data(), $(this).data());
fat's avatar
fat committed
602

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

XhmikosR's avatar
Dist    
XhmikosR committed
605
606
      if (slideIndex) {
        config.interval = false;
Mark Otto's avatar
dist    
Mark Otto committed
607
      }
Mark Otto's avatar
dist    
Mark Otto committed
608

XhmikosR's avatar
Dist    
XhmikosR committed
609
610
611
612
613
      Carousel._jQueryInterface.call($(target), config);

      if (slideIndex) {
        $(target).data(DATA_KEY).to(slideIndex);
      }
fat's avatar
fat committed
614

XhmikosR's avatar
Dist    
XhmikosR committed
615
      event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
616
    };
Mark Otto's avatar
dist    
Mark Otto committed
617

XhmikosR's avatar
Dist    
XhmikosR committed
618
619
620
621
622
623
624
625
626
627
628
629
    _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
630
    return Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


  $(document).on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
  $(window).on(Event.LOAD_DATA_API, function () {
    var carousels = [].slice.call(document.querySelectorAll(Selector.DATA_RIDE));

    for (var i = 0, len = carousels.length; i < len; i++) {
      var $carousel = $(carousels[i]);

      Carousel._jQueryInterface.call($carousel, $carousel.data());
    }
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */

  $.fn[NAME] = Carousel._jQueryInterface;
  $.fn[NAME].Constructor = Carousel;

  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Carousel._jQueryInterface;
  };
fat's avatar
fat committed
662
663

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

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