carousel.js 15.6 KB
Newer Older
Mark Otto's avatar
grunt    
Mark Otto committed
1
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
fat's avatar
fat committed
2

Mark Otto's avatar
grunt    
Mark Otto committed
3
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
fat's avatar
fat committed
4

Mark Otto's avatar
grunt    
Mark Otto committed
5
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
fat's avatar
fat committed
6
7
8

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
9
 * Bootstrap (v4.0.0-beta): carousel.js
fat's avatar
fat committed
10
11
12
13
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

Mark Otto's avatar
grunt    
Mark Otto committed
14
var Carousel = function ($) {
fat's avatar
fat committed
15
16
17
18
19
20
21
22

  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'carousel';
Mark Otto's avatar
Mark Otto committed
23
  var VERSION = '4.0.0-beta';
fat's avatar
fat committed
24
  var DATA_KEY = 'bs.carousel';
fat's avatar
fat committed
25
26
  var EVENT_KEY = '.' + DATA_KEY;
  var DATA_API_KEY = '.data-api';
fat's avatar
fat committed
27
28
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  var TRANSITION_DURATION = 600;
Chris Rebert's avatar
grunt    
Chris Rebert committed
29
30
  var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key
  var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key
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
40
  };

fat's avatar
fat committed
41
42
43
44
  var DefaultType = {
    interval: '(number|boolean)',
    keyboard: 'boolean',
    slide: '(boolean|string)',
45
    pause: '(string|boolean)',
fat's avatar
fat committed
46
47
48
    wrap: 'boolean'
  };

fat's avatar
fat committed
49
50
  var Direction = {
    NEXT: 'next',
Mark Otto's avatar
grunt    
Mark Otto committed
51
52
53
    PREV: 'prev',
    LEFT: 'left',
    RIGHT: 'right'
fat's avatar
fat committed
54
55
56
  };

  var Event = {
fat's avatar
fat committed
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,
Mark Otto's avatar
build    
Mark Otto committed
62
    TOUCHEND: 'touchend' + EVENT_KEY,
Jacob Thornton's avatar
Jacob Thornton committed
63
64
    LOAD_DATA_API: 'load' + EVENT_KEY + DATA_API_KEY,
    CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
fat's avatar
fat committed
65
66
67
68
69
70
  };

  var ClassName = {
    CAROUSEL: 'carousel',
    ACTIVE: 'active',
    SLIDE: 'slide',
Mark Otto's avatar
grunt    
Mark Otto committed
71
72
73
74
    RIGHT: 'carousel-item-right',
    LEFT: 'carousel-item-left',
    NEXT: 'carousel-item-next',
    PREV: 'carousel-item-prev',
fat's avatar
fat committed
75
76
77
78
79
80
81
    ITEM: 'carousel-item'
  };

  var Selector = {
    ACTIVE: '.active',
    ACTIVE_ITEM: '.active.carousel-item',
    ITEM: '.carousel-item',
Mark Otto's avatar
grunt    
Mark Otto committed
82
    NEXT_PREV: '.carousel-item-next, .carousel-item-prev',
fat's avatar
fat committed
83
84
85
86
    INDICATORS: '.carousel-indicators',
    DATA_SLIDE: '[data-slide], [data-slide-to]',
    DATA_RIDE: '[data-ride="carousel"]'

Mark Otto's avatar
dist    
Mark Otto committed
87
88
89
90
91
    /**
     * ------------------------------------------------------------------------
     * Class Definition
     * ------------------------------------------------------------------------
     */
fat's avatar
fat committed
92

Mark Otto's avatar
dist    
Mark Otto committed
93
  };
Mark Otto's avatar
grunt    
Mark Otto committed
94
  var Carousel = function () {
fat's avatar
fat committed
95
96
97
98
99
100
101
102
103
104
    function Carousel(element, config) {
      _classCallCheck(this, Carousel);

      this._items = null;
      this._interval = null;
      this._activeElement = null;

      this._isPaused = false;
      this._isSliding = false;

Mark Otto's avatar
build    
Mark Otto committed
105
106
      this.touchTimeout = null;

fat's avatar
fat committed
107
      this._config = this._getConfig(config);
fat's avatar
fat committed
108
109
110
111
112
113
      this._element = $(element)[0];
      this._indicatorsElement = $(this._element).find(Selector.INDICATORS)[0];

      this._addEventListeners();
    }

Jacob Thornton's avatar
Jacob Thornton committed
114
115
    // getters

Mark Otto's avatar
grunt    
Mark Otto committed
116
    // public
fat's avatar
fat committed
117

Mark Otto's avatar
grunt    
Mark Otto committed
118
    Carousel.prototype.next = function next() {
Mark Otto's avatar
grunt    
Mark Otto committed
119
120
      if (!this._isSliding) {
        this._slide(Direction.NEXT);
Mark Otto's avatar
grunt    
Mark Otto committed
121
122
      }
    };
fat's avatar
fat committed
123

Mark Otto's avatar
grunt    
Mark Otto committed
124
125
    Carousel.prototype.nextWhenVisible = function nextWhenVisible() {
      // Don't call next when the page isn't visible
Mark Otto's avatar
dist    
Mark Otto committed
126
127
      // or the carousel or its parent isn't visible
      if (!document.hidden && $(this._element).is(':visible') && $(this._element).css('visibility') !== 'hidden') {
Mark Otto's avatar
grunt    
Mark Otto committed
128
        this.next();
fat's avatar
fat committed
129
      }
Mark Otto's avatar
grunt    
Mark Otto committed
130
131
132
    };

    Carousel.prototype.prev = function prev() {
Mark Otto's avatar
grunt    
Mark Otto committed
133
134
      if (!this._isSliding) {
        this._slide(Direction.PREV);
XhmikosR's avatar
XhmikosR committed
135
      }
Mark Otto's avatar
grunt    
Mark Otto committed
136
137
138
139
140
    };

    Carousel.prototype.pause = function pause(event) {
      if (!event) {
        this._isPaused = true;
fat's avatar
fat committed
141
142
      }

Mark Otto's avatar
grunt    
Mark Otto committed
143
144
145
146
      if ($(this._element).find(Selector.NEXT_PREV)[0] && Util.supportsTransitionEnd()) {
        Util.triggerTransitionEnd(this._element);
        this.cycle(true);
      }
fat's avatar
fat committed
147

Mark Otto's avatar
grunt    
Mark Otto committed
148
149
150
151
152
153
154
155
156
157
      clearInterval(this._interval);
      this._interval = null;
    };

    Carousel.prototype.cycle = function cycle(event) {
      if (!event) {
        this._isPaused = false;
      }

      if (this._interval) {
fat's avatar
fat committed
158
159
160
161
        clearInterval(this._interval);
        this._interval = null;
      }

Mark Otto's avatar
grunt    
Mark Otto committed
162
      if (this._config.interval && !this._isPaused) {
Mark Otto's avatar
grunt    
Mark Otto committed
163
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
Mark Otto's avatar
grunt    
Mark Otto committed
164
165
      }
    };
fat's avatar
fat committed
166

Mark Otto's avatar
grunt    
Mark Otto committed
167
168
169
170
171
172
173
174
175
    Carousel.prototype.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;
fat's avatar
fat committed
176
177
      }

Mark Otto's avatar
grunt    
Mark Otto committed
178
179
180
181
182
183
      if (this._isSliding) {
        $(this._element).one(Event.SLID, function () {
          return _this.to(index);
        });
        return;
      }
fat's avatar
fat committed
184

Mark Otto's avatar
grunt    
Mark Otto committed
185
186
187
188
189
      if (activeIndex === index) {
        this.pause();
        this.cycle();
        return;
      }
fat's avatar
fat committed
190

Mark Otto's avatar
grunt    
Mark Otto committed
191
      var direction = index > activeIndex ? Direction.NEXT : Direction.PREV;
fat's avatar
fat committed
192

Mark Otto's avatar
grunt    
Mark Otto committed
193
194
      this._slide(direction, this._items[index]);
    };
fat's avatar
fat committed
195

Mark Otto's avatar
grunt    
Mark Otto committed
196
197
198
    Carousel.prototype.dispose = function dispose() {
      $(this._element).off(EVENT_KEY);
      $.removeData(this._element, DATA_KEY);
fat's avatar
fat committed
199

Mark Otto's avatar
grunt    
Mark Otto committed
200
201
202
203
204
205
206
207
208
      this._items = null;
      this._config = null;
      this._element = null;
      this._interval = null;
      this._isPaused = null;
      this._isSliding = null;
      this._activeElement = null;
      this._indicatorsElement = null;
    };
fat's avatar
fat committed
209

Mark Otto's avatar
grunt    
Mark Otto committed
210
    // private
fat's avatar
fat committed
211

Mark Otto's avatar
grunt    
Mark Otto committed
212
213
214
215
216
    Carousel.prototype._getConfig = function _getConfig(config) {
      config = $.extend({}, Default, config);
      Util.typeCheckConfig(NAME, config, DefaultType);
      return config;
    };
fat's avatar
fat committed
217

Mark Otto's avatar
grunt    
Mark Otto committed
218
    Carousel.prototype._addEventListeners = function _addEventListeners() {
Mark Otto's avatar
grunt    
Mark Otto committed
219
220
      var _this2 = this;

Mark Otto's avatar
grunt    
Mark Otto committed
221
      if (this._config.keyboard) {
Mark Otto's avatar
grunt    
Mark Otto committed
222
223
224
        $(this._element).on(Event.KEYDOWN, function (event) {
          return _this2._keydown(event);
        });
fat's avatar
fat committed
225
      }
fat's avatar
fat committed
226

Mark Otto's avatar
build    
Mark Otto committed
227
      if (this._config.pause === 'hover') {
Mark Otto's avatar
grunt    
Mark Otto committed
228
229
230
231
232
        $(this._element).on(Event.MOUSEENTER, function (event) {
          return _this2.pause(event);
        }).on(Event.MOUSELEAVE, function (event) {
          return _this2.cycle(event);
        });
Mark Otto's avatar
build    
Mark Otto committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
        if ('ontouchstart' in document.documentElement) {
          // 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
          $(this._element).on(Event.TOUCHEND, function () {
            _this2.pause();
            if (_this2.touchTimeout) {
              clearTimeout(_this2.touchTimeout);
            }
            _this2.touchTimeout = setTimeout(function (event) {
              return _this2.cycle(event);
            }, TOUCHEVENT_COMPAT_WAIT + _this2._config.interval);
          });
        }
fat's avatar
fat committed
251
      }
Mark Otto's avatar
grunt    
Mark Otto committed
252
    };
fat's avatar
fat committed
253

Mark Otto's avatar
grunt    
Mark Otto committed
254
255
256
    Carousel.prototype._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
fat's avatar
fat committed
257
      }
Mark Otto's avatar
grunt    
Mark Otto committed
258
259
260

      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
Mark Otto's avatar
grunt    
Mark Otto committed
261
          event.preventDefault();
Mark Otto's avatar
grunt    
Mark Otto committed
262
263
264
          this.prev();
          break;
        case ARROW_RIGHT_KEYCODE:
Mark Otto's avatar
grunt    
Mark Otto committed
265
          event.preventDefault();
Mark Otto's avatar
grunt    
Mark Otto committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
          this.next();
          break;
        default:
          return;
      }
    };

    Carousel.prototype._getItemIndex = function _getItemIndex(element) {
      this._items = $.makeArray($(element).parent().find(Selector.ITEM));
      return this._items.indexOf(element);
    };

    Carousel.prototype._getItemByDirection = function _getItemByDirection(direction, activeElement) {
      var isNextDirection = direction === Direction.NEXT;
Mark Otto's avatar
grunt    
Mark Otto committed
280
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
grunt    
Mark Otto committed
281
282
283
284
285
286
      var activeIndex = this._getItemIndex(activeElement);
      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
287
288
      }

Mark Otto's avatar
grunt    
Mark Otto committed
289
      var delta = direction === Direction.PREV ? -1 : 1;
Mark Otto's avatar
grunt    
Mark Otto committed
290
      var itemIndex = (activeIndex + delta) % this._items.length;
fat's avatar
fat committed
291

Mark Otto's avatar
grunt    
Mark Otto committed
292
293
      return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
    };
fat's avatar
fat committed
294

Mark Otto's avatar
grunt    
Mark Otto committed
295
    Carousel.prototype._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
Mark Otto's avatar
grunt    
Mark Otto committed
296
297
      var targetIndex = this._getItemIndex(relatedTarget);
      var fromIndex = this._getItemIndex($(this._element).find(Selector.ACTIVE_ITEM)[0]);
Mark Otto's avatar
grunt    
Mark Otto committed
298
299
      var slideEvent = $.Event(Event.SLIDE, {
        relatedTarget: relatedTarget,
Mark Otto's avatar
grunt    
Mark Otto committed
300
301
302
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
Mark Otto's avatar
grunt    
Mark Otto committed
303
      });
fat's avatar
fat committed
304

Mark Otto's avatar
grunt    
Mark Otto committed
305
      $(this._element).trigger(slideEvent);
fat's avatar
fat committed
306

Mark Otto's avatar
grunt    
Mark Otto committed
307
308
      return slideEvent;
    };
fat's avatar
fat committed
309

Mark Otto's avatar
grunt    
Mark Otto committed
310
311
312
313
314
315
316
317
    Carousel.prototype._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
        $(this._indicatorsElement).find(Selector.ACTIVE).removeClass(ClassName.ACTIVE);

        var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];

        if (nextIndicator) {
          $(nextIndicator).addClass(ClassName.ACTIVE);
fat's avatar
fat committed
318
319
        }
      }
Mark Otto's avatar
grunt    
Mark Otto committed
320
    };
fat's avatar
fat committed
321

Mark Otto's avatar
grunt    
Mark Otto committed
322
    Carousel.prototype._slide = function _slide(direction, element) {
Mark Otto's avatar
grunt    
Mark Otto committed
323
      var _this3 = this;
fat's avatar
fat committed
324

Mark Otto's avatar
grunt    
Mark Otto committed
325
      var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
Mark Otto's avatar
grunt    
Mark Otto committed
326
      var activeElementIndex = this._getItemIndex(activeElement);
Mark Otto's avatar
grunt    
Mark Otto committed
327
      var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
Mark Otto's avatar
grunt    
Mark Otto committed
328
      var nextElementIndex = this._getItemIndex(nextElement);
Mark Otto's avatar
grunt    
Mark Otto committed
329
      var isCycling = Boolean(this._interval);
fat's avatar
fat committed
330

Mark Otto's avatar
grunt    
Mark Otto committed
331
332
333
334
335
336
337
338
339
340
341
342
343
      var directionalClassName = void 0;
      var orderClassName = void 0;
      var eventDirectionName = void 0;

      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
344

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

Mark Otto's avatar
grunt    
Mark Otto committed
350
      var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
Mark Otto's avatar
grunt    
Mark Otto committed
351
352
353
      if (slideEvent.isDefaultPrevented()) {
        return;
      }
fat's avatar
fat committed
354

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
366
      this._setActiveIndicatorElement(nextElement);
fat's avatar
fat committed
367

Mark Otto's avatar
grunt    
Mark Otto committed
368
369
      var slidEvent = $.Event(Event.SLID, {
        relatedTarget: nextElement,
Mark Otto's avatar
grunt    
Mark Otto committed
370
371
372
        direction: eventDirectionName,
        from: activeElementIndex,
        to: nextElementIndex
Mark Otto's avatar
grunt    
Mark Otto committed
373
      });
fat's avatar
fat committed
374

Mark Otto's avatar
grunt    
Mark Otto committed
375
      if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) {
fat's avatar
fat committed
376

Mark Otto's avatar
grunt    
Mark Otto committed
377
        $(nextElement).addClass(orderClassName);
fat's avatar
fat committed
378

Mark Otto's avatar
grunt    
Mark Otto committed
379
        Util.reflow(nextElement);
fat's avatar
fat committed
380

Mark Otto's avatar
grunt    
Mark Otto committed
381
382
        $(activeElement).addClass(directionalClassName);
        $(nextElement).addClass(directionalClassName);
fat's avatar
fat committed
383

Mark Otto's avatar
grunt    
Mark Otto committed
384
        $(activeElement).one(Util.TRANSITION_END, function () {
Mark Otto's avatar
grunt    
Mark Otto committed
385
          $(nextElement).removeClass(directionalClassName + ' ' + orderClassName).addClass(ClassName.ACTIVE);
fat's avatar
fat committed
386

Mark Otto's avatar
grunt    
Mark Otto committed
387
          $(activeElement).removeClass(ClassName.ACTIVE + ' ' + orderClassName + ' ' + directionalClassName);
fat's avatar
fat committed
388

Mark Otto's avatar
grunt    
Mark Otto committed
389
          _this3._isSliding = false;
fat's avatar
fat committed
390

Mark Otto's avatar
grunt    
Mark Otto committed
391
          setTimeout(function () {
Mark Otto's avatar
grunt    
Mark Otto committed
392
            return $(_this3._element).trigger(slidEvent);
Mark Otto's avatar
grunt    
Mark Otto committed
393
394
395
396
397
          }, 0);
        }).emulateTransitionEnd(TRANSITION_DURATION);
      } else {
        $(activeElement).removeClass(ClassName.ACTIVE);
        $(nextElement).addClass(ClassName.ACTIVE);
fat's avatar
fat committed
398

Mark Otto's avatar
grunt    
Mark Otto committed
399
400
        this._isSliding = false;
        $(this._element).trigger(slidEvent);
fat's avatar
fat committed
401
402
      }

Mark Otto's avatar
grunt    
Mark Otto committed
403
404
405
406
      if (isCycling) {
        this.cycle();
      }
    };
fat's avatar
fat committed
407

Mark Otto's avatar
grunt    
Mark Otto committed
408
    // static
fat's avatar
fat committed
409

Mark Otto's avatar
grunt    
Mark Otto committed
410
411
412
413
    Carousel._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
        var _config = $.extend({}, Default, $(this).data());
fat's avatar
fat committed
414

Mark Otto's avatar
grunt    
Mark Otto committed
415
416
417
        if ((typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object') {
          $.extend(_config, config);
        }
fat's avatar
fat committed
418

Mark Otto's avatar
grunt    
Mark Otto committed
419
        var action = typeof config === 'string' ? config : _config.slide;
fat's avatar
fat committed
420

Mark Otto's avatar
grunt    
Mark Otto committed
421
422
423
424
        if (!data) {
          data = new Carousel(this, _config);
          $(this).data(DATA_KEY, data);
        }
fat's avatar
fat committed
425

Mark Otto's avatar
grunt    
Mark Otto committed
426
427
428
429
430
431
432
433
434
435
        if (typeof config === 'number') {
          data.to(config);
        } else if (typeof action === 'string') {
          if (data[action] === undefined) {
            throw new Error('No method named "' + action + '"');
          }
          data[action]();
        } else if (_config.interval) {
          data.pause();
          data.cycle();
fat's avatar
fat committed
436
        }
Mark Otto's avatar
grunt    
Mark Otto committed
437
438
      });
    };
fat's avatar
fat committed
439

Mark Otto's avatar
grunt    
Mark Otto committed
440
441
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
      var selector = Util.getSelectorFromElement(this);
fat's avatar
fat committed
442

Mark Otto's avatar
grunt    
Mark Otto committed
443
444
445
      if (!selector) {
        return;
      }
fat's avatar
fat committed
446

Mark Otto's avatar
grunt    
Mark Otto committed
447
      var target = $(selector)[0];
Mark Otto's avatar
Mark Otto committed
448

Mark Otto's avatar
grunt    
Mark Otto committed
449
450
451
      if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
        return;
      }
fat's avatar
fat committed
452

Mark Otto's avatar
grunt    
Mark Otto committed
453
454
      var config = $.extend({}, $(target).data(), $(this).data());
      var slideIndex = this.getAttribute('data-slide-to');
fat's avatar
fat committed
455

Mark Otto's avatar
grunt    
Mark Otto committed
456
457
458
      if (slideIndex) {
        config.interval = false;
      }
fat's avatar
fat committed
459

Mark Otto's avatar
grunt    
Mark Otto committed
460
461
462
463
      Carousel._jQueryInterface.call($(target), config);

      if (slideIndex) {
        $(target).data(DATA_KEY).to(slideIndex);
fat's avatar
fat committed
464
      }
Mark Otto's avatar
grunt    
Mark Otto committed
465
466
467
468
469

      event.preventDefault();
    };

    _createClass(Carousel, null, [{
Jacob Thornton's avatar
Jacob Thornton committed
470
471
472
473
474
475
476
477
478
      key: 'VERSION',
      get: function get() {
        return VERSION;
      }
    }, {
      key: 'Default',
      get: function get() {
        return Default;
      }
fat's avatar
fat committed
479
480
481
    }]);

    return Carousel;
Mark Otto's avatar
grunt    
Mark Otto committed
482
483
484
485
486
487
488
  }();

  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
fat's avatar
fat committed
489

fat's avatar
fat committed
490
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
fat's avatar
fat committed
491

fat's avatar
fat committed
492
  $(window).on(Event.LOAD_DATA_API, function () {
fat's avatar
fat committed
493
494
495
496
    $(Selector.DATA_RIDE).each(function () {
      var $carousel = $(this);
      Carousel._jQueryInterface.call($carousel, $carousel.data());
    });
Mark Otto's avatar
Mark Otto committed
497
  });
fat's avatar
fat committed
498
499
500
501
502
503
504

  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */

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

  return Carousel;
Mark Otto's avatar
grunt    
Mark Otto committed
513
}(jQuery);
Mark Otto's avatar
build    
Mark Otto committed
514
//# sourceMappingURL=carousel.js.map