carousel.js 19.9 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
2
3
4
5
/*!
  * Bootstrap carousel.js v4.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2018 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
7
8
9
10
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
(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) :
  (global.Carousel = factory(global.jQuery,global.Util));
}(this, (function ($,Util) { 'use strict';

  $ = $ && $.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
72
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
145
146
147
  var NAME = 'carousel';
  var VERSION = '4.1.3';
  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,
    POINTERMOVE: "pointermove" + EVENT_KEY,
    POINTERUP: "pointerup" + EVENT_KEY,
    POINTERLEAVE: "pointerleave" + EVENT_KEY,
    POINTERCANCEL: "pointercancel" + 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
148
149
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
150
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
151
152
     * ------------------------------------------------------------------------
     */
XhmikosR's avatar
Dist    
XhmikosR committed
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

  };

  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
185
    };
XhmikosR's avatar
Dist    
XhmikosR committed
186
187
188
189
190
191
192

    _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
193
    };
XhmikosR's avatar
Dist    
XhmikosR committed
194
195
196
197
198

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

XhmikosR's avatar
Dist    
XhmikosR committed
201
202
203
204
205
206
207
208
209
210
211
212
    _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
213
    };
fat's avatar
fat committed
214

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

XhmikosR's avatar
Dist    
XhmikosR committed
220
221
222
223
      if (this._interval) {
        clearInterval(this._interval);
        this._interval = null;
      }
fat's avatar
fat committed
224

XhmikosR's avatar
Dist    
XhmikosR committed
225
226
227
228
      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
229

XhmikosR's avatar
Dist    
XhmikosR committed
230
231
    _proto.to = function to(index) {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
232

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

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

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

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
256
257
      this._slide(direction, this._items[index]);
    };
Mark Otto's avatar
dist    
Mark Otto committed
258

XhmikosR's avatar
Dist    
XhmikosR committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
    _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;
    }; // Private


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

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

XhmikosR's avatar
Dist    
XhmikosR committed
282
283
284
      if (absDeltax <= SWIPE_THRESHOLD) {
        return;
      }
fat's avatar
fat committed
285

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

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


XhmikosR's avatar
Dist    
XhmikosR committed
293
294
295
296
      if (direction < 0) {
        this.next();
      }
    };
fat's avatar
fat committed
297

XhmikosR's avatar
Dist    
XhmikosR committed
298
299
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
fat's avatar
fat committed
300

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

XhmikosR's avatar
Dist    
XhmikosR committed
307
308
309
310
311
312
313
      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
314

XhmikosR's avatar
Dist    
XhmikosR committed
315
316
      this._addTouchEventListeners();
    };
Mark Otto's avatar
dist    
Mark Otto committed
317

XhmikosR's avatar
Dist    
XhmikosR committed
318
319
    _proto._addTouchEventListeners = function _addTouchEventListeners() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
320

XhmikosR's avatar
Dist    
XhmikosR committed
321
322
323
      if (!this._touchSupported) {
        return;
      }
fat's avatar
fat committed
324

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

XhmikosR's avatar
Dist    
XhmikosR committed
333
334
335
336
337
338
      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
339
340
        }
      };
fat's avatar
fat committed
341

XhmikosR's avatar
Dist    
XhmikosR committed
342
343
344
      var end = function end(event) {
        if (_this3._pointerEvent && (event.originalEvent.pointerType === PointerType.TOUCH || event.originalEvent.pointerType === PointerType.PEN)) {
          _this3.touchDeltaX = event.originalEvent.clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
345
        }
Mark Otto's avatar
dist    
Mark Otto committed
346

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

XhmikosR's avatar
Dist    
XhmikosR committed
359
360
361
          if (_this3.touchTimeout) {
            clearTimeout(_this3.touchTimeout);
          }
fat's avatar
fat committed
362

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
373
374
375
376
377
378
379
      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
380

XhmikosR's avatar
Dist    
XhmikosR committed
381
382
383
384
385
386
387
388
389
390
391
392
393
        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
394

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
406
407
408
409
        case ARROW_RIGHT_KEYCODE:
          event.preventDefault();
          this.next();
          break;
fat's avatar
fat committed
410

XhmikosR's avatar
Dist    
XhmikosR committed
411
412
413
        default:
      }
    };
fat's avatar
fat committed
414

XhmikosR's avatar
Dist    
XhmikosR committed
415
416
417
418
    _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
419

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
429
430
431
      if (isGoingToWrap && !this._config.wrap) {
        return activeElement;
      }
fat's avatar
fat committed
432

XhmikosR's avatar
Dist    
XhmikosR committed
433
434
435
436
      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
437

XhmikosR's avatar
Dist    
XhmikosR committed
438
439
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
      var targetIndex = this._getItemIndex(relatedTarget);
fat's avatar
fat committed
440

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
453
454
455
456
    _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
457

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
466
467
    _proto._slide = function _slide(direction, element) {
      var _this4 = this;
fat's avatar
fat committed
468

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

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
477
478
479
480
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
481

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

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
499
500
501
      if (slideEvent.isDefaultPrevented()) {
        return;
      }
fat's avatar
fat committed
502

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

XhmikosR's avatar
Dist    
XhmikosR committed
508
      this._isSliding = true;
Mark Otto's avatar
Mark Otto committed
509

XhmikosR's avatar
Dist    
XhmikosR committed
510
511
512
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
513

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
523
524
525
526
527
528
      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
529

XhmikosR's avatar
Dist    
XhmikosR committed
530
531
532
533
534
535
        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
536

XhmikosR's avatar
Dist    
XhmikosR committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
        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
552

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


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

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

XhmikosR's avatar
Dist    
XhmikosR committed
565
566
567
        if (typeof config === 'object') {
          _config = _objectSpread({}, _config, config);
        }
Mark Otto's avatar
dist    
Mark Otto committed
568

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
576
577
578
579
580
581
        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
582

XhmikosR's avatar
Dist    
XhmikosR committed
583
584
585
586
          data[action]();
        } else if (_config.interval) {
          data.pause();
          data.cycle();
Mark Otto's avatar
dist    
Mark Otto committed
587
        }
XhmikosR's avatar
Dist    
XhmikosR committed
588
589
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
590

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

XhmikosR's avatar
Dist    
XhmikosR committed
594
595
596
      if (!selector) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
597

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

XhmikosR's avatar
Dist    
XhmikosR committed
600
601
602
      if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
        return;
      }
fat's avatar
fat committed
603

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
608
609
      if (slideIndex) {
        config.interval = false;
Mark Otto's avatar
dist    
Mark Otto committed
610
      }
Mark Otto's avatar
dist    
Mark Otto committed
611

XhmikosR's avatar
Dist    
XhmikosR committed
612
613
614
615
616
      Carousel._jQueryInterface.call($(target), config);

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

XhmikosR's avatar
Dist    
XhmikosR committed
618
      event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
619
    };
Mark Otto's avatar
dist    
Mark Otto committed
620

XhmikosR's avatar
Dist    
XhmikosR committed
621
622
623
624
625
626
627
628
629
630
631
632
    _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
633
    return Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
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
662
663
664
  }();
  /**
   * ------------------------------------------------------------------------
   * 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
665
666

  return Carousel;
Mark Otto's avatar
dist    
Mark Otto committed
667
668
669

})));
//# sourceMappingURL=carousel.js.map