carousel.js 15.9 KB
Newer Older
Mark Otto's avatar
dist    
Mark Otto committed
1
2
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

Mark Otto's avatar
dist    
Mark Otto committed
3
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
4

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

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

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

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
88
89
90
91
  var Carousel =
  /*#__PURE__*/
  function () {
    function Carousel(element, config) {
fat's avatar
fat committed
92
93
94
95
96
      this._items = null;
      this._interval = null;
      this._activeElement = null;
      this._isPaused = false;
      this._isSliding = false;
Mark Otto's avatar
build    
Mark Otto committed
97
      this.touchTimeout = null;
fat's avatar
fat committed
98
      this._config = this._getConfig(config);
fat's avatar
fat committed
99
100
      this._element = $(element)[0];
      this._indicatorsElement = $(this._element).find(Selector.INDICATORS)[0];
Mark Otto's avatar
dist    
Mark Otto committed
101
      this._transitionDuration = this._getTransitionDuration();
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
135
136
137

      if ($(this._element).find(Selector.NEXT_PREV)[0] && Util.supportsTransitionEnd()) {
        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
162
163
164
165
166
167
    _proto.to = function to(index) {
      var _this = this;

      this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];

      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 = _extends({}, 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
210
211
212
213
214
215
216
217
218
219
220
221
    _proto._getTransitionDuration = function _getTransitionDuration() {
      // Get transition-duration of first element in the carousel
      var transitionDuration = $(this._element).find(Selector.ITEM).css('transition-duration'); // Return 0 carousel item is not found

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


      transitionDuration = transitionDuration.split(',')[0]; // Multiply by 1000 if transition-duration is defined in seconds

      return transitionDuration.indexOf('ms') > -1 ? parseFloat(transitionDuration) : parseFloat(transitionDuration) * MILLISECONDS_MULTIPLIER;
    };

Mark Otto's avatar
dist    
Mark Otto committed
222
223
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
224

Mark Otto's avatar
dist    
Mark Otto committed
225
226
227
228
      if (this._config.keyboard) {
        $(this._element).on(Event.KEYDOWN, function (event) {
          return _this2._keydown(event);
        });
fat's avatar
fat committed
229
      }
fat's avatar
fat committed
230

Mark Otto's avatar
dist    
Mark Otto committed
231
232
233
234
235
236
237
238
      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
239
          // If it's a touch-enabled device, mouseenter/leave are fired as
Mark Otto's avatar
dist    
Mark Otto committed
240
241
242
243
244
245
246
247
248
249
250
251
          // 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
252

Mark Otto's avatar
dist    
Mark Otto committed
253
254
255
            _this2.touchTimeout = setTimeout(function (event) {
              return _this2.cycle(event);
            }, TOUCHEVENT_COMPAT_WAIT + _this2._config.interval);
Mark Otto's avatar
dist    
Mark Otto committed
256
257
          });
        }
fat's avatar
fat committed
258
      }
Mark Otto's avatar
dist    
Mark Otto committed
259
    };
Mark Otto's avatar
dist    
Mark Otto committed
260

Mark Otto's avatar
dist    
Mark Otto committed
261
262
263
    _proto._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
Mark Otto's avatar
grunt    
Mark Otto committed
264
      }
fat's avatar
fat committed
265

Mark Otto's avatar
dist    
Mark Otto committed
266
267
268
269
270
      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
          event.preventDefault();
          this.prev();
          break;
fat's avatar
fat committed
271

Mark Otto's avatar
dist    
Mark Otto committed
272
273
274
275
276
277
        case ARROW_RIGHT_KEYCODE:
          event.preventDefault();
          this.next();
          break;

        default:
Mark Otto's avatar
dist    
Mark Otto committed
278
      }
Mark Otto's avatar
dist    
Mark Otto committed
279
    };
fat's avatar
fat committed
280

Mark Otto's avatar
dist    
Mark Otto committed
281
282
283
284
    _proto._getItemIndex = function _getItemIndex(element) {
      this._items = $.makeArray($(element).parent().find(Selector.ITEM));
      return this._items.indexOf(element);
    };
fat's avatar
fat committed
285

Mark Otto's avatar
dist    
Mark Otto committed
286
287
288
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
      var isNextDirection = direction === Direction.NEXT;
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
grunt    
Mark Otto committed
289

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

Mark Otto's avatar
dist    
Mark Otto committed
292
293
294
295
296
      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
297
298
      }

Mark Otto's avatar
dist    
Mark Otto committed
299
300
301
302
      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
303

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

Mark Otto's avatar
dist    
Mark Otto committed
307
      var fromIndex = this._getItemIndex($(this._element).find(Selector.ACTIVE_ITEM)[0]);
fat's avatar
fat committed
308

Mark Otto's avatar
dist    
Mark Otto committed
309
310
311
312
313
314
315
316
317
      var slideEvent = $.Event(Event.SLIDE, {
        relatedTarget: relatedTarget,
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
      });
      $(this._element).trigger(slideEvent);
      return slideEvent;
    };
fat's avatar
fat committed
318

Mark Otto's avatar
dist    
Mark Otto committed
319
320
321
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
        $(this._indicatorsElement).find(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
fat's avatar
fat committed
322

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

Mark Otto's avatar
dist    
Mark Otto committed
325
326
327
328
329
        if (nextIndicator) {
          $(nextIndicator).addClass(ClassName.ACTIVE);
        }
      }
    };
fat's avatar
fat committed
330

Mark Otto's avatar
dist    
Mark Otto committed
331
332
    _proto._slide = function _slide(direction, element) {
      var _this3 = this;
fat's avatar
fat committed
333

Mark Otto's avatar
dist    
Mark Otto committed
334
      var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
fat's avatar
fat committed
335

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

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

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

Mark Otto's avatar
dist    
Mark Otto committed
342
343
344
345
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
346

Mark Otto's avatar
dist    
Mark Otto committed
347
348
349
350
351
352
353
354
355
      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
356

Mark Otto's avatar
dist    
Mark Otto committed
357
358
359
360
      if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
        this._isSliding = false;
        return;
      }
fat's avatar
fat committed
361

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

Mark Otto's avatar
dist    
Mark Otto committed
364
365
      if (slideEvent.isDefaultPrevented()) {
        return;
Mark Otto's avatar
grunt    
Mark Otto committed
366
      }
fat's avatar
fat committed
367

Mark Otto's avatar
dist    
Mark Otto committed
368
      if (!activeElement || !nextElement) {
Mark Otto's avatar
dist    
Mark Otto committed
369
        // Some weirdness is happening, so we bail
Mark Otto's avatar
dist    
Mark Otto committed
370
371
        return;
      }
fat's avatar
fat committed
372

Mark Otto's avatar
dist    
Mark Otto committed
373
      this._isSliding = true;
fat's avatar
fat committed
374

Mark Otto's avatar
dist    
Mark Otto committed
375
376
377
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
378

Mark Otto's avatar
dist    
Mark Otto committed
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
      this._setActiveIndicatorElement(nextElement);

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

      if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) {
        $(nextElement).addClass(orderClassName);
        Util.reflow(nextElement);
        $(activeElement).addClass(directionalClassName);
        $(nextElement).addClass(directionalClassName);
        $(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
400
        }).emulateTransitionEnd(this._transitionDuration);
Mark Otto's avatar
dist    
Mark Otto committed
401
402
403
404
405
406
      } else {
        $(activeElement).removeClass(ClassName.ACTIVE);
        $(nextElement).addClass(ClassName.ACTIVE);
        this._isSliding = false;
        $(this._element).trigger(slidEvent);
      }
fat's avatar
fat committed
407

Mark Otto's avatar
dist    
Mark Otto committed
408
409
      if (isCycling) {
        this.cycle();
Mark Otto's avatar
grunt    
Mark Otto committed
410
      }
Mark Otto's avatar
dist    
Mark Otto committed
411
    }; // Static
fat's avatar
fat committed
412

Mark Otto's avatar
Mark Otto committed
413

Mark Otto's avatar
dist    
Mark Otto committed
414
415
416
    Carousel._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
fat's avatar
fat committed
417

Mark Otto's avatar
dist    
Mark Otto committed
418
        var _config = _extends({}, Default, $(this).data());
Mark Otto's avatar
dist    
Mark Otto committed
419
420

        if (typeof config === 'object') {
Mark Otto's avatar
dist    
Mark Otto committed
421
          _config = _extends({}, _config, config);
Mark Otto's avatar
dist    
Mark Otto committed
422
        }
fat's avatar
fat committed
423

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

Mark Otto's avatar
dist    
Mark Otto committed
426
427
428
        if (!data) {
          data = new Carousel(this, _config);
          $(this).data(DATA_KEY, data);
Mark Otto's avatar
dist    
Mark Otto committed
429
        }
Mark Otto's avatar
grunt    
Mark Otto committed
430

Mark Otto's avatar
dist    
Mark Otto committed
431
432
433
434
        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
435
            throw new TypeError("No method named \"" + action + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
436
          }
Mark Otto's avatar
grunt    
Mark Otto committed
437

Mark Otto's avatar
dist    
Mark Otto committed
438
439
440
441
          data[action]();
        } else if (_config.interval) {
          data.pause();
          data.cycle();
Mark Otto's avatar
dist    
Mark Otto committed
442
        }
Mark Otto's avatar
dist    
Mark Otto committed
443
444
      });
    };
Mark Otto's avatar
grunt    
Mark Otto committed
445

Mark Otto's avatar
dist    
Mark Otto committed
446
447
448
449
450
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
      var selector = Util.getSelectorFromElement(this);

      if (!selector) {
        return;
Mark Otto's avatar
dist    
Mark Otto committed
451
      }
Mark Otto's avatar
dist    
Mark Otto committed
452
453
454
455
456
457
458

      var target = $(selector)[0];

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

Mark Otto's avatar
dist    
Mark Otto committed
459
460
      var config = _extends({}, $(target).data(), $(this).data());

Mark Otto's avatar
dist    
Mark Otto committed
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
      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
478
479
480
481
      get: function get() {
        return VERSION;
      }
    }, {
Mark Otto's avatar
dist    
Mark Otto committed
482
      key: "Default",
Jacob Thornton's avatar
Jacob Thornton committed
483
484
485
      get: function get() {
        return Default;
      }
fat's avatar
fat committed
486
487
488
    }]);

    return Carousel;
Mark Otto's avatar
grunt    
Mark Otto committed
489
490
491
492
493
494
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
495
496


Mark Otto's avatar
dist    
Mark Otto committed
497
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
fat's avatar
fat committed
498
  $(window).on(Event.LOAD_DATA_API, function () {
fat's avatar
fat committed
499
500
    $(Selector.DATA_RIDE).each(function () {
      var $carousel = $(this);
Mark Otto's avatar
dist    
Mark Otto committed
501

fat's avatar
fat committed
502
503
      Carousel._jQueryInterface.call($carousel, $carousel.data());
    });
Mark Otto's avatar
Mark Otto committed
504
  });
fat's avatar
fat committed
505
506
507
508
509
510
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */

Mark Otto's avatar
Mark Otto committed
511
  $.fn[NAME] = Carousel._jQueryInterface;
fat's avatar
fat committed
512
  $.fn[NAME].Constructor = Carousel;
Mark Otto's avatar
dist    
Mark Otto committed
513

fat's avatar
fat committed
514
515
516
517
518
519
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Carousel._jQueryInterface;
  };

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