aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/carousel.js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
committerMario <mario@mariovavti.com>2021-07-29 08:25:05 +0000
commitd459dfac74e90c29950d49a82edc19fd913d435e (patch)
tree7bed5f2dbc318f87bbe0f4be2cde3dde09cd97c7 /vendor/twbs/bootstrap/js/dist/carousel.js
parentcec2f0d894b80f3affeb60cff2d4afa49a2019a8 (diff)
downloadvolse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.gz
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.tar.bz2
volse-hubzilla-d459dfac74e90c29950d49a82edc19fd913d435e.zip
update to bootstrap 5.0.2
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/carousel.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/carousel.js119
1 files changed, 67 insertions, 52 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/carousel.js b/vendor/twbs/bootstrap/js/dist/carousel.js
index 0c0282c0c..53e9a9687 100644
--- a/vendor/twbs/bootstrap/js/dist/carousel.js
+++ b/vendor/twbs/bootstrap/js/dist/carousel.js
@@ -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) {
- event.preventDefault();
+ const direction = KEY_TO_DIRECTION[event.key];
- this._slide(DIRECTION_RIGHT);
- } else if (event.key === ARROW_RIGHT_KEY) {
+ if (direction) {
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]));
}
});
/**