carousel.js 15.5 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-alpha.6): 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-alpha.6';
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
    INDICATORS: '.carousel-indicators',
    DATA_SLIDE: '[data-slide], [data-slide-to]',
    DATA_RIDE: '[data-ride="carousel"]'
Mark Otto's avatar
Mark Otto committed
86
  };
fat's avatar
fat committed
87

Mark Otto's avatar
Mark Otto committed
88
89
90
91
92
  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */
fat's avatar
fat 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
126
127
    Carousel.prototype.nextWhenVisible = function nextWhenVisible() {
      // Don't call next when the page isn't visible
      if (!document.hidden) {
        this.next();
fat's avatar
fat committed
128
      }
Mark Otto's avatar
grunt    
Mark Otto committed
129
130
131
    };

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
147
148
149
150
151
152
153
154
155
156
      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
157
158
159
160
        clearInterval(this._interval);
        this._interval = null;
      }

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

Mark Otto's avatar
grunt    
Mark Otto committed
166
167
168
169
170
171
172
173
174
    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
175
176
      }

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

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

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
199
200
201
202
203
204
205
206
207
      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
208

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

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

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

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

Mark Otto's avatar
build    
Mark Otto committed
226
      if (this._config.pause === 'hover') {
Mark Otto's avatar
grunt    
Mark Otto committed
227
228
229
230
231
        $(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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
        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
250
      }
Mark Otto's avatar
grunt    
Mark Otto committed
251
    };
fat's avatar
fat committed
252

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

      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
Mark Otto's avatar
grunt    
Mark Otto committed
260
          event.preventDefault();
Mark Otto's avatar
grunt    
Mark Otto committed
261
262
263
          this.prev();
          break;
        case ARROW_RIGHT_KEYCODE:
Mark Otto's avatar
grunt    
Mark Otto committed
264
          event.preventDefault();
Mark Otto's avatar
grunt    
Mark Otto committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
          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
279
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
grunt    
Mark Otto committed
280
281
282
283
284
285
      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
286
287
      }

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

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

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
309
310
311
312
313
314
315
316
    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
317
318
        }
      }
Mark Otto's avatar
grunt    
Mark Otto committed
319
    };
fat's avatar
fat committed
320

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
330
331
332
333
334
335
336
337
338
339
340
341
342
      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
343

Mark Otto's avatar
grunt    
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
grunt    
Mark Otto committed
349
      var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
Mark Otto's avatar
grunt    
Mark Otto committed
350
351
352
      if (slideEvent.isDefaultPrevented()) {
        return;
      }
fat's avatar
fat committed
353

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
409
410
411
412
    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
413

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

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

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

Mark Otto's avatar
grunt    
Mark Otto committed
425
426
427
428
429
430
431
432
433
434
        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
435
        }
Mark Otto's avatar
grunt    
Mark Otto committed
436
437
      });
    };
fat's avatar
fat committed
438

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

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

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

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

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

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

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

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

      event.preventDefault();
    };

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

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

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

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

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

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

Mark Otto's avatar
Mark Otto committed
504
  $.fn[NAME] = Carousel._jQueryInterface;
fat's avatar
fat committed
505
506
507
508
509
510
511
  $.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
512
}(jQuery);
Mark Otto's avatar
build    
Mark Otto committed
513
//# sourceMappingURL=carousel.js.map