mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-11 08:04:59 +02:00
121
js/dist/carousel.js
vendored
121
js/dist/carousel.js
vendored
@@ -1,18 +1,17 @@
|
||||
/*!
|
||||
* Bootstrap carousel.js v5.0.1 (https://getbootstrap.com/)
|
||||
* Bootstrap carousel.js v5.0.2 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
*/
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/selector-engine.js'), require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
|
||||
typeof define === 'function' && define.amd ? define(['./dom/selector-engine', './dom/data', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.SelectorEngine, global.Data, global.EventHandler, global.Manipulator, global.Base));
|
||||
}(this, (function (SelectorEngine, Data, EventHandler, Manipulator, BaseComponent) { 'use strict';
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/selector-engine.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./base-component.js')) :
|
||||
typeof define === 'function' && define.amd ? define(['./dom/selector-engine', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.SelectorEngine, global.EventHandler, global.Manipulator, global.Base));
|
||||
}(this, (function (SelectorEngine, EventHandler, Manipulator, BaseComponent) { 'use strict';
|
||||
|
||||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
||||
|
||||
var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
|
||||
var Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
|
||||
var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
||||
var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
|
||||
var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
|
||||
@@ -85,17 +84,11 @@
|
||||
};
|
||||
|
||||
const isVisible = element => {
|
||||
if (!element) {
|
||||
if (!isElement(element) || element.getClientRects().length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element.style && element.parentNode && element.parentNode.style) {
|
||||
const elementStyle = getComputedStyle(element);
|
||||
const parentNodeStyle = getComputedStyle(element.parentNode);
|
||||
return elementStyle.display !== 'none' && parentNodeStyle.display !== 'none' && elementStyle.visibility !== 'hidden';
|
||||
}
|
||||
|
||||
return false;
|
||||
return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
|
||||
};
|
||||
|
||||
const reflow = element => element.offsetHeight;
|
||||
@@ -112,9 +105,18 @@
|
||||
return null;
|
||||
};
|
||||
|
||||
const DOMContentLoadedCallbacks = [];
|
||||
|
||||
const onDOMContentLoaded = callback => {
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', callback);
|
||||
// add listener on the first call when the document is in loading state
|
||||
if (!DOMContentLoadedCallbacks.length) {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
DOMContentLoadedCallbacks.forEach(callback => callback());
|
||||
});
|
||||
}
|
||||
|
||||
DOMContentLoadedCallbacks.push(callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
@@ -140,10 +142,37 @@
|
||||
}
|
||||
});
|
||||
};
|
||||
/**
|
||||
* Return the previous/next element of a list.
|
||||
*
|
||||
* @param {array} list The list of elements
|
||||
* @param activeElement The active element
|
||||
* @param shouldGetNext Choose to get next or previous element
|
||||
* @param isCycleAllowed
|
||||
* @return {Element|elem} The proper element
|
||||
*/
|
||||
|
||||
|
||||
const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
|
||||
let index = list.indexOf(activeElement); // if the element does not exist in the list return an element depending on the direction and if cycle is allowed
|
||||
|
||||
if (index === -1) {
|
||||
return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0];
|
||||
}
|
||||
|
||||
const listLength = list.length;
|
||||
index += shouldGetNext ? 1 : -1;
|
||||
|
||||
if (isCycleAllowed) {
|
||||
index = (index + listLength) % listLength;
|
||||
}
|
||||
|
||||
return list[Math.max(0, Math.min(index, listLength - 1))];
|
||||
};
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Bootstrap (v5.0.1): carousel.js
|
||||
* Bootstrap (v5.0.2): carousel.js
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -182,6 +211,10 @@
|
||||
const ORDER_PREV = 'prev';
|
||||
const DIRECTION_LEFT = 'left';
|
||||
const DIRECTION_RIGHT = 'right';
|
||||
const KEY_TO_DIRECTION = {
|
||||
[ARROW_LEFT_KEY]: DIRECTION_RIGHT,
|
||||
[ARROW_RIGHT_KEY]: DIRECTION_LEFT
|
||||
};
|
||||
const EVENT_SLIDE = `slide${EVENT_KEY}`;
|
||||
const EVENT_SLID = `slid${EVENT_KEY}`;
|
||||
const EVENT_KEYDOWN = `keydown${EVENT_KEY}`;
|
||||
@@ -250,9 +283,7 @@
|
||||
|
||||
|
||||
next() {
|
||||
if (!this._isSliding) {
|
||||
this._slide(ORDER_NEXT);
|
||||
}
|
||||
this._slide(ORDER_NEXT);
|
||||
}
|
||||
|
||||
nextWhenVisible() {
|
||||
@@ -264,9 +295,7 @@
|
||||
}
|
||||
|
||||
prev() {
|
||||
if (!this._isSliding) {
|
||||
this._slide(ORDER_PREV);
|
||||
}
|
||||
this._slide(ORDER_PREV);
|
||||
}
|
||||
|
||||
pause(event) {
|
||||
@@ -328,7 +357,8 @@
|
||||
|
||||
_getConfig(config) {
|
||||
config = { ...Default,
|
||||
...config
|
||||
...Manipulator__default['default'].getDataAttributes(this._element),
|
||||
...(typeof config === 'object' ? config : {})
|
||||
};
|
||||
typeCheckConfig(NAME, config, DefaultType);
|
||||
return config;
|
||||
@@ -426,14 +456,12 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.key === ARROW_LEFT_KEY) {
|
||||
const direction = KEY_TO_DIRECTION[event.key];
|
||||
|
||||
if (direction) {
|
||||
event.preventDefault();
|
||||
|
||||
this._slide(DIRECTION_RIGHT);
|
||||
} else if (event.key === ARROW_RIGHT_KEY) {
|
||||
event.preventDefault();
|
||||
|
||||
this._slide(DIRECTION_LEFT);
|
||||
this._slide(direction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,20 +472,7 @@
|
||||
|
||||
_getItemByOrder(order, activeElement) {
|
||||
const isNext = order === ORDER_NEXT;
|
||||
const isPrev = order === ORDER_PREV;
|
||||
|
||||
const activeIndex = this._getItemIndex(activeElement);
|
||||
|
||||
const lastItemIndex = this._items.length - 1;
|
||||
const isGoingToWrap = isPrev && activeIndex === 0 || isNext && activeIndex === lastItemIndex;
|
||||
|
||||
if (isGoingToWrap && !this._config.wrap) {
|
||||
return activeElement;
|
||||
}
|
||||
|
||||
const delta = isPrev ? -1 : 1;
|
||||
const itemIndex = (activeIndex + delta) % this._items.length;
|
||||
return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
|
||||
return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap);
|
||||
}
|
||||
|
||||
_triggerSlideEvent(relatedTarget, eventDirectionName) {
|
||||
@@ -530,6 +545,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._isSliding) {
|
||||
return;
|
||||
}
|
||||
|
||||
const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
|
||||
|
||||
if (slideEvent.defaultPrevented) {
|
||||
@@ -613,10 +632,10 @@
|
||||
|
||||
|
||||
static carouselInterface(element, config) {
|
||||
let data = Data__default['default'].get(element, DATA_KEY);
|
||||
let _config = { ...Default,
|
||||
...Manipulator__default['default'].getDataAttributes(element)
|
||||
};
|
||||
const data = Carousel.getOrCreateInstance(element, config);
|
||||
let {
|
||||
_config
|
||||
} = data;
|
||||
|
||||
if (typeof config === 'object') {
|
||||
_config = { ..._config,
|
||||
@@ -626,10 +645,6 @@
|
||||
|
||||
const action = typeof config === 'string' ? config : _config.slide;
|
||||
|
||||
if (!data) {
|
||||
data = new Carousel(element, _config);
|
||||
}
|
||||
|
||||
if (typeof config === 'number') {
|
||||
data.to(config);
|
||||
} else if (typeof action === 'string') {
|
||||
@@ -669,7 +684,7 @@
|
||||
Carousel.carouselInterface(target, config);
|
||||
|
||||
if (slideIndex) {
|
||||
Data__default['default'].get(target, DATA_KEY).to(slideIndex);
|
||||
Carousel.getInstance(target).to(slideIndex);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
@@ -688,7 +703,7 @@
|
||||
const carousels = SelectorEngine__default['default'].find(SELECTOR_DATA_RIDE);
|
||||
|
||||
for (let i = 0, len = carousels.length; i < len; i++) {
|
||||
Carousel.carouselInterface(carousels[i], Data__default['default'].get(carousels[i], DATA_KEY));
|
||||
Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i]));
|
||||
}
|
||||
});
|
||||
/**
|
||||
|
Reference in New Issue
Block a user