carousel.js 15.8 KB
Newer Older
Mark Otto's avatar
dist    
Mark Otto committed
1
2
3
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); 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; }

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; } return obj; }
Mark Otto's avatar
dist    
Mark Otto committed
4

Mark Otto's avatar
dist    
Mark Otto committed
5
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); } }
Mark Otto's avatar
dist    
Mark Otto committed
6

Mark Otto's avatar
dist    
Mark Otto committed
7
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
fat's avatar
fat committed
8
9
10

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
11
 * Bootstrap (v4.1.2): carousel.js
fat's avatar
fat committed
12
13
14
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */
Mark Otto's avatar
dist    
Mark Otto committed
15
var Carousel = function ($) {
fat's avatar
fat committed
16
17
18
19
20
21
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */
  var NAME = 'carousel';
Mark Otto's avatar
Mark Otto committed
22
  var VERSION = '4.1.2';
fat's avatar
fat committed
23
  var DATA_KEY = 'bs.carousel';
Mark Otto's avatar
dist    
Mark Otto committed
24
  var EVENT_KEY = "." + DATA_KEY;
fat's avatar
fat committed
25
  var DATA_API_KEY = '.data-api';
fat's avatar
fat committed
26
  var JQUERY_NO_CONFLICT = $.fn[NAME];
Chris Rebert's avatar
grunt    
Chris Rebert committed
27
  var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key
Mark Otto's avatar
dist    
Mark Otto committed
28

Chris Rebert's avatar
grunt    
Chris Rebert committed
29
  var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key
Mark Otto's avatar
dist    
Mark Otto committed
30

Mark Otto's avatar
build    
Mark Otto committed
31
  var TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch
fat's avatar
fat committed
32

33
  var Default = {
fat's avatar
fat committed
34
35
36
37
38
    interval: 5000,
    keyboard: true,
    slide: false,
    pause: 'hover',
    wrap: true
fat's avatar
fat committed
39
  };
fat's avatar
fat committed
40
41
42
43
  var DefaultType = {
    interval: '(number|boolean)',
    keyboard: 'boolean',
    slide: '(boolean|string)',
44
    pause: '(string|boolean)',
fat's avatar
fat committed
45
46
    wrap: 'boolean'
  };
fat's avatar
fat committed
47
48
  var Direction = {
    NEXT: 'next',
Mark Otto's avatar
grunt    
Mark Otto committed
49
50
51
    PREV: 'prev',
    LEFT: 'left',
    RIGHT: 'right'
fat's avatar
fat committed
52
53
  };
  var Event = {
Mark Otto's avatar
dist    
Mark Otto committed
54
55
56
57
58
59
60
61
    SLIDE: "slide" + EVENT_KEY,
    SLID: "slid" + EVENT_KEY,
    KEYDOWN: "keydown" + EVENT_KEY,
    MOUSEENTER: "mouseenter" + EVENT_KEY,
    MOUSELEAVE: "mouseleave" + EVENT_KEY,
    TOUCHEND: "touchend" + EVENT_KEY,
    LOAD_DATA_API: "load" + EVENT_KEY + DATA_API_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
fat's avatar
fat committed
62
63
64
65
66
  };
  var ClassName = {
    CAROUSEL: 'carousel',
    ACTIVE: 'active',
    SLIDE: 'slide',
Mark Otto's avatar
grunt    
Mark Otto committed
67
68
69
70
    RIGHT: 'carousel-item-right',
    LEFT: 'carousel-item-left',
    NEXT: 'carousel-item-next',
    PREV: 'carousel-item-prev',
fat's avatar
fat committed
71
72
73
74
75
76
    ITEM: 'carousel-item'
  };
  var Selector = {
    ACTIVE: '.active',
    ACTIVE_ITEM: '.active.carousel-item',
    ITEM: '.carousel-item',
Mark Otto's avatar
grunt    
Mark Otto committed
77
    NEXT_PREV: '.carousel-item-next, .carousel-item-prev',
fat's avatar
fat committed
78
79
80
    INDICATORS: '.carousel-indicators',
    DATA_SLIDE: '[data-slide], [data-slide-to]',
    DATA_RIDE: '[data-ride="carousel"]'
Mark Otto's avatar
dist    
Mark Otto committed
81
82
83
84
85
    /**
     * ------------------------------------------------------------------------
     * Class Definition
     * ------------------------------------------------------------------------
     */
fat's avatar
fat committed
86

Mark Otto's avatar
dist    
Mark Otto committed
87
  };
fat's avatar
fat committed
88

Mark Otto's avatar
dist    
Mark Otto committed
89
90
91
92
  var Carousel =
  /*#__PURE__*/
  function () {
    function Carousel(element, config) {
fat's avatar
fat committed
93
94
95
96
97
      this._items = null;
      this._interval = null;
      this._activeElement = null;
      this._isPaused = false;
      this._isSliding = false;
Mark Otto's avatar
build    
Mark Otto committed
98
      this.touchTimeout = null;
fat's avatar
fat committed
99
      this._config = this._getConfig(config);
fat's avatar
fat committed
100
      this._element = $(element)[0];
Mark Otto's avatar
dist    
Mark Otto committed
101
      this._indicatorsElement = this._element.querySelector(Selector.INDICATORS);
fat's avatar
fat committed
102
103

      this._addEventListeners();
Mark Otto's avatar
dist    
Mark Otto committed
104
    } // Getters
fat's avatar
fat committed
105

Jacob Thornton's avatar
Jacob Thornton committed
106

Mark Otto's avatar
dist    
Mark Otto committed
107
    var _proto = Carousel.prototype;
fat's avatar
fat committed
108

Mark Otto's avatar
dist    
Mark Otto committed
109
    // Public
Mark Otto's avatar
dist    
Mark Otto committed
110
111
112
113
114
    _proto.next = function next() {
      if (!this._isSliding) {
        this._slide(Direction.NEXT);
      }
    };
fat's avatar
fat committed
115

Mark Otto's avatar
dist    
Mark Otto committed
116
117
118
119
120
121
122
    _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
grunt    
Mark Otto committed
123

Mark Otto's avatar
dist    
Mark Otto committed
124
125
126
    _proto.prev = function prev() {
      if (!this._isSliding) {
        this._slide(Direction.PREV);
XhmikosR's avatar
XhmikosR committed
127
      }
Mark Otto's avatar
dist    
Mark Otto committed
128
129
130
131
132
    };

    _proto.pause = function pause(event) {
      if (!event) {
        this._isPaused = true;
fat's avatar
fat committed
133
      }
Mark Otto's avatar
dist    
Mark Otto committed
134

Mark Otto's avatar
dist    
Mark Otto committed
135
      if (this._element.querySelector(Selector.NEXT_PREV)) {
Mark Otto's avatar
dist    
Mark Otto committed
136
137
        Util.triggerTransitionEnd(this._element);
        this.cycle(true);
Mark Otto's avatar
grunt    
Mark Otto committed
138
      }
fat's avatar
fat committed
139

Mark Otto's avatar
dist    
Mark Otto committed
140
141
142
143
144
145
146
147
      clearInterval(this._interval);
      this._interval = null;
    };

    _proto.cycle = function cycle(event) {
      if (!event) {
        this._isPaused = false;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
148

Mark Otto's avatar
dist    
Mark Otto committed
149
      if (this._interval) {
fat's avatar
fat committed
150
151
152
153
        clearInterval(this._interval);
        this._interval = null;
      }

Mark Otto's avatar
dist    
Mark Otto committed
154
155
156
157
      if (this._config.interval && !this._isPaused) {
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
      }
    };
fat's avatar
fat committed
158

Mark Otto's avatar
dist    
Mark Otto committed
159
160
161
    _proto.to = function to(index) {
      var _this = this;

Mark Otto's avatar
dist    
Mark Otto committed
162
      this._activeElement = this._element.querySelector(Selector.ACTIVE_ITEM);
Mark Otto's avatar
dist    
Mark Otto committed
163
164
165
166
167

      var activeIndex = this._getItemIndex(this._activeElement);

      if (index > this._items.length - 1 || index < 0) {
        return;
Mark Otto's avatar
grunt    
Mark Otto committed
168
      }
fat's avatar
fat committed
169

Mark Otto's avatar
dist    
Mark Otto committed
170
171
172
173
174
175
      if (this._isSliding) {
        $(this._element).one(Event.SLID, function () {
          return _this.to(index);
        });
        return;
      }
fat's avatar
fat committed
176

Mark Otto's avatar
dist    
Mark Otto committed
177
178
179
180
181
      if (activeIndex === index) {
        this.pause();
        this.cycle();
        return;
      }
fat's avatar
fat committed
182

Mark Otto's avatar
dist    
Mark Otto committed
183
      var direction = index > activeIndex ? Direction.NEXT : Direction.PREV;
fat's avatar
fat committed
184

Mark Otto's avatar
dist    
Mark Otto committed
185
186
      this._slide(direction, this._items[index]);
    };
fat's avatar
fat committed
187

Mark Otto's avatar
dist    
Mark Otto committed
188
189
190
191
192
193
194
195
196
197
198
    _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
dist    
Mark Otto committed
199
    }; // Private
fat's avatar
fat committed
200
201


Mark Otto's avatar
dist    
Mark Otto committed
202
    _proto._getConfig = function _getConfig(config) {
Mark Otto's avatar
dist    
Mark Otto committed
203
      config = _objectSpread({}, Default, config);
Mark Otto's avatar
dist    
Mark Otto committed
204
205
206
      Util.typeCheckConfig(NAME, config, DefaultType);
      return config;
    };
fat's avatar
fat committed
207

Mark Otto's avatar
dist    
Mark Otto committed
208
209
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
210

Mark Otto's avatar
dist    
Mark Otto committed
211
212
213
214
      if (this._config.keyboard) {
        $(this._element).on(Event.KEYDOWN, function (event) {
          return _this2._keydown(event);
        });
fat's avatar
fat committed
215
      }
fat's avatar
fat committed
216

Mark Otto's avatar
dist    
Mark Otto committed
217
218
219
220
221
222
223
224
      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);
        });

        if ('ontouchstart' in document.documentElement) {
Mark Otto's avatar
dist    
Mark Otto committed
225
          // If it's a touch-enabled device, mouseenter/leave are fired as
Mark Otto's avatar
dist    
Mark Otto committed
226
227
228
229
230
231
232
233
234
235
236
237
          // 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
          $(this._element).on(Event.TOUCHEND, function () {
            _this2.pause();

            if (_this2.touchTimeout) {
              clearTimeout(_this2.touchTimeout);
            }
fat's avatar
fat committed
238

Mark Otto's avatar
dist    
Mark Otto committed
239
240
241
            _this2.touchTimeout = setTimeout(function (event) {
              return _this2.cycle(event);
            }, TOUCHEVENT_COMPAT_WAIT + _this2._config.interval);
Mark Otto's avatar
dist    
Mark Otto committed
242
243
          });
        }
fat's avatar
fat committed
244
      }
Mark Otto's avatar
dist    
Mark Otto committed
245
    };
Mark Otto's avatar
dist    
Mark Otto committed
246

Mark Otto's avatar
dist    
Mark Otto committed
247
248
249
    _proto._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
Mark Otto's avatar
grunt    
Mark Otto committed
250
      }
fat's avatar
fat committed
251

Mark Otto's avatar
dist    
Mark Otto committed
252
253
254
255
256
      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
          event.preventDefault();
          this.prev();
          break;
fat's avatar
fat committed
257

Mark Otto's avatar
dist    
Mark Otto committed
258
259
260
261
262
263
        case ARROW_RIGHT_KEYCODE:
          event.preventDefault();
          this.next();
          break;

        default:
Mark Otto's avatar
dist    
Mark Otto committed
264
      }
Mark Otto's avatar
dist    
Mark Otto committed
265
    };
fat's avatar
fat committed
266

Mark Otto's avatar
dist    
Mark Otto committed
267
    _proto._getItemIndex = function _getItemIndex(element) {
Mark Otto's avatar
dist    
Mark Otto committed
268
      this._items = element && element.parentNode ? [].slice.call(element.parentNode.querySelectorAll(Selector.ITEM)) : [];
Mark Otto's avatar
dist    
Mark Otto committed
269
270
      return this._items.indexOf(element);
    };
fat's avatar
fat committed
271

Mark Otto's avatar
dist    
Mark Otto committed
272
273
274
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
      var isNextDirection = direction === Direction.NEXT;
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
grunt    
Mark Otto committed
275

Mark Otto's avatar
dist    
Mark Otto committed
276
      var activeIndex = this._getItemIndex(activeElement);
Mark Otto's avatar
grunt    
Mark Otto committed
277

Mark Otto's avatar
dist    
Mark Otto committed
278
279
280
281
282
      var lastItemIndex = this._items.length - 1;
      var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;

      if (isGoingToWrap && !this._config.wrap) {
        return activeElement;
fat's avatar
fat committed
283
284
      }

Mark Otto's avatar
dist    
Mark Otto committed
285
286
287
288
      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
289

Mark Otto's avatar
dist    
Mark Otto committed
290
291
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
      var targetIndex = this._getItemIndex(relatedTarget);
fat's avatar
fat committed
292

Mark Otto's avatar
dist    
Mark Otto committed
293
      var fromIndex = this._getItemIndex(this._element.querySelector(Selector.ACTIVE_ITEM));
fat's avatar
fat committed
294

Mark Otto's avatar
dist    
Mark Otto committed
295
296
297
298
299
300
301
302
303
      var slideEvent = $.Event(Event.SLIDE, {
        relatedTarget: relatedTarget,
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
      });
      $(this._element).trigger(slideEvent);
      return slideEvent;
    };
fat's avatar
fat committed
304

Mark Otto's avatar
dist    
Mark Otto committed
305
306
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
Mark Otto's avatar
dist    
Mark Otto committed
307
308
        var indicators = [].slice.call(this._indicatorsElement.querySelectorAll(Selector.ACTIVE));
        $(indicators).removeClass(ClassName.ACTIVE);
fat's avatar
fat committed
309

Mark Otto's avatar
dist    
Mark Otto committed
310
        var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
fat's avatar
fat committed
311

Mark Otto's avatar
dist    
Mark Otto committed
312
313
314
315
316
        if (nextIndicator) {
          $(nextIndicator).addClass(ClassName.ACTIVE);
        }
      }
    };
fat's avatar
fat committed
317

Mark Otto's avatar
dist    
Mark Otto committed
318
319
    _proto._slide = function _slide(direction, element) {
      var _this3 = this;
fat's avatar
fat committed
320

Mark Otto's avatar
dist    
Mark Otto committed
321
      var activeElement = this._element.querySelector(Selector.ACTIVE_ITEM);
fat's avatar
fat committed
322

Mark Otto's avatar
dist    
Mark Otto committed
323
      var activeElementIndex = this._getItemIndex(activeElement);
fat's avatar
fat committed
324

Mark Otto's avatar
dist    
Mark Otto committed
325
      var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
fat's avatar
fat committed
326

Mark Otto's avatar
dist    
Mark Otto committed
327
      var nextElementIndex = this._getItemIndex(nextElement);
fat's avatar
fat committed
328

Mark Otto's avatar
dist    
Mark Otto committed
329
330
331
332
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
333

Mark Otto's avatar
dist    
Mark Otto committed
334
335
336
337
338
339
340
341
342
      if (direction === Direction.NEXT) {
        directionalClassName = ClassName.LEFT;
        orderClassName = ClassName.NEXT;
        eventDirectionName = Direction.LEFT;
      } else {
        directionalClassName = ClassName.RIGHT;
        orderClassName = ClassName.PREV;
        eventDirectionName = Direction.RIGHT;
      }
fat's avatar
fat committed
343

Mark Otto's avatar
dist    
Mark Otto committed
344
345
346
347
      if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
        this._isSliding = false;
        return;
      }
fat's avatar
fat committed
348

Mark Otto's avatar
dist    
Mark Otto committed
349
      var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
fat's avatar
fat committed
350

Mark Otto's avatar
dist    
Mark Otto committed
351
352
      if (slideEvent.isDefaultPrevented()) {
        return;
Mark Otto's avatar
grunt    
Mark Otto committed
353
      }
fat's avatar
fat committed
354

Mark Otto's avatar
dist    
Mark Otto committed
355
      if (!activeElement || !nextElement) {
Mark Otto's avatar
dist    
Mark Otto committed
356
        // Some weirdness is happening, so we bail
Mark Otto's avatar
dist    
Mark Otto committed
357
358
        return;
      }
fat's avatar
fat committed
359

Mark Otto's avatar
dist    
Mark Otto committed
360
      this._isSliding = true;
fat's avatar
fat committed
361

Mark Otto's avatar
dist    
Mark Otto committed
362
363
364
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
365

Mark Otto's avatar
dist    
Mark Otto committed
366
367
368
369
370
371
372
373
374
      this._setActiveIndicatorElement(nextElement);

      var slidEvent = $.Event(Event.SLID, {
        relatedTarget: nextElement,
        direction: eventDirectionName,
        from: activeElementIndex,
        to: nextElementIndex
      });

Mark Otto's avatar
dist    
Mark Otto committed
375
      if ($(this._element).hasClass(ClassName.SLIDE)) {
Mark Otto's avatar
dist    
Mark Otto committed
376
377
378
379
        $(nextElement).addClass(orderClassName);
        Util.reflow(nextElement);
        $(activeElement).addClass(directionalClassName);
        $(nextElement).addClass(directionalClassName);
Mark Otto's avatar
dist    
Mark Otto committed
380
        var transitionDuration = Util.getTransitionDurationFromElement(activeElement);
Mark Otto's avatar
dist    
Mark Otto committed
381
382
383
384
385
386
387
        $(activeElement).one(Util.TRANSITION_END, function () {
          $(nextElement).removeClass(directionalClassName + " " + orderClassName).addClass(ClassName.ACTIVE);
          $(activeElement).removeClass(ClassName.ACTIVE + " " + orderClassName + " " + directionalClassName);
          _this3._isSliding = false;
          setTimeout(function () {
            return $(_this3._element).trigger(slidEvent);
          }, 0);
Mark Otto's avatar
dist    
Mark Otto committed
388
        }).emulateTransitionEnd(transitionDuration);
Mark Otto's avatar
dist    
Mark Otto committed
389
390
391
392
393
394
      } else {
        $(activeElement).removeClass(ClassName.ACTIVE);
        $(nextElement).addClass(ClassName.ACTIVE);
        this._isSliding = false;
        $(this._element).trigger(slidEvent);
      }
fat's avatar
fat committed
395

Mark Otto's avatar
dist    
Mark Otto committed
396
397
      if (isCycling) {
        this.cycle();
Mark Otto's avatar
grunt    
Mark Otto committed
398
      }
Mark Otto's avatar
dist    
Mark Otto committed
399
    }; // Static
fat's avatar
fat committed
400

Mark Otto's avatar
Mark Otto committed
401

Mark Otto's avatar
dist    
Mark Otto committed
402
403
404
    Carousel._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
fat's avatar
fat committed
405

Mark Otto's avatar
dist    
Mark Otto committed
406
        var _config = _objectSpread({}, Default, $(this).data());
Mark Otto's avatar
dist    
Mark Otto committed
407
408

        if (typeof config === 'object') {
Mark Otto's avatar
dist    
Mark Otto committed
409
          _config = _objectSpread({}, _config, config);
Mark Otto's avatar
dist    
Mark Otto committed
410
        }
fat's avatar
fat committed
411

Mark Otto's avatar
dist    
Mark Otto committed
412
        var action = typeof config === 'string' ? config : _config.slide;
fat's avatar
fat committed
413

Mark Otto's avatar
dist    
Mark Otto committed
414
415
416
        if (!data) {
          data = new Carousel(this, _config);
          $(this).data(DATA_KEY, data);
Mark Otto's avatar
dist    
Mark Otto committed
417
        }
Mark Otto's avatar
grunt    
Mark Otto committed
418

Mark Otto's avatar
dist    
Mark Otto committed
419
420
421
422
        if (typeof config === 'number') {
          data.to(config);
        } else if (typeof action === 'string') {
          if (typeof data[action] === 'undefined') {
Mark Otto's avatar
dist    
Mark Otto committed
423
            throw new TypeError("No method named \"" + action + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
424
          }
Mark Otto's avatar
grunt    
Mark Otto committed
425

Mark Otto's avatar
dist    
Mark Otto committed
426
427
428
429
          data[action]();
        } else if (_config.interval) {
          data.pause();
          data.cycle();
Mark Otto's avatar
dist    
Mark Otto committed
430
        }
Mark Otto's avatar
dist    
Mark Otto committed
431
432
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
433

Mark Otto's avatar
dist    
Mark Otto committed
434
435
436
437
438
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
      var selector = Util.getSelectorFromElement(this);

      if (!selector) {
        return;
Mark Otto's avatar
dist    
Mark Otto committed
439
      }
Mark Otto's avatar
dist    
Mark Otto committed
440
441
442
443
444
445
446

      var target = $(selector)[0];

      if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
        return;
      }

Mark Otto's avatar
dist    
Mark Otto committed
447
      var config = _objectSpread({}, $(target).data(), $(this).data());
Mark Otto's avatar
dist    
Mark Otto committed
448

Mark Otto's avatar
dist    
Mark Otto committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
      var slideIndex = this.getAttribute('data-slide-to');

      if (slideIndex) {
        config.interval = false;
      }

      Carousel._jQueryInterface.call($(target), config);

      if (slideIndex) {
        $(target).data(DATA_KEY).to(slideIndex);
      }

      event.preventDefault();
    };

    _createClass(Carousel, null, [{
      key: "VERSION",
Jacob Thornton's avatar
Jacob Thornton committed
466
467
468
469
      get: function get() {
        return VERSION;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
470
      key: "Default",
Jacob Thornton's avatar
Jacob Thornton committed
471
472
473
      get: function get() {
        return Default;
      }
fat's avatar
fat committed
474
475
476
    }]);

    return Carousel;
Mark Otto's avatar
grunt    
Mark Otto committed
477
478
479
480
481
482
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
483
484


Mark Otto's avatar
dist    
Mark Otto committed
485
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
fat's avatar
fat committed
486
  $(window).on(Event.LOAD_DATA_API, function () {
Mark Otto's avatar
dist    
Mark Otto committed
487
488
489
490
    var carousels = [].slice.call(document.querySelectorAll(Selector.DATA_RIDE));

    for (var i = 0, len = carousels.length; i < len; i++) {
      var $carousel = $(carousels[i]);
Mark Otto's avatar
dist    
Mark Otto committed
491

fat's avatar
fat committed
492
      Carousel._jQueryInterface.call($carousel, $carousel.data());
Mark Otto's avatar
dist    
Mark Otto committed
493
    }
Mark Otto's avatar
Mark Otto committed
494
  });
fat's avatar
fat committed
495
496
497
498
499
500
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */

Mark Otto's avatar
Mark Otto committed
501
  $.fn[NAME] = Carousel._jQueryInterface;
fat's avatar
fat committed
502
  $.fn[NAME].Constructor = Carousel;
Mark Otto's avatar
dist    
Mark Otto committed
503

fat's avatar
fat committed
504
505
506
507
508
509
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Carousel._jQueryInterface;
  };

  return Carousel;
Mark Otto's avatar
dist    
Mark Otto committed
510
}($);
Mark Otto's avatar
build    
Mark Otto committed
511
//# sourceMappingURL=carousel.js.map