carousel.js 24.8 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap carousel.js v4.3.1 (https://getbootstrap.com/)
Mark Otto's avatar
Mark Otto committed
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
XhmikosR's avatar
XhmikosR committed
7
8
9
10
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/eventHandler.js'), require('./dom/manipulator.js'), require('./dom/selectorEngine.js')) :
  typeof define === 'function' && define.amd ? define(['./dom/data.js', './dom/eventHandler.js', './dom/manipulator.js', './dom/selectorEngine.js'], factory) :
  (global = global || self, global.Carousel = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
}(this, function (Data, EventHandler, Manipulator, SelectorEngine) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11

XhmikosR's avatar
XhmikosR committed
12
13
14
15
  Data = Data && Data.hasOwnProperty('default') ? Data['default'] : Data;
  EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Manipulator.hasOwnProperty('default') ? Manipulator['default'] : Manipulator;
  SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

  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);
    }
  }

  function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
  }

  function _defineProperty(obj, key, value) {
    if (key in obj) {
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
      });
    } else {
      obj[key] = value;
    }
Mark Otto's avatar
dist    
Mark Otto committed
44

Mark Otto's avatar
dist    
Mark Otto committed
45
46
    return obj;
  }
Mark Otto's avatar
dist    
Mark Otto committed
47

Mark Otto's avatar
dist    
Mark Otto committed
48
49
50
51
  function _objectSpread(target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
      var ownKeys = Object.keys(source);
Mark Otto's avatar
dist    
Mark Otto committed
52

Mark Otto's avatar
dist    
Mark Otto committed
53
54
55
56
57
58
59
60
61
62
63
64
65
      if (typeof Object.getOwnPropertySymbols === 'function') {
        ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
          return Object.getOwnPropertyDescriptor(source, sym).enumerable;
        }));
      }

      ownKeys.forEach(function (key) {
        _defineProperty(target, key, source[key]);
      });
    }

    return target;
  }
fat's avatar
fat committed
66

XhmikosR's avatar
XhmikosR committed
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.3.1): util/index.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
  var TRANSITION_END = 'transitionend';
  var jQuery = window.jQuery; // Shoutout AngusCroll (https://goo.gl/pxwQGp)

  var toType = function toType(obj) {
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

  var getSelectorFromElement = function getSelectorFromElement(element) {
    var selector = element.getAttribute('data-target');

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : '';
    }

    try {
      return document.querySelector(selector) ? selector : null;
    } catch (err) {
      return null;
    }
  };

  var getTransitionDurationFromElement = function getTransitionDurationFromElement(element) {
    if (!element) {
      return 0;
    } // Get transition-duration of the element


    var _window$getComputedSt = window.getComputedStyle(element),
        transitionDuration = _window$getComputedSt.transitionDuration,
        transitionDelay = _window$getComputedSt.transitionDelay;

    var floatTransitionDuration = parseFloat(transitionDuration);
    var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found

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


    transitionDuration = transitionDuration.split(',')[0];
    transitionDelay = transitionDelay.split(',')[0];
    return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  };

  var triggerTransitionEnd = function triggerTransitionEnd(element) {
    element.dispatchEvent(new Event(TRANSITION_END));
  };

  var isElement = function isElement(obj) {
    return (obj[0] || obj).nodeType;
  };

  var emulateTransitionEnd = function emulateTransitionEnd(element, duration) {
    var called = false;
    var durationPadding = 5;
    var emulatedDuration = duration + durationPadding;

    function listener() {
      called = true;
      element.removeEventListener(TRANSITION_END, listener);
    }

    element.addEventListener(TRANSITION_END, listener);
    setTimeout(function () {
      if (!called) {
        triggerTransitionEnd(element);
      }
    }, emulatedDuration);
  };

  var typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) {
    Object.keys(configTypes).forEach(function (property) {
      var expectedTypes = configTypes[property];
      var value = config[property];
      var valueType = value && isElement(value) ? 'element' : toType(value);

      if (!new RegExp(expectedTypes).test(valueType)) {
        throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
      }
    });
  };

  var makeArray = function makeArray(nodeList) {
    if (!nodeList) {
      return [];
    }

    return [].slice.call(nodeList);
  };

  var isVisible = function isVisible(element) {
    if (!element) {
      return false;
    }

    if (element.style && element.parentNode && element.parentNode.style) {
      return element.style.display !== 'none' && element.parentNode.style.display !== 'none' && element.style.visibility !== 'hidden';
    }

    return false;
  };

  var reflow = function reflow(element) {
    return element.offsetHeight;
  };

fat's avatar
fat committed
181
  /**
XhmikosR's avatar
Dist    
XhmikosR committed
182
183
184
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
fat's avatar
fat committed
185
   */
Mark Otto's avatar
dist    
Mark Otto committed
186

XhmikosR's avatar
Dist    
XhmikosR committed
187
  var NAME = 'carousel';
XhmikosR's avatar
XhmikosR committed
188
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
  var DATA_KEY = 'bs.carousel';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key

  var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key

  var TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch

  var SWIPE_THRESHOLD = 40;
  var Default = {
    interval: 5000,
    keyboard: true,
    slide: false,
    pause: 'hover',
    wrap: true,
    touch: true
  };
  var DefaultType = {
    interval: '(number|boolean)',
    keyboard: 'boolean',
    slide: '(boolean|string)',
    pause: '(string|boolean)',
    wrap: 'boolean',
    touch: 'boolean'
  };
  var Direction = {
    NEXT: 'next',
    PREV: 'prev',
    LEFT: 'left',
    RIGHT: 'right'
  };
XhmikosR's avatar
XhmikosR committed
221
  var Event$1 = {
XhmikosR's avatar
Dist    
XhmikosR committed
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
    SLIDE: "slide" + EVENT_KEY,
    SLID: "slid" + EVENT_KEY,
    KEYDOWN: "keydown" + EVENT_KEY,
    MOUSEENTER: "mouseenter" + EVENT_KEY,
    MOUSELEAVE: "mouseleave" + EVENT_KEY,
    TOUCHSTART: "touchstart" + EVENT_KEY,
    TOUCHMOVE: "touchmove" + EVENT_KEY,
    TOUCHEND: "touchend" + EVENT_KEY,
    POINTERDOWN: "pointerdown" + EVENT_KEY,
    POINTERUP: "pointerup" + EVENT_KEY,
    DRAG_START: "dragstart" + EVENT_KEY,
    LOAD_DATA_API: "load" + EVENT_KEY + DATA_API_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
  };
  var ClassName = {
    CAROUSEL: 'carousel',
    ACTIVE: 'active',
    SLIDE: 'slide',
    RIGHT: 'carousel-item-right',
    LEFT: 'carousel-item-left',
    NEXT: 'carousel-item-next',
    PREV: 'carousel-item-prev',
    ITEM: 'carousel-item',
    POINTER_EVENT: 'pointer-event'
  };
  var Selector = {
    ACTIVE: '.active',
    ACTIVE_ITEM: '.active.carousel-item',
    ITEM: '.carousel-item',
    ITEM_IMG: '.carousel-item img',
    NEXT_PREV: '.carousel-item-next, .carousel-item-prev',
    INDICATORS: '.carousel-indicators',
    DATA_SLIDE: '[data-slide], [data-slide-to]',
    DATA_RIDE: '[data-ride="carousel"]'
  };
  var PointerType = {
    TOUCH: 'touch',
    PEN: 'pen'
Mark Otto's avatar
dist    
Mark Otto committed
260
261
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
262
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
263
264
     * ------------------------------------------------------------------------
     */
XhmikosR's avatar
Dist    
XhmikosR committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281

  };

  var Carousel =
  /*#__PURE__*/
  function () {
    function Carousel(element, config) {
      this._items = null;
      this._interval = null;
      this._activeElement = null;
      this._isPaused = false;
      this._isSliding = false;
      this.touchTimeout = null;
      this.touchStartX = 0;
      this.touchDeltaX = 0;
      this._config = this._getConfig(config);
      this._element = element;
XhmikosR's avatar
XhmikosR committed
282
      this._indicatorsElement = SelectorEngine.findOne(Selector.INDICATORS, this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
283
284
285
286
      this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
      this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent);

      this._addEventListeners();
XhmikosR's avatar
XhmikosR committed
287
288

      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
289
290
291
292
293
294
295
296
297
298
    } // Getters


    var _proto = Carousel.prototype;

    // Public
    _proto.next = function next() {
      if (!this._isSliding) {
        this._slide(Direction.NEXT);
      }
Mark Otto's avatar
dist    
Mark Otto committed
299
    };
XhmikosR's avatar
Dist    
XhmikosR committed
300
301
302
303

    _proto.nextWhenVisible = function nextWhenVisible() {
      // Don't call next when the page isn't visible
      // or the carousel or its parent isn't visible
XhmikosR's avatar
XhmikosR committed
304
      if (!document.hidden && isVisible(this._element)) {
XhmikosR's avatar
Dist    
XhmikosR committed
305
306
        this.next();
      }
Mark Otto's avatar
dist    
Mark Otto committed
307
    };
XhmikosR's avatar
Dist    
XhmikosR committed
308
309
310
311
312

    _proto.prev = function prev() {
      if (!this._isSliding) {
        this._slide(Direction.PREV);
      }
Mark Otto's avatar
dist    
Mark Otto committed
313
    };
fat's avatar
fat committed
314

XhmikosR's avatar
Dist    
XhmikosR committed
315
316
317
318
319
    _proto.pause = function pause(event) {
      if (!event) {
        this._isPaused = true;
      }

XhmikosR's avatar
XhmikosR committed
320
321
      if (SelectorEngine.findOne(Selector.NEXT_PREV, this._element)) {
        triggerTransitionEnd(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
322
323
324
325
326
        this.cycle(true);
      }

      clearInterval(this._interval);
      this._interval = null;
Mark Otto's avatar
dist    
Mark Otto committed
327
    };
fat's avatar
fat committed
328

XhmikosR's avatar
Dist    
XhmikosR committed
329
330
    _proto.cycle = function cycle(event) {
      if (!event) {
Mark Otto's avatar
dist    
Mark Otto committed
331
        this._isPaused = false;
XhmikosR's avatar
Dist    
XhmikosR committed
332
      }
fat's avatar
fat committed
333

XhmikosR's avatar
Dist    
XhmikosR committed
334
335
336
337
      if (this._interval) {
        clearInterval(this._interval);
        this._interval = null;
      }
fat's avatar
fat committed
338

XhmikosR's avatar
XhmikosR committed
339
      if (this._config && this._config.interval && !this._isPaused) {
XhmikosR's avatar
Dist    
XhmikosR committed
340
341
342
        this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
343

XhmikosR's avatar
Dist    
XhmikosR committed
344
345
    _proto.to = function to(index) {
      var _this = this;
Mark Otto's avatar
dist    
Mark Otto committed
346

XhmikosR's avatar
XhmikosR committed
347
      this._activeElement = SelectorEngine.findOne(Selector.ACTIVE_ITEM, this._element);
Mark Otto's avatar
dist    
Mark Otto committed
348

XhmikosR's avatar
Dist    
XhmikosR committed
349
      var activeIndex = this._getItemIndex(this._activeElement);
fat's avatar
fat committed
350

XhmikosR's avatar
Dist    
XhmikosR committed
351
352
353
      if (index > this._items.length - 1 || index < 0) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
354

XhmikosR's avatar
Dist    
XhmikosR committed
355
      if (this._isSliding) {
XhmikosR's avatar
XhmikosR committed
356
        EventHandler.one(this._element, Event$1.SLID, function () {
XhmikosR's avatar
Dist    
XhmikosR committed
357
358
359
360
          return _this.to(index);
        });
        return;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
361

XhmikosR's avatar
Dist    
XhmikosR committed
362
363
364
365
366
      if (activeIndex === index) {
        this.pause();
        this.cycle();
        return;
      }
fat's avatar
fat committed
367

XhmikosR's avatar
Dist    
XhmikosR committed
368
      var direction = index > activeIndex ? Direction.NEXT : Direction.PREV;
fat's avatar
fat committed
369

XhmikosR's avatar
Dist    
XhmikosR committed
370
371
      this._slide(direction, this._items[index]);
    };
Mark Otto's avatar
dist    
Mark Otto committed
372

XhmikosR's avatar
Dist    
XhmikosR committed
373
    _proto.dispose = function dispose() {
XhmikosR's avatar
XhmikosR committed
374
375
      EventHandler.off(this._element, EVENT_KEY);
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
376
377
378
379
380
381
382
383
      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
Mark Otto committed
384
385
    } // Private
    ;
XhmikosR's avatar
Dist    
XhmikosR committed
386
387
388

    _proto._getConfig = function _getConfig(config) {
      config = _objectSpread({}, Default, config);
XhmikosR's avatar
XhmikosR committed
389
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
390
391
      return config;
    };
Mark Otto's avatar
dist    
Mark Otto committed
392

XhmikosR's avatar
Dist    
XhmikosR committed
393
394
    _proto._handleSwipe = function _handleSwipe() {
      var absDeltax = Math.abs(this.touchDeltaX);
Mark Otto's avatar
dist    
Mark Otto committed
395

XhmikosR's avatar
Dist    
XhmikosR committed
396
397
398
      if (absDeltax <= SWIPE_THRESHOLD) {
        return;
      }
fat's avatar
fat committed
399

XhmikosR's avatar
Dist    
XhmikosR committed
400
      var direction = absDeltax / this.touchDeltaX; // swipe left
fat's avatar
fat committed
401

XhmikosR's avatar
Dist    
XhmikosR committed
402
403
404
      if (direction > 0) {
        this.prev();
      } // swipe right
fat's avatar
fat committed
405
406


XhmikosR's avatar
Dist    
XhmikosR committed
407
408
409
410
      if (direction < 0) {
        this.next();
      }
    };
fat's avatar
fat committed
411

XhmikosR's avatar
Dist    
XhmikosR committed
412
413
    _proto._addEventListeners = function _addEventListeners() {
      var _this2 = this;
fat's avatar
fat committed
414

XhmikosR's avatar
Dist    
XhmikosR committed
415
      if (this._config.keyboard) {
XhmikosR's avatar
XhmikosR committed
416
        EventHandler.on(this._element, Event$1.KEYDOWN, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
417
418
419
          return _this2._keydown(event);
        });
      }
Mark Otto's avatar
grunt    
Mark Otto committed
420

XhmikosR's avatar
Dist    
XhmikosR committed
421
      if (this._config.pause === 'hover') {
XhmikosR's avatar
XhmikosR committed
422
        EventHandler.on(this._element, Event$1.MOUSEENTER, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
423
          return _this2.pause(event);
XhmikosR's avatar
XhmikosR committed
424
425
        });
        EventHandler.on(this._element, Event$1.MOUSELEAVE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
426
427
428
          return _this2.cycle(event);
        });
      }
fat's avatar
fat committed
429

Mark Otto's avatar
Mark Otto committed
430
431
432
      if (this._config.touch) {
        this._addTouchEventListeners();
      }
XhmikosR's avatar
Dist    
XhmikosR committed
433
    };
Mark Otto's avatar
dist    
Mark Otto committed
434

XhmikosR's avatar
Dist    
XhmikosR committed
435
436
    _proto._addTouchEventListeners = function _addTouchEventListeners() {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
437

XhmikosR's avatar
Dist    
XhmikosR committed
438
439
440
      if (!this._touchSupported) {
        return;
      }
fat's avatar
fat committed
441

XhmikosR's avatar
Dist    
XhmikosR committed
442
      var start = function start(event) {
XhmikosR's avatar
XhmikosR committed
443
444
        if (_this3._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
          _this3.touchStartX = event.clientX;
XhmikosR's avatar
Dist    
XhmikosR committed
445
        } else if (!_this3._pointerEvent) {
XhmikosR's avatar
XhmikosR committed
446
          _this3.touchStartX = event.touches[0].clientX;
Mark Otto's avatar
dist    
Mark Otto committed
447
        }
XhmikosR's avatar
Dist    
XhmikosR committed
448
      };
Mark Otto's avatar
dist    
Mark Otto committed
449

XhmikosR's avatar
Dist    
XhmikosR committed
450
451
      var move = function move(event) {
        // ensure swiping with one touch and not pinching
XhmikosR's avatar
XhmikosR committed
452
        if (event.touches && event.touches.length > 1) {
XhmikosR's avatar
Dist    
XhmikosR committed
453
454
          _this3.touchDeltaX = 0;
        } else {
XhmikosR's avatar
XhmikosR committed
455
          _this3.touchDeltaX = event.touches[0].clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
456
457
        }
      };
fat's avatar
fat committed
458

XhmikosR's avatar
Dist    
XhmikosR committed
459
      var end = function end(event) {
XhmikosR's avatar
XhmikosR committed
460
461
        if (_this3._pointerEvent && PointerType[event.pointerType.toUpperCase()]) {
          _this3.touchDeltaX = event.clientX - _this3.touchStartX;
Mark Otto's avatar
dist    
Mark Otto committed
462
        }
Mark Otto's avatar
dist    
Mark Otto committed
463

XhmikosR's avatar
Dist    
XhmikosR committed
464
465
466
467
468
469
470
471
472
473
474
        _this3._handleSwipe();

        if (_this3._config.pause === 'hover') {
          // 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
          _this3.pause();
fat's avatar
fat committed
475

XhmikosR's avatar
Dist    
XhmikosR committed
476
477
478
          if (_this3.touchTimeout) {
            clearTimeout(_this3.touchTimeout);
          }
fat's avatar
fat committed
479

XhmikosR's avatar
Dist    
XhmikosR committed
480
481
482
          _this3.touchTimeout = setTimeout(function (event) {
            return _this3.cycle(event);
          }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval);
Mark Otto's avatar
dist    
Mark Otto committed
483
484
        }
      };
Mark Otto's avatar
grunt    
Mark Otto committed
485

XhmikosR's avatar
XhmikosR committed
486
487
488
489
      makeArray(SelectorEngine.find(Selector.ITEM_IMG, this._element)).forEach(function (itemImg) {
        EventHandler.on(itemImg, Event$1.DRAG_START, function (e) {
          return e.preventDefault();
        });
XhmikosR's avatar
Dist    
XhmikosR committed
490
      });
Mark Otto's avatar
grunt    
Mark Otto committed
491

XhmikosR's avatar
Dist    
XhmikosR committed
492
      if (this._pointerEvent) {
XhmikosR's avatar
XhmikosR committed
493
        EventHandler.on(this._element, Event$1.POINTERDOWN, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
494
495
          return start(event);
        });
XhmikosR's avatar
XhmikosR committed
496
        EventHandler.on(this._element, Event$1.POINTERUP, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
497
498
          return end(event);
        });
Mark Otto's avatar
dist    
Mark Otto committed
499

XhmikosR's avatar
Dist    
XhmikosR committed
500
501
        this._element.classList.add(ClassName.POINTER_EVENT);
      } else {
XhmikosR's avatar
XhmikosR committed
502
        EventHandler.on(this._element, Event$1.TOUCHSTART, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
503
504
          return start(event);
        });
XhmikosR's avatar
XhmikosR committed
505
        EventHandler.on(this._element, Event$1.TOUCHMOVE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
506
507
          return move(event);
        });
XhmikosR's avatar
XhmikosR committed
508
        EventHandler.on(this._element, Event$1.TOUCHEND, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
509
510
511
512
          return end(event);
        });
      }
    };
fat's avatar
fat committed
513

XhmikosR's avatar
Dist    
XhmikosR committed
514
515
516
517
    _proto._keydown = function _keydown(event) {
      if (/input|textarea/i.test(event.target.tagName)) {
        return;
      }
fat's avatar
fat committed
518

XhmikosR's avatar
Dist    
XhmikosR committed
519
520
521
522
523
      switch (event.which) {
        case ARROW_LEFT_KEYCODE:
          event.preventDefault();
          this.prev();
          break;
fat's avatar
fat committed
524

XhmikosR's avatar
Dist    
XhmikosR committed
525
526
527
528
        case ARROW_RIGHT_KEYCODE:
          event.preventDefault();
          this.next();
          break;
fat's avatar
fat committed
529

XhmikosR's avatar
Dist    
XhmikosR committed
530
531
532
        default:
      }
    };
fat's avatar
fat committed
533

XhmikosR's avatar
Dist    
XhmikosR committed
534
    _proto._getItemIndex = function _getItemIndex(element) {
XhmikosR's avatar
XhmikosR committed
535
      this._items = element && element.parentNode ? makeArray(SelectorEngine.find(Selector.ITEM, element.parentNode)) : [];
XhmikosR's avatar
Dist    
XhmikosR committed
536
537
      return this._items.indexOf(element);
    };
fat's avatar
fat committed
538

XhmikosR's avatar
Dist    
XhmikosR committed
539
540
541
    _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
      var isNextDirection = direction === Direction.NEXT;
      var isPrevDirection = direction === Direction.PREV;
Mark Otto's avatar
dist    
Mark Otto committed
542

XhmikosR's avatar
Dist    
XhmikosR committed
543
      var activeIndex = this._getItemIndex(activeElement);
fat's avatar
fat committed
544

XhmikosR's avatar
Dist    
XhmikosR committed
545
546
      var lastItemIndex = this._items.length - 1;
      var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
Mark Otto's avatar
dist    
Mark Otto committed
547

XhmikosR's avatar
Dist    
XhmikosR committed
548
549
550
      if (isGoingToWrap && !this._config.wrap) {
        return activeElement;
      }
fat's avatar
fat committed
551

XhmikosR's avatar
Dist    
XhmikosR committed
552
553
554
555
      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
556

XhmikosR's avatar
Dist    
XhmikosR committed
557
558
    _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
      var targetIndex = this._getItemIndex(relatedTarget);
fat's avatar
fat committed
559

XhmikosR's avatar
XhmikosR committed
560
      var fromIndex = this._getItemIndex(SelectorEngine.findOne(Selector.ACTIVE_ITEM, this._element));
fat's avatar
fat committed
561

XhmikosR's avatar
XhmikosR committed
562
      return EventHandler.trigger(this._element, Event$1.SLIDE, {
XhmikosR's avatar
Dist    
XhmikosR committed
563
564
565
566
567
568
        relatedTarget: relatedTarget,
        direction: eventDirectionName,
        from: fromIndex,
        to: targetIndex
      });
    };
fat's avatar
fat committed
569

XhmikosR's avatar
Dist    
XhmikosR committed
570
571
    _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
      if (this._indicatorsElement) {
XhmikosR's avatar
XhmikosR committed
572
573
574
575
576
        var indicators = SelectorEngine.find(Selector.ACTIVE, this._indicatorsElement);

        for (var i = 0; i < indicators.length; i++) {
          indicators[i].classList.remove(ClassName.ACTIVE);
        }
fat's avatar
fat committed
577

XhmikosR's avatar
Dist    
XhmikosR committed
578
        var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
fat's avatar
fat committed
579

XhmikosR's avatar
Dist    
XhmikosR committed
580
        if (nextIndicator) {
XhmikosR's avatar
XhmikosR committed
581
          nextIndicator.classList.add(ClassName.ACTIVE);
Mark Otto's avatar
dist    
Mark Otto committed
582
        }
XhmikosR's avatar
Dist    
XhmikosR committed
583
584
      }
    };
fat's avatar
fat committed
585

XhmikosR's avatar
Dist    
XhmikosR committed
586
587
    _proto._slide = function _slide(direction, element) {
      var _this4 = this;
fat's avatar
fat committed
588

XhmikosR's avatar
XhmikosR committed
589
      var activeElement = SelectorEngine.findOne(Selector.ACTIVE_ITEM, this._element);
fat's avatar
fat committed
590

XhmikosR's avatar
Dist    
XhmikosR committed
591
      var activeElementIndex = this._getItemIndex(activeElement);
fat's avatar
fat committed
592

XhmikosR's avatar
Dist    
XhmikosR committed
593
      var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
fat's avatar
fat committed
594

XhmikosR's avatar
Dist    
XhmikosR committed
595
      var nextElementIndex = this._getItemIndex(nextElement);
fat's avatar
fat committed
596

XhmikosR's avatar
Dist    
XhmikosR committed
597
598
599
600
      var isCycling = Boolean(this._interval);
      var directionalClassName;
      var orderClassName;
      var eventDirectionName;
fat's avatar
fat committed
601

XhmikosR's avatar
Dist    
XhmikosR committed
602
603
604
605
606
607
608
609
610
      if (direction === Direction.NEXT) {
        directionalClassName = ClassName.LEFT;
        orderClassName = ClassName.NEXT;
        eventDirectionName = Direction.LEFT;
      } else {
        directionalClassName = ClassName.RIGHT;
        orderClassName = ClassName.PREV;
        eventDirectionName = Direction.RIGHT;
      }
Mark Otto's avatar
dist    
Mark Otto committed
611

XhmikosR's avatar
XhmikosR committed
612
      if (nextElement && nextElement.classList.contains(ClassName.ACTIVE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
613
614
615
        this._isSliding = false;
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
616

XhmikosR's avatar
Dist    
XhmikosR committed
617
      var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
Mark Otto's avatar
dist    
Mark Otto committed
618

XhmikosR's avatar
XhmikosR committed
619
      if (slideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
620
621
        return;
      }
fat's avatar
fat committed
622

XhmikosR's avatar
Dist    
XhmikosR committed
623
624
625
626
      if (!activeElement || !nextElement) {
        // Some weirdness is happening, so we bail
        return;
      }
fat's avatar
fat committed
627

XhmikosR's avatar
Dist    
XhmikosR committed
628
      this._isSliding = true;
Mark Otto's avatar
Mark Otto committed
629

XhmikosR's avatar
Dist    
XhmikosR committed
630
631
632
      if (isCycling) {
        this.pause();
      }
fat's avatar
fat committed
633

XhmikosR's avatar
Dist    
XhmikosR committed
634
      this._setActiveIndicatorElement(nextElement);
Mark Otto's avatar
dist    
Mark Otto committed
635

XhmikosR's avatar
XhmikosR committed
636
637
638
639
640
      if (this._element.classList.contains(ClassName.SLIDE)) {
        nextElement.classList.add(orderClassName);
        reflow(nextElement);
        activeElement.classList.add(directionalClassName);
        nextElement.classList.add(directionalClassName);
XhmikosR's avatar
Dist    
XhmikosR committed
641
        var nextElementInterval = parseInt(nextElement.getAttribute('data-interval'), 10);
fat's avatar
fat committed
642

XhmikosR's avatar
Dist    
XhmikosR committed
643
644
645
646
647
648
        if (nextElementInterval) {
          this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
          this._config.interval = nextElementInterval;
        } else {
          this._config.interval = this._config.defaultInterval || this._config.interval;
        }
Mark Otto's avatar
dist    
Mark Otto committed
649

XhmikosR's avatar
XhmikosR committed
650
651
652
653
654
655
656
657
        var transitionDuration = getTransitionDurationFromElement(activeElement);
        EventHandler.one(activeElement, TRANSITION_END, function () {
          nextElement.classList.remove(directionalClassName);
          nextElement.classList.remove(orderClassName);
          nextElement.classList.add(ClassName.ACTIVE);
          activeElement.classList.remove(ClassName.ACTIVE);
          activeElement.classList.remove(orderClassName);
          activeElement.classList.remove(directionalClassName);
XhmikosR's avatar
Dist    
XhmikosR committed
658
659
          _this4._isSliding = false;
          setTimeout(function () {
XhmikosR's avatar
XhmikosR committed
660
661
662
663
664
665
            EventHandler.trigger(_this4._element, Event$1.SLID, {
              relatedTarget: nextElement,
              direction: eventDirectionName,
              from: activeElementIndex,
              to: nextElementIndex
            });
XhmikosR's avatar
Dist    
XhmikosR committed
666
          }, 0);
XhmikosR's avatar
XhmikosR committed
667
668
        });
        emulateTransitionEnd(activeElement, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
669
      } else {
XhmikosR's avatar
XhmikosR committed
670
671
        activeElement.classList.remove(ClassName.ACTIVE);
        nextElement.classList.add(ClassName.ACTIVE);
XhmikosR's avatar
Dist    
XhmikosR committed
672
        this._isSliding = false;
XhmikosR's avatar
XhmikosR committed
673
674
675
676
677
678
        EventHandler.trigger(this._element, Event$1.SLID, {
          relatedTarget: nextElement,
          direction: eventDirectionName,
          from: activeElementIndex,
          to: nextElementIndex
        });
XhmikosR's avatar
Dist    
XhmikosR committed
679
      }
Mark Otto's avatar
dist    
Mark Otto committed
680

XhmikosR's avatar
Dist    
XhmikosR committed
681
682
683
      if (isCycling) {
        this.cycle();
      }
Mark Otto's avatar
Mark Otto committed
684
685
    } // Static
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
686

XhmikosR's avatar
XhmikosR committed
687
688
    Carousel._carouselInterface = function _carouselInterface(element, config) {
      var data = Data.getData(element, DATA_KEY);
Mark Otto's avatar
dist    
Mark Otto committed
689

XhmikosR's avatar
XhmikosR committed
690
      var _config = _objectSpread({}, Default, Manipulator.getDataAttributes(element));
Mark Otto's avatar
dist    
Mark Otto committed
691

XhmikosR's avatar
XhmikosR committed
692
693
694
      if (typeof config === 'object') {
        _config = _objectSpread({}, _config, config);
      }
Mark Otto's avatar
dist    
Mark Otto committed
695

XhmikosR's avatar
XhmikosR committed
696
      var action = typeof config === 'string' ? config : _config.slide;
Mark Otto's avatar
dist    
Mark Otto committed
697

XhmikosR's avatar
XhmikosR committed
698
699
700
701
702
703
704
705
706
      if (!data) {
        data = new Carousel(element, _config);
      }

      if (typeof config === 'number') {
        data.to(config);
      } else if (typeof action === 'string') {
        if (typeof data[action] === 'undefined') {
          throw new Error("No method named \"" + action + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
707
        }
Mark Otto's avatar
dist    
Mark Otto committed
708

XhmikosR's avatar
XhmikosR committed
709
710
711
712
713
714
        data[action]();
      } else if (_config.interval && _config.ride) {
        data.pause();
        data.cycle();
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
715

XhmikosR's avatar
XhmikosR committed
716
717
718
    Carousel._jQueryInterface = function _jQueryInterface(config) {
      return this.each(function () {
        Carousel._carouselInterface(this, config);
XhmikosR's avatar
Dist    
XhmikosR committed
719
720
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
721

XhmikosR's avatar
Dist    
XhmikosR committed
722
    Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
XhmikosR's avatar
XhmikosR committed
723
      var selector = getSelectorFromElement(this);
Mark Otto's avatar
dist    
Mark Otto committed
724

XhmikosR's avatar
Dist    
XhmikosR committed
725
726
727
      if (!selector) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
728

XhmikosR's avatar
XhmikosR committed
729
      var target = SelectorEngine.findOne(selector);
fat's avatar
fat committed
730

XhmikosR's avatar
XhmikosR committed
731
      if (!target || !target.classList.contains(ClassName.CAROUSEL)) {
XhmikosR's avatar
Dist    
XhmikosR committed
732
733
        return;
      }
fat's avatar
fat committed
734

XhmikosR's avatar
XhmikosR committed
735
      var config = _objectSpread({}, Manipulator.getDataAttributes(target), Manipulator.getDataAttributes(this));
fat's avatar
fat committed
736

XhmikosR's avatar
Dist    
XhmikosR committed
737
      var slideIndex = this.getAttribute('data-slide-to');
Mark Otto's avatar
dist    
Mark Otto committed
738

XhmikosR's avatar
Dist    
XhmikosR committed
739
740
      if (slideIndex) {
        config.interval = false;
Mark Otto's avatar
dist    
Mark Otto committed
741
      }
Mark Otto's avatar
dist    
Mark Otto committed
742

XhmikosR's avatar
XhmikosR committed
743
      Carousel._carouselInterface(target, config);
XhmikosR's avatar
Dist    
XhmikosR committed
744
745

      if (slideIndex) {
XhmikosR's avatar
XhmikosR committed
746
        Data.getData(target, DATA_KEY).to(slideIndex);
XhmikosR's avatar
Dist    
XhmikosR committed
747
      }
fat's avatar
fat committed
748

XhmikosR's avatar
Dist    
XhmikosR committed
749
      event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
750
    };
Mark Otto's avatar
dist    
Mark Otto committed
751

XhmikosR's avatar
XhmikosR committed
752
753
754
755
    Carousel._getInstance = function _getInstance(element) {
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
756
757
758
759
760
761
762
763
764
765
766
767
    _createClass(Carousel, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);

Mark Otto's avatar
dist    
Mark Otto committed
768
    return Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
769
770
771
772
773
774
775
776
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */


XhmikosR's avatar
XhmikosR committed
777
778
779
  EventHandler.on(document, Event$1.CLICK_DATA_API, Selector.DATA_SLIDE, Carousel._dataApiClickHandler);
  EventHandler.on(window, Event$1.LOAD_DATA_API, function () {
    var carousels = makeArray(SelectorEngine.find(Selector.DATA_RIDE));
XhmikosR's avatar
Dist    
XhmikosR committed
780
781

    for (var i = 0, len = carousels.length; i < len; i++) {
XhmikosR's avatar
XhmikosR committed
782
      Carousel._carouselInterface(carousels[i], Data.getData(carousels[i], DATA_KEY));
XhmikosR's avatar
Dist    
XhmikosR committed
783
784
785
786
787
788
    }
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
XhmikosR's avatar
XhmikosR committed
789
   * add .carousel to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
790
791
   */

XhmikosR's avatar
XhmikosR committed
792
793
794
795
  if (typeof jQuery !== 'undefined') {
    var JQUERY_NO_CONFLICT = jQuery.fn[NAME];
    jQuery.fn[NAME] = Carousel._jQueryInterface;
    jQuery.fn[NAME].Constructor = Carousel;
XhmikosR's avatar
Dist    
XhmikosR committed
796

XhmikosR's avatar
XhmikosR committed
797
798
799
800
801
    jQuery.fn[NAME].noConflict = function () {
      jQuery.fn[NAME] = JQUERY_NO_CONFLICT;
      return Carousel._jQueryInterface;
    };
  }
fat's avatar
fat committed
802
803

  return Carousel;
Mark Otto's avatar
dist    
Mark Otto committed
804

Mark Otto's avatar
Mark Otto committed
805
}));
Mark Otto's avatar
dist    
Mark Otto committed
806
//# sourceMappingURL=carousel.js.map