Passed
Pull Request — master (#45)
by
unknown
02:56
created

carousel.js ➔ _defineProperties   A

Complexity

Conditions 3

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 1
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
/*!
2
  * Bootstrap carousel.js v4.5.3 (https://getbootstrap.com/)
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.jQuery, global.Util));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
}(this, (function ($, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
16
17
  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); }
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 17 as a function. While this will work, it can be very confusing.
Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
18
19
  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); } }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
21
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
  /**
23
   * ------------------------------------------------------------------------
24
   * Constants
25
   * ------------------------------------------------------------------------
26
   */
27
28
  var NAME = 'carousel';
29
  var VERSION = '4.5.3';
30
  var DATA_KEY = 'bs.carousel';
31
  var EVENT_KEY = "." + DATA_KEY;
32
  var DATA_API_KEY = '.data-api';
33
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
34
  var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key
35
36
  var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key
37
38
  var TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch
39
40
  var SWIPE_THRESHOLD = 40;
41
  var Default = {
42
    interval: 5000,
43
    keyboard: true,
44
    slide: false,
45
    pause: 'hover',
46
    wrap: true,
47
    touch: true
48
  };
49
  var DefaultType = {
50
    interval: '(number|boolean)',
51
    keyboard: 'boolean',
52
    slide: '(boolean|string)',
53
    pause: '(string|boolean)',
54
    wrap: 'boolean',
55
    touch: 'boolean'
56
  };
57
  var DIRECTION_NEXT = 'next';
58
  var DIRECTION_PREV = 'prev';
59
  var DIRECTION_LEFT = 'left';
60
  var DIRECTION_RIGHT = 'right';
61
  var EVENT_SLIDE = "slide" + EVENT_KEY;
62
  var EVENT_SLID = "slid" + EVENT_KEY;
63
  var EVENT_KEYDOWN = "keydown" + EVENT_KEY;
64
  var EVENT_MOUSEENTER = "mouseenter" + EVENT_KEY;
65
  var EVENT_MOUSELEAVE = "mouseleave" + EVENT_KEY;
66
  var EVENT_TOUCHSTART = "touchstart" + EVENT_KEY;
67
  var EVENT_TOUCHMOVE = "touchmove" + EVENT_KEY;
68
  var EVENT_TOUCHEND = "touchend" + EVENT_KEY;
69
  var EVENT_POINTERDOWN = "pointerdown" + EVENT_KEY;
70
  var EVENT_POINTERUP = "pointerup" + EVENT_KEY;
71
  var EVENT_DRAG_START = "dragstart" + EVENT_KEY;
72
  var EVENT_LOAD_DATA_API = "load" + EVENT_KEY + DATA_API_KEY;
73
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
74
  var CLASS_NAME_CAROUSEL = 'carousel';
75
  var CLASS_NAME_ACTIVE = 'active';
76
  var CLASS_NAME_SLIDE = 'slide';
77
  var CLASS_NAME_RIGHT = 'carousel-item-right';
78
  var CLASS_NAME_LEFT = 'carousel-item-left';
79
  var CLASS_NAME_NEXT = 'carousel-item-next';
80
  var CLASS_NAME_PREV = 'carousel-item-prev';
81
  var CLASS_NAME_POINTER_EVENT = 'pointer-event';
82
  var SELECTOR_ACTIVE = '.active';
83
  var SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
84
  var SELECTOR_ITEM = '.carousel-item';
85
  var SELECTOR_ITEM_IMG = '.carousel-item img';
86
  var SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
87
  var SELECTOR_INDICATORS = '.carousel-indicators';
88
  var SELECTOR_DATA_SLIDE = '[data-slide], [data-slide-to]';
89
  var SELECTOR_DATA_RIDE = '[data-ride="carousel"]';
90
  var PointerType = {
91
    TOUCH: 'touch',
92
    PEN: 'pen'
93
  };
94
  /**
95
   * ------------------------------------------------------------------------
96
   * Class Definition
97
   * ------------------------------------------------------------------------
98
   */
99
100
  var Carousel = /*#__PURE__*/function () {
101
    function Carousel(element, config) {
102
      this._items = null;
103
      this._interval = null;
104
      this._activeElement = null;
105
      this._isPaused = false;
106
      this._isSliding = false;
107
      this.touchTimeout = null;
108
      this.touchStartX = 0;
109
      this.touchDeltaX = 0;
110
      this._config = this._getConfig(config);
111
      this._element = element;
112
      this._indicatorsElement = this._element.querySelector(SELECTOR_INDICATORS);
113
      this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
114
      this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent);
115
116
      this._addEventListeners();
117
    } // Getters
118
119
120
    var _proto = Carousel.prototype;
121
122
    // Public
123
    _proto.next = function next() {
124
      if (!this._isSliding) {
125
        this._slide(DIRECTION_NEXT);
126
      }
127
    };
128
129
    _proto.nextWhenVisible = function nextWhenVisible() {
130
      var $element = $__default['default'](this._element); // Don't call next when the page isn't visible
131
      // or the carousel or its parent isn't visible
132
133
      if (!document.hidden && $element.is(':visible') && $element.css('visibility') !== 'hidden') {
134
        this.next();
135
      }
136
    };
137
138
    _proto.prev = function prev() {
139
      if (!this._isSliding) {
140
        this._slide(DIRECTION_PREV);
141
      }
142
    };
143
144
    _proto.pause = function pause(event) {
145
      if (!event) {
146
        this._isPaused = true;
147
      }
148
149
      if (this._element.querySelector(SELECTOR_NEXT_PREV)) {
150
        Util__default['default'].triggerTransitionEnd(this._element);
151
        this.cycle(true);
152
      }
153
154
      clearInterval(this._interval);
155
      this._interval = null;
156
    };
157
158
    _proto.cycle = function cycle(event) {
159
      if (!event) {
160
        this._isPaused = false;
161
      }
162
163
      if (this._interval) {
164
        clearInterval(this._interval);
165
        this._interval = null;
166
      }
167
168
      if (this._config.interval && !this._isPaused) {
169
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
170
      }
171
    };
172
173
    _proto.to = function to(index) {
174
      var _this = this;
175
176
      this._activeElement = this._element.querySelector(SELECTOR_ACTIVE_ITEM);
177
178
      var activeIndex = this._getItemIndex(this._activeElement);
179
180
      if (index > this._items.length - 1 || index < 0) {
181
        return;
182
      }
183
184
      if (this._isSliding) {
185
        $__default['default'](this._element).one(EVENT_SLID, function () {
186
          return _this.to(index);
187
        });
188
        return;
189
      }
190
191
      if (activeIndex === index) {
192
        this.pause();
193
        this.cycle();
194
        return;
195
      }
196
197
      var direction = index > activeIndex ? DIRECTION_NEXT : DIRECTION_PREV;
198
199
      this._slide(direction, this._items[index]);
200
    };
201
202
    _proto.dispose = function dispose() {
203
      $__default['default'](this._element).off(EVENT_KEY);
204
      $__default['default'].removeData(this._element, DATA_KEY);
205
      this._items = null;
206
      this._config = null;
207
      this._element = null;
208
      this._interval = null;
209
      this._isPaused = null;
210
      this._isSliding = null;
211
      this._activeElement = null;
212
      this._indicatorsElement = null;
213
    } // Private
214
    ;
215
216
    _proto._getConfig = function _getConfig(config) {
217
      config = _extends({}, Default, config);
218
      Util__default['default'].typeCheckConfig(NAME, config, DefaultType);
219
      return config;
220
    };
221
222
    _proto._handleSwipe = function _handleSwipe() {
223
      var absDeltax = Math.abs(this.touchDeltaX);
224
225
      if (absDeltax <= SWIPE_THRESHOLD) {
226
        return;
227
      }
228
229
      var direction = absDeltax / this.touchDeltaX;
230
      this.touchDeltaX = 0; // swipe left
231
232
      if (direction > 0) {
233
        this.prev();
234
      } // swipe right
235
236
237
      if (direction < 0) {
238
        this.next();
239
      }
240
    };
241
242
    _proto._addEventListeners = function _addEventListeners() {
243
      var _this2 = this;
244
245
      if (this._config.keyboard) {
246
        $__default['default'](this._element).on(EVENT_KEYDOWN, function (event) {
247
          return _this2._keydown(event);
248
        });
249
      }
250
251
      if (this._config.pause === 'hover') {
252
        $__default['default'](this._element).on(EVENT_MOUSEENTER, function (event) {
253
          return _this2.pause(event);
254
        }).on(EVENT_MOUSELEAVE, function (event) {
255
          return _this2.cycle(event);
256
        });
257
      }
258
259
      if (this._config.touch) {
260
        this._addTouchEventListeners();
261
      }
262
    };
263
264
    _proto._addTouchEventListeners = function _addTouchEventListeners() {
265
      var _this3 = this;
266
267
      if (!this._touchSupported) {
268
        return;
269
      }
270
271
      var start = function start(event) {
272
        if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
273
          _this3.touchStartX = event.originalEvent.clientX;
274
        } else if (!_this3._pointerEvent) {
275
          _this3.touchStartX = event.originalEvent.touches[0].clientX;
276
        }
277
      };
278
279
      var move = function move(event) {
280
        // ensure swiping with one touch and not pinching
281
        if (event.originalEvent.touches && event.originalEvent.touches.length > 1) {
282
          _this3.touchDeltaX = 0;
283
        } else {
284
          _this3.touchDeltaX = event.originalEvent.touches[0].clientX - _this3.touchStartX;
285
        }
286
      };
287
288
      var end = function end(event) {
289
        if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
290
          _this3.touchDeltaX = event.originalEvent.clientX - _this3.touchStartX;
291
        }
292
293
        _this3._handleSwipe();
294
295
        if (_this3._config.pause === 'hover') {
296
          // If it's a touch-enabled device, mouseenter/leave are fired as
297
          // part of the mouse compatibility events on first tap - the carousel
298
          // would stop cycling until user tapped out of it;
299
          // here, we listen for touchend, explicitly pause the carousel
300
          // (as if it's the second time we tap on it, mouseenter compat event
301
          // is NOT fired) and after a timeout (to allow for mouse compatibility
302
          // events to fire) we explicitly restart cycling
303
          _this3.pause();
304
305
          if (_this3.touchTimeout) {
306
            clearTimeout(_this3.touchTimeout);
307
          }
308
309
          _this3.touchTimeout = setTimeout(function (event) {
310
            return _this3.cycle(event);
311
          }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval);
312
        }
313
      };
314
315
      $__default['default'](this._element.querySelectorAll(SELECTOR_ITEM_IMG)).on(EVENT_DRAG_START, function (e) {
316
        return e.preventDefault();
317
      });
318
319
      if (this._pointerEvent) {
320
        $__default['default'](this._element).on(EVENT_POINTERDOWN, function (event) {
321
          return start(event);
322
        });
323
        $__default['default'](this._element).on(EVENT_POINTERUP, function (event) {
324
          return end(event);
325
        });
326
327
        this._element.classList.add(CLASS_NAME_POINTER_EVENT);
328
      } else {
329
        $__default['default'](this._element).on(EVENT_TOUCHSTART, function (event) {
330
          return start(event);
331
        });
332
        $__default['default'](this._element).on(EVENT_TOUCHMOVE, function (event) {
333
          return move(event);
334
        });
335
        $__default['default'](this._element).on(EVENT_TOUCHEND, function (event) {
336
          return end(event);
337
        });
338
      }
339
    };
340
341
    _proto._keydown = function _keydown(event) {
342
      if (/input|textarea/i.test(event.target.tagName)) {
343
        return;
344
      }
345
346
      switch (event.which) {
347
        case ARROW_LEFT_KEYCODE:
348
          event.preventDefault();
349
          this.prev();
350
          break;
351
352
        case ARROW_RIGHT_KEYCODE:
353
          event.preventDefault();
354
          this.next();
355
          break;
356
      }
357
    };
358
359
    _proto._getItemIndex = function _getItemIndex(element) {
360
      this._items = element && element.parentNode ? [].slice.call(element.parentNode.querySelectorAll(SELECTOR_ITEM)) : [];
361
      return this._items.indexOf(element);
362
    };
363
364
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
365
      var isNextDirection = direction === DIRECTION_NEXT;
366
      var isPrevDirection = direction === DIRECTION_PREV;
367
368
      var activeIndex = this._getItemIndex(activeElement);
369
370
      var lastItemIndex = this._items.length - 1;
371
      var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
372
373
      if (isGoingToWrap && !this._config.wrap) {
374
        return activeElement;
375
      }
376
377
      var delta = direction === DIRECTION_PREV ? -1 : 1;
378
      var itemIndex = (activeIndex + delta) % this._items.length;
379
      return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
380
    };
381
382
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
383
      var targetIndex = this._getItemIndex(relatedTarget);
384
385
      var fromIndex = this._getItemIndex(this._element.querySelector(SELECTOR_ACTIVE_ITEM));
386
387
      var slideEvent = $__default['default'].Event(EVENT_SLIDE, {
388
        relatedTarget: relatedTarget,
389
        direction: eventDirectionName,
390
        from: fromIndex,
391
        to: targetIndex
392
      });
393
      $__default['default'](this._element).trigger(slideEvent);
394
      return slideEvent;
395
    };
396
397
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
398
      if (this._indicatorsElement) {
399
        var indicators = [].slice.call(this._indicatorsElement.querySelectorAll(SELECTOR_ACTIVE));
400
        $__default['default'](indicators).removeClass(CLASS_NAME_ACTIVE);
401
402
        var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
403
404
        if (nextIndicator) {
405
          $__default['default'](nextIndicator).addClass(CLASS_NAME_ACTIVE);
406
        }
407
      }
408
    };
409
410
    _proto._slide = function _slide(direction, element) {
411
      var _this4 = this;
412
413
      var activeElement = this._element.querySelector(SELECTOR_ACTIVE_ITEM);
414
415
      var activeElementIndex = this._getItemIndex(activeElement);
416
417
      var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
418
419
      var nextElementIndex = this._getItemIndex(nextElement);
420
421
      var isCycling = Boolean(this._interval);
422
      var directionalClassName;
423
      var orderClassName;
424
      var eventDirectionName;
425
426
      if (direction === DIRECTION_NEXT) {
427
        directionalClassName = CLASS_NAME_LEFT;
428
        orderClassName = CLASS_NAME_NEXT;
429
        eventDirectionName = DIRECTION_LEFT;
430
      } else {
431
        directionalClassName = CLASS_NAME_RIGHT;
432
        orderClassName = CLASS_NAME_PREV;
433
        eventDirectionName = DIRECTION_RIGHT;
434
      }
435
436
      if (nextElement && $__default['default'](nextElement).hasClass(CLASS_NAME_ACTIVE)) {
437
        this._isSliding = false;
438
        return;
439
      }
440
441
      var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
442
443
      if (slideEvent.isDefaultPrevented()) {
444
        return;
445
      }
446
447
      if (!activeElement || !nextElement) {
448
        // Some weirdness is happening, so we bail
449
        return;
450
      }
451
452
      this._isSliding = true;
453
454
      if (isCycling) {
455
        this.pause();
456
      }
457
458
      this._setActiveIndicatorElement(nextElement);
459
460
      var slidEvent = $__default['default'].Event(EVENT_SLID, {
461
        relatedTarget: nextElement,
462
        direction: eventDirectionName,
463
        from: activeElementIndex,
464
        to: nextElementIndex
465
      });
466
467
      if ($__default['default'](this._element).hasClass(CLASS_NAME_SLIDE)) {
468
        $__default['default'](nextElement).addClass(orderClassName);
469
        Util__default['default'].reflow(nextElement);
470
        $__default['default'](activeElement).addClass(directionalClassName);
471
        $__default['default'](nextElement).addClass(directionalClassName);
472
        var nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10);
473
474
        if (nextElementInterval) {
475
          this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
476
          this._config.interval = nextElementInterval;
477
        } else {
478
          this._config.interval = this._config.defaultInterval || this._config.interval;
479
        }
480
481
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(activeElement);
482
        $__default['default'](activeElement).one(Util__default['default'].TRANSITION_END, function () {
483
          $__default['default'](nextElement).removeClass(directionalClassName + " " + orderClassName).addClass(CLASS_NAME_ACTIVE);
484
          $__default['default'](activeElement).removeClass(CLASS_NAME_ACTIVE + " " + orderClassName + " " + directionalClassName);
485
          _this4._isSliding = false;
486
          setTimeout(function () {
487
            return $__default['default'](_this4._element).trigger(slidEvent);
488
          }, 0);
489
        }).emulateTransitionEnd(transitionDuration);
490
      } else {
491
        $__default['default'](activeElement).removeClass(CLASS_NAME_ACTIVE);
492
        $__default['default'](nextElement).addClass(CLASS_NAME_ACTIVE);
493
        this._isSliding = false;
494
        $__default['default'](this._element).trigger(slidEvent);
495
      }
496
497
      if (isCycling) {
498
        this.cycle();
499
      }
500
    } // Static
501
    ;
502
503
    Carousel._jQueryInterface = function _jQueryInterface(config) {
504
      return this.each(function () {
505
        var data = $__default['default'](this).data(DATA_KEY);
506
507
        var _config = _extends({}, Default, $__default['default'](this).data());
508
509
        if (typeof config === 'object') {
510
          _config = _extends({}, _config, config);
511
        }
512
513
        var action = typeof config === 'string' ? config : _config.slide;
514
515
        if (!data) {
516
          data = new Carousel(this, _config);
517
          $__default['default'](this).data(DATA_KEY, data);
518
        }
519
520
        if (typeof config === 'number') {
521
          data.to(config);
522
        } else if (typeof action === 'string') {
523
          if (typeof data[action] === 'undefined') {
524
            throw new TypeError("No method named \"" + action + "\"");
525
          }
526
527
          data[action]();
528
        } else if (_config.interval && _config.ride) {
529
          data.pause();
530
          data.cycle();
531
        }
532
      });
533
    };
534
535
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
536
      var selector = Util__default['default'].getSelectorFromElement(this);
537
538
      if (!selector) {
539
        return;
540
      }
541
542
      var target = $__default['default'](selector)[0];
543
544
      if (!target || !$__default['default'](target).hasClass(CLASS_NAME_CAROUSEL)) {
545
        return;
546
      }
547
548
      var config = _extends({}, $__default['default'](target).data(), $__default['default'](this).data());
549
550
      var slideIndex = this.getAttribute('data-slide-to');
551
552
      if (slideIndex) {
553
        config.interval = false;
554
      }
555
556
      Carousel._jQueryInterface.call($__default['default'](target), config);
557
558
      if (slideIndex) {
559
        $__default['default'](target).data(DATA_KEY).to(slideIndex);
560
      }
561
562
      event.preventDefault();
563
    };
564
565
    _createClass(Carousel, null, [{
566
      key: "VERSION",
567
      get: function get() {
568
        return VERSION;
569
      }
570
    }, {
571
      key: "Default",
572
      get: function get() {
573
        return Default;
574
      }
575
    }]);
576
577
    return Carousel;
578
  }();
579
  /**
580
   * ------------------------------------------------------------------------
581
   * Data Api implementation
582
   * ------------------------------------------------------------------------
583
   */
584
585
586
  $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel._dataApiClickHandler);
587
  $__default['default'](window).on(EVENT_LOAD_DATA_API, function () {
588
    var carousels = [].slice.call(document.querySelectorAll(SELECTOR_DATA_RIDE));
589
590
    for (var i = 0, len = carousels.length; i < len; i++) {
591
      var $carousel = $__default['default'](carousels[i]);
592
593
      Carousel._jQueryInterface.call($carousel, $carousel.data());
594
    }
595
  });
596
  /**
597
   * ------------------------------------------------------------------------
598
   * jQuery
599
   * ------------------------------------------------------------------------
600
   */
601
602
  $__default['default'].fn[NAME] = Carousel._jQueryInterface;
603
  $__default['default'].fn[NAME].Constructor = Carousel;
604
605
  $__default['default'].fn[NAME].noConflict = function () {
606
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
607
    return Carousel._jQueryInterface;
608
  };
609
610
  return Carousel;
611
612
})));
613
//# sourceMappingURL=carousel.js.map
614