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
; };
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
; }; }();
5 function _classCallCheck(instance
, Constructor
) { if (!(instance
instanceof Constructor
)) { throw new TypeError("Cannot call a class as a function"); } }
8 * --------------------------------------------------------------------------
9 * Bootstrap (v4.0.0-alpha.6): carousel.js
10 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
11 * --------------------------------------------------------------------------
14 var Carousel = function ($) {
17 * ------------------------------------------------------------------------
19 * ------------------------------------------------------------------------
22 var NAME
= 'carousel';
23 var VERSION
= '4.0.0-alpha.6';
24 var DATA_KEY
= 'bs.carousel';
25 var EVENT_KEY
= '.' + DATA_KEY
;
26 var DATA_API_KEY
= '.data-api';
27 var JQUERY_NO_CONFLICT
= $.fn
[NAME
];
28 var TRANSITION_DURATION
= 600;
29 var ARROW_LEFT_KEYCODE
= 37; // KeyboardEvent.which value for left arrow key
30 var ARROW_RIGHT_KEYCODE
= 39; // KeyboardEvent.which value for right arrow key
41 interval
: '(number|boolean)',
43 slide
: '(boolean|string)',
44 pause
: '(string|boolean)',
56 SLIDE
: 'slide' + EVENT_KEY
,
57 SLID
: 'slid' + EVENT_KEY
,
58 KEYDOWN
: 'keydown' + EVENT_KEY
,
59 MOUSEENTER
: 'mouseenter' + EVENT_KEY
,
60 MOUSELEAVE
: 'mouseleave' + EVENT_KEY
,
61 LOAD_DATA_API
: 'load' + EVENT_KEY
+ DATA_API_KEY
,
62 CLICK_DATA_API
: 'click' + EVENT_KEY
+ DATA_API_KEY
69 RIGHT
: 'carousel-item-right',
70 LEFT
: 'carousel-item-left',
71 NEXT
: 'carousel-item-next',
72 PREV
: 'carousel-item-prev',
78 ACTIVE_ITEM
: '.active.carousel-item',
79 ITEM
: '.carousel-item',
80 NEXT_PREV
: '.carousel-item-next, .carousel-item-prev',
81 INDICATORS
: '.carousel-indicators',
82 DATA_SLIDE
: '[data-slide], [data-slide-to]',
83 DATA_RIDE
: '[data-ride="carousel"]'
87 * ------------------------------------------------------------------------
89 * ------------------------------------------------------------------------
92 var Carousel = function () {
93 function Carousel(element
, config
) {
94 _classCallCheck(this, Carousel
);
97 this._interval
= null;
98 this._activeElement
= null;
100 this._isPaused
= false;
101 this._isSliding
= false;
103 this._config
= this._getConfig(config
);
104 this._element
= $(element
)[0];
105 this._indicatorsElement
= $(this._element
).find(Selector
.INDICATORS
)[0];
107 this._addEventListeners();
114 Carousel
.prototype.next
= function next() {
115 if (this._isSliding
) {
116 throw new Error('Carousel is sliding');
118 this._slide(Direction
.NEXT
);
121 Carousel
.prototype.nextWhenVisible
= function nextWhenVisible() {
122 // Don't call next when the page isn't visible
123 if (!document
.hidden
) {
128 Carousel
.prototype.prev
= function prev() {
129 if (this._isSliding
) {
130 throw new Error('Carousel is sliding');
132 this._slide(Direction
.PREVIOUS
);
135 Carousel
.prototype.pause
= function pause(event
) {
137 this._isPaused
= true;
140 if ($(this._element
).find(Selector
.NEXT_PREV
)[0] && Util
.supportsTransitionEnd()) {
141 Util
.triggerTransitionEnd(this._element
);
145 clearInterval(this._interval
);
146 this._interval
= null;
149 Carousel
.prototype.cycle
= function cycle(event
) {
151 this._isPaused
= false;
154 if (this._interval
) {
155 clearInterval(this._interval
);
156 this._interval
= null;
159 if (this._config
.interval
&& !this._isPaused
) {
160 this._interval
= setInterval((document
.visibilityState
? this.nextWhenVisible
: this.next
).bind(this), this._config
.interval
);
164 Carousel
.prototype.to
= function to(index
) {
167 this._activeElement
= $(this._element
).find(Selector
.ACTIVE_ITEM
)[0];
169 var activeIndex
= this._getItemIndex(this._activeElement
);
171 if (index
> this._items
.length
- 1 || index
< 0) {
175 if (this._isSliding
) {
176 $(this._element
).one(Event
.SLID
, function () {
177 return _this
.to(index
);
182 if (activeIndex
=== index
) {
188 var direction
= index
> activeIndex
? Direction
.NEXT
: Direction
.PREVIOUS
;
190 this._slide(direction
, this._items
[index
]);
193 Carousel
.prototype.dispose
= function dispose() {
194 $(this._element
).off(EVENT_KEY
);
195 $.removeData(this._element
, DATA_KEY
);
199 this._element
= null;
200 this._interval
= null;
201 this._isPaused
= null;
202 this._isSliding
= null;
203 this._activeElement
= null;
204 this._indicatorsElement
= null;
209 Carousel
.prototype._getConfig
= function _getConfig(config
) {
210 config
= $.extend({}, Default
, config
);
211 Util
.typeCheckConfig(NAME
, config
, DefaultType
);
215 Carousel
.prototype._addEventListeners
= function _addEventListeners() {
218 if (this._config
.keyboard
) {
219 $(this._element
).on(Event
.KEYDOWN
, function (event
) {
220 return _this2
._keydown(event
);
224 if (this._config
.pause
=== 'hover' && !('ontouchstart' in document
.documentElement
)) {
225 $(this._element
).on(Event
.MOUSEENTER
, function (event
) {
226 return _this2
.pause(event
);
227 }).on(Event
.MOUSELEAVE
, function (event
) {
228 return _this2
.cycle(event
);
233 Carousel
.prototype._keydown
= function _keydown(event
) {
234 if (/input|textarea/i.test(event
.target
.tagName
)) {
238 switch (event
.which
) {
239 case ARROW_LEFT_KEYCODE
:
240 event
.preventDefault();
243 case ARROW_RIGHT_KEYCODE
:
244 event
.preventDefault();
252 Carousel
.prototype._getItemIndex
= function _getItemIndex(element
) {
253 this._items
= $.makeArray($(element
).parent().find(Selector
.ITEM
));
254 return this._items
.indexOf(element
);
257 Carousel
.prototype._getItemByDirection
= function _getItemByDirection(direction
, activeElement
) {
258 var isNextDirection
= direction
=== Direction
.NEXT
;
259 var isPrevDirection
= direction
=== Direction
.PREVIOUS
;
260 var activeIndex
= this._getItemIndex(activeElement
);
261 var lastItemIndex
= this._items
.length
- 1;
262 var isGoingToWrap
= isPrevDirection
&& activeIndex
=== 0 || isNextDirection
&& activeIndex
=== lastItemIndex
;
264 if (isGoingToWrap
&& !this._config
.wrap
) {
265 return activeElement
;
268 var delta
= direction
=== Direction
.PREVIOUS
? -1 : 1;
269 var itemIndex
= (activeIndex
+ delta
) % this._items
.length
;
271 return itemIndex
=== -1 ? this._items
[this._items
.length
- 1] : this._items
[itemIndex
];
274 Carousel
.prototype._triggerSlideEvent
= function _triggerSlideEvent(relatedTarget
, eventDirectionName
) {
275 var slideEvent
= $.Event(Event
.SLIDE
, {
276 relatedTarget
: relatedTarget
,
277 direction
: eventDirectionName
280 $(this._element
).trigger(slideEvent
);
285 Carousel
.prototype._setActiveIndicatorElement
= function _setActiveIndicatorElement(element
) {
286 if (this._indicatorsElement
) {
287 $(this._indicatorsElement
).find(Selector
.ACTIVE
).removeClass(ClassName
.ACTIVE
);
289 var nextIndicator
= this._indicatorsElement
.children
[this._getItemIndex(element
)];
292 $(nextIndicator
).addClass(ClassName
.ACTIVE
);
297 Carousel
.prototype._slide
= function _slide(direction
, element
) {
300 var activeElement
= $(this._element
).find(Selector
.ACTIVE_ITEM
)[0];
301 var nextElement
= element
|| activeElement
&& this._getItemByDirection(direction
, activeElement
);
303 var isCycling
= Boolean(this._interval
);
305 var directionalClassName
= void 0;
306 var orderClassName
= void 0;
307 var eventDirectionName
= void 0;
309 if (direction
=== Direction
.NEXT
) {
310 directionalClassName
= ClassName
.LEFT
;
311 orderClassName
= ClassName
.NEXT
;
312 eventDirectionName
= Direction
.LEFT
;
314 directionalClassName
= ClassName
.RIGHT
;
315 orderClassName
= ClassName
.PREV
;
316 eventDirectionName
= Direction
.RIGHT
;
319 if (nextElement
&& $(nextElement
).hasClass(ClassName
.ACTIVE
)) {
320 this._isSliding
= false;
324 var slideEvent
= this._triggerSlideEvent(nextElement
, eventDirectionName
);
325 if (slideEvent
.isDefaultPrevented()) {
329 if (!activeElement
|| !nextElement
) {
330 // some weirdness is happening, so we bail
334 this._isSliding
= true;
340 this._setActiveIndicatorElement(nextElement
);
342 var slidEvent
= $.Event(Event
.SLID
, {
343 relatedTarget
: nextElement
,
344 direction
: eventDirectionName
347 if (Util
.supportsTransitionEnd() && $(this._element
).hasClass(ClassName
.SLIDE
)) {
349 $(nextElement
).addClass(orderClassName
);
351 Util
.reflow(nextElement
);
353 $(activeElement
).addClass(directionalClassName
);
354 $(nextElement
).addClass(directionalClassName
);
356 $(activeElement
).one(Util
.TRANSITION_END
, function () {
357 $(nextElement
).removeClass(directionalClassName
+ ' ' + orderClassName
).addClass(ClassName
.ACTIVE
);
359 $(activeElement
).removeClass(ClassName
.ACTIVE
+ ' ' + orderClassName
+ ' ' + directionalClassName
);
361 _this3
._isSliding
= false;
363 setTimeout(function () {
364 return $(_this3
._element
).trigger(slidEvent
);
366 }).emulateTransitionEnd(TRANSITION_DURATION
);
368 $(activeElement
).removeClass(ClassName
.ACTIVE
);
369 $(nextElement
).addClass(ClassName
.ACTIVE
);
371 this._isSliding
= false;
372 $(this._element
).trigger(slidEvent
);
382 Carousel
._jQueryInterface
= function _jQueryInterface(config
) {
383 return this.each(function () {
384 var data
= $(this).data(DATA_KEY
);
385 var _config
= $.extend({}, Default
, $(this).data());
387 if ((typeof config
=== 'undefined' ? 'undefined' : _typeof(config
)) === 'object') {
388 $.extend(_config
, config
);
391 var action
= typeof config
=== 'string' ? config
: _config
.slide
;
394 data
= new Carousel(this, _config
);
395 $(this).data(DATA_KEY
, data
);
398 if (typeof config
=== 'number') {
400 } else if (typeof action
=== 'string') {
401 if (data
[action
] === undefined) {
402 throw new Error('No method named "' + action
+ '"');
405 } else if (_config
.interval
) {
412 Carousel
._dataApiClickHandler
= function _dataApiClickHandler(event
) {
413 var selector
= Util
.getSelectorFromElement(this);
419 var target
= $(selector
)[0];
421 if (!target
|| !$(target
).hasClass(ClassName
.CAROUSEL
)) {
425 var config
= $.extend({}, $(target
).data(), $(this).data());
426 var slideIndex
= this.getAttribute('data-slide-to');
429 config
.interval
= false;
432 Carousel
._jQueryInterface
.call($(target
), config
);
435 $(target
).data(DATA_KEY
).to(slideIndex
);
438 event
.preventDefault();
441 _createClass(Carousel
, null, [{
443 get: function get() {
448 get: function get() {
457 * ------------------------------------------------------------------------
458 * Data Api implementation
459 * ------------------------------------------------------------------------
462 $(document
).on(Event
.CLICK_DATA_API
, Selector
.DATA_SLIDE
, Carousel
._dataApiClickHandler
);
464 $(window
).on(Event
.LOAD_DATA_API
, function () {
465 $(Selector
.DATA_RIDE
).each(function () {
466 var $carousel
= $(this);
467 Carousel
._jQueryInterface
.call($carousel
, $carousel
.data());
472 * ------------------------------------------------------------------------
474 * ------------------------------------------------------------------------
477 $.fn
[NAME
] = Carousel
._jQueryInterface
;
478 $.fn
[NAME
].Constructor
= Carousel
;
479 $.fn
[NAME
].noConflict = function () {
480 $.fn
[NAME
] = JQUERY_NO_CONFLICT
;
481 return Carousel
._jQueryInterface
;
486 //# sourceMappingURL=carousel.js.map