aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/twbs/bootstrap/js/dist/carousel.js
diff options
context:
space:
mode:
authornobody <nobody@zotlabs.com>2021-08-25 19:13:31 -0700
committernobody <nobody@zotlabs.com>2021-08-25 19:13:31 -0700
commitaa2106f9495bee4dcf0701fbd9fec8de6fa44984 (patch)
treef2e7178f78311069bd54471f6c063c5901d16fb7 /vendor/twbs/bootstrap/js/dist/carousel.js
parent73b53675b1a339cfd950845279438e35b4e2dc7c (diff)
parent6261d0826c49ca24df9f694931592fbb9bf60f7e (diff)
downloadvolse-hubzilla-aa2106f9495bee4dcf0701fbd9fec8de6fa44984.tar.gz
volse-hubzilla-aa2106f9495bee4dcf0701fbd9fec8de6fa44984.tar.bz2
volse-hubzilla-aa2106f9495bee4dcf0701fbd9fec8de6fa44984.zip
Merge branch 'dev' of https://framagit.org/hubzilla/core into dev
Diffstat (limited to 'vendor/twbs/bootstrap/js/dist/carousel.js')
-rw-r--r--vendor/twbs/bootstrap/js/dist/carousel.js818
1 files changed, 443 insertions, 375 deletions
diff --git a/vendor/twbs/bootstrap/js/dist/carousel.js b/vendor/twbs/bootstrap/js/dist/carousel.js
index 4520f5409..53e9a9687 100644
--- a/vendor/twbs/bootstrap/js/dist/carousel.js
+++ b/vendor/twbs/bootstrap/js/dist/carousel.js
@@ -1,73 +1,197 @@
/*!
- * Bootstrap carousel.js v4.6.0 (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('jquery'), require('./util.js')) :
- typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.jQuery, global.Util));
-}(this, (function ($, Util) { '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 $__default = /*#__PURE__*/_interopDefaultLegacy($);
- var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
+ var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
+ var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
+ var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
+ var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
- 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);
+ const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
+
+ const toType = obj => {
+ if (obj === null || obj === undefined) {
+ return `${obj}`;
}
- }
- function _createClass(Constructor, protoProps, staticProps) {
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
- if (staticProps) _defineProperties(Constructor, staticProps);
- return Constructor;
- }
+ return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
+ };
- function _extends() {
- _extends = Object.assign || function (target) {
- for (var i = 1; i < arguments.length; i++) {
- var source = arguments[i];
+ const getSelector = element => {
+ let selector = element.getAttribute('data-bs-target');
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- target[key] = source[key];
- }
- }
+ if (!selector || selector === '#') {
+ let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
+ // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
+ // `document.querySelector` will rightfully complain it is invalid.
+ // See https://github.com/twbs/bootstrap/issues/32273
+
+ if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
+ return null;
+ } // Just in case some CMS puts out a full URL with the anchor appended
+
+
+ if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
+ hrefAttr = `#${hrefAttr.split('#')[1]}`;
}
- return target;
- };
+ selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
+ }
- return _extends.apply(this, arguments);
- }
+ return selector;
+ };
+
+ const getElementFromSelector = element => {
+ const selector = getSelector(element);
+ return selector ? document.querySelector(selector) : null;
+ };
+
+ const triggerTransitionEnd = element => {
+ element.dispatchEvent(new Event(TRANSITION_END));
+ };
+
+ const isElement = obj => {
+ if (!obj || typeof obj !== 'object') {
+ return false;
+ }
+
+ if (typeof obj.jquery !== 'undefined') {
+ obj = obj[0];
+ }
+
+ return typeof obj.nodeType !== 'undefined';
+ };
+
+ const typeCheckConfig = (componentName, config, configTypes) => {
+ Object.keys(configTypes).forEach(property => {
+ const expectedTypes = configTypes[property];
+ const value = config[property];
+ const valueType = value && isElement(value) ? 'element' : toType(value);
+
+ if (!new RegExp(expectedTypes).test(valueType)) {
+ throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
+ }
+ });
+ };
+
+ const isVisible = element => {
+ if (!isElement(element) || element.getClientRects().length === 0) {
+ return false;
+ }
+
+ return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
+ };
+
+ const reflow = element => element.offsetHeight;
+
+ const getjQuery = () => {
+ const {
+ jQuery
+ } = window;
+ if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
+ return jQuery;
+ }
+
+ return null;
+ };
+
+ const DOMContentLoadedCallbacks = [];
+
+ const onDOMContentLoaded = callback => {
+ if (document.readyState === 'loading') {
+ // 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();
+ }
+ };
+
+ const isRTL = () => document.documentElement.dir === 'rtl';
+
+ const defineJQueryPlugin = plugin => {
+ onDOMContentLoaded(() => {
+ const $ = getjQuery();
+ /* istanbul ignore if */
+
+ if ($) {
+ const name = plugin.NAME;
+ const JQUERY_NO_CONFLICT = $.fn[name];
+ $.fn[name] = plugin.jQueryInterface;
+ $.fn[name].Constructor = plugin;
+
+ $.fn[name].noConflict = () => {
+ $.fn[name] = JQUERY_NO_CONFLICT;
+ return plugin.jQueryInterface;
+ };
+ }
+ });
+ };
+ /**
+ * 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.2): carousel.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
+ * --------------------------------------------------------------------------
+ */
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
- var NAME = 'carousel';
- var VERSION = '4.6.0';
- var DATA_KEY = 'bs.carousel';
- var EVENT_KEY = "." + DATA_KEY;
- var DATA_API_KEY = '.data-api';
- var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
- var ARROW_LEFT_KEYCODE = 37; // KeyboardEvent.which value for left arrow key
-
- var ARROW_RIGHT_KEYCODE = 39; // KeyboardEvent.which value for right arrow key
+ const NAME = 'carousel';
+ const DATA_KEY = 'bs.carousel';
+ const EVENT_KEY = `.${DATA_KEY}`;
+ const DATA_API_KEY = '.data-api';
+ const ARROW_LEFT_KEY = 'ArrowLeft';
+ const ARROW_RIGHT_KEY = 'ArrowRight';
+ const TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch
- var TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch
-
- var SWIPE_THRESHOLD = 40;
- var Default = {
+ const SWIPE_THRESHOLD = 40;
+ const Default = {
interval: 5000,
keyboard: true,
slide: false,
@@ -75,7 +199,7 @@
wrap: true,
touch: true
};
- var DefaultType = {
+ const DefaultType = {
interval: '(number|boolean)',
keyboard: 'boolean',
slide: '(boolean|string)',
@@ -83,51 +207,55 @@
wrap: 'boolean',
touch: 'boolean'
};
- var DIRECTION_NEXT = 'next';
- var DIRECTION_PREV = 'prev';
- var DIRECTION_LEFT = 'left';
- var DIRECTION_RIGHT = 'right';
- var EVENT_SLIDE = "slide" + EVENT_KEY;
- var EVENT_SLID = "slid" + EVENT_KEY;
- var EVENT_KEYDOWN = "keydown" + EVENT_KEY;
- var EVENT_MOUSEENTER = "mouseenter" + EVENT_KEY;
- var EVENT_MOUSELEAVE = "mouseleave" + EVENT_KEY;
- var EVENT_TOUCHSTART = "touchstart" + EVENT_KEY;
- var EVENT_TOUCHMOVE = "touchmove" + EVENT_KEY;
- var EVENT_TOUCHEND = "touchend" + EVENT_KEY;
- var EVENT_POINTERDOWN = "pointerdown" + EVENT_KEY;
- var EVENT_POINTERUP = "pointerup" + EVENT_KEY;
- var EVENT_DRAG_START = "dragstart" + EVENT_KEY;
- var EVENT_LOAD_DATA_API = "load" + EVENT_KEY + DATA_API_KEY;
- var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
- var CLASS_NAME_CAROUSEL = 'carousel';
- var CLASS_NAME_ACTIVE = 'active';
- var CLASS_NAME_SLIDE = 'slide';
- var CLASS_NAME_RIGHT = 'carousel-item-right';
- var CLASS_NAME_LEFT = 'carousel-item-left';
- var CLASS_NAME_NEXT = 'carousel-item-next';
- var CLASS_NAME_PREV = 'carousel-item-prev';
- var CLASS_NAME_POINTER_EVENT = 'pointer-event';
- var SELECTOR_ACTIVE = '.active';
- var SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
- var SELECTOR_ITEM = '.carousel-item';
- var SELECTOR_ITEM_IMG = '.carousel-item img';
- var SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
- var SELECTOR_INDICATORS = '.carousel-indicators';
- var SELECTOR_DATA_SLIDE = '[data-slide], [data-slide-to]';
- var SELECTOR_DATA_RIDE = '[data-ride="carousel"]';
- var PointerType = {
- TOUCH: 'touch',
- PEN: 'pen'
+ const ORDER_NEXT = 'next';
+ 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}`;
+ const EVENT_MOUSEENTER = `mouseenter${EVENT_KEY}`;
+ const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY}`;
+ const EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`;
+ const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`;
+ const EVENT_TOUCHEND = `touchend${EVENT_KEY}`;
+ const EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`;
+ const EVENT_POINTERUP = `pointerup${EVENT_KEY}`;
+ const EVENT_DRAG_START = `dragstart${EVENT_KEY}`;
+ const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}`;
+ const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
+ const CLASS_NAME_CAROUSEL = 'carousel';
+ const CLASS_NAME_ACTIVE = 'active';
+ const CLASS_NAME_SLIDE = 'slide';
+ const CLASS_NAME_END = 'carousel-item-end';
+ const CLASS_NAME_START = 'carousel-item-start';
+ const CLASS_NAME_NEXT = 'carousel-item-next';
+ const CLASS_NAME_PREV = 'carousel-item-prev';
+ const CLASS_NAME_POINTER_EVENT = 'pointer-event';
+ const SELECTOR_ACTIVE = '.active';
+ const SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
+ const SELECTOR_ITEM = '.carousel-item';
+ const SELECTOR_ITEM_IMG = '.carousel-item img';
+ const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
+ const SELECTOR_INDICATORS = '.carousel-indicators';
+ const SELECTOR_INDICATOR = '[data-bs-target]';
+ const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]';
+ const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]';
+ const POINTER_TYPE_TOUCH = 'touch';
+ const POINTER_TYPE_PEN = 'pen';
/**
* ------------------------------------------------------------------------
* Class Definition
* ------------------------------------------------------------------------
*/
- var Carousel = /*#__PURE__*/function () {
- function Carousel(element, config) {
+ class Carousel extends BaseComponent__default['default'] {
+ constructor(element, config) {
+ super(element);
this._items = null;
this._interval = null;
this._activeElement = null;
@@ -137,54 +265,54 @@
this.touchStartX = 0;
this.touchDeltaX = 0;
this._config = this._getConfig(config);
- this._element = element;
- this._indicatorsElement = this._element.querySelector(SELECTOR_INDICATORS);
+ this._indicatorsElement = SelectorEngine__default['default'].findOne(SELECTOR_INDICATORS, this._element);
this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
- this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent);
+ this._pointerEvent = Boolean(window.PointerEvent);
this._addEventListeners();
} // Getters
- var _proto = Carousel.prototype;
+ static get Default() {
+ return Default;
+ }
- // Public
- _proto.next = function next() {
- if (!this._isSliding) {
- this._slide(DIRECTION_NEXT);
- }
- };
+ static get NAME() {
+ return NAME;
+ } // Public
- _proto.nextWhenVisible = function nextWhenVisible() {
- var $element = $__default['default'](this._element); // Don't call next when the page isn't visible
- // or the carousel or its parent isn't visible
- if (!document.hidden && $element.is(':visible') && $element.css('visibility') !== 'hidden') {
+ next() {
+ this._slide(ORDER_NEXT);
+ }
+
+ nextWhenVisible() {
+ // Don't call next when the page isn't visible
+ // or the carousel or its parent isn't visible
+ if (!document.hidden && isVisible(this._element)) {
this.next();
}
- };
+ }
- _proto.prev = function prev() {
- if (!this._isSliding) {
- this._slide(DIRECTION_PREV);
- }
- };
+ prev() {
+ this._slide(ORDER_PREV);
+ }
- _proto.pause = function pause(event) {
+ pause(event) {
if (!event) {
this._isPaused = true;
}
- if (this._element.querySelector(SELECTOR_NEXT_PREV)) {
- Util__default['default'].triggerTransitionEnd(this._element);
+ if (SelectorEngine__default['default'].findOne(SELECTOR_NEXT_PREV, this._element)) {
+ triggerTransitionEnd(this._element);
this.cycle(true);
}
clearInterval(this._interval);
this._interval = null;
- };
+ }
- _proto.cycle = function cycle(event) {
+ cycle(event) {
if (!event) {
this._isPaused = false;
}
@@ -194,28 +322,24 @@
this._interval = null;
}
- if (this._config.interval && !this._isPaused) {
+ if (this._config && this._config.interval && !this._isPaused) {
this._updateInterval();
this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
}
- };
-
- _proto.to = function to(index) {
- var _this = this;
+ }
- this._activeElement = this._element.querySelector(SELECTOR_ACTIVE_ITEM);
+ to(index) {
+ this._activeElement = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
- var activeIndex = this._getItemIndex(this._activeElement);
+ const activeIndex = this._getItemIndex(this._activeElement);
if (index > this._items.length - 1 || index < 0) {
return;
}
if (this._isSliding) {
- $__default['default'](this._element).one(EVENT_SLID, function () {
- return _this.to(index);
- });
+ EventHandler__default['default'].one(this._element, EVENT_SLID, () => this.to(index));
return;
}
@@ -225,105 +349,75 @@
return;
}
- var direction = index > activeIndex ? DIRECTION_NEXT : DIRECTION_PREV;
-
- this._slide(direction, this._items[index]);
- };
+ const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV;
- _proto.dispose = function dispose() {
- $__default['default'](this._element).off(EVENT_KEY);
- $__default['default'].removeData(this._element, DATA_KEY);
- this._items = null;
- this._config = null;
- this._element = null;
- this._interval = null;
- this._isPaused = null;
- this._isSliding = null;
- this._activeElement = null;
- this._indicatorsElement = null;
+ this._slide(order, this._items[index]);
} // Private
- ;
- _proto._getConfig = function _getConfig(config) {
- config = _extends({}, Default, config);
- Util__default['default'].typeCheckConfig(NAME, config, DefaultType);
+
+ _getConfig(config) {
+ config = { ...Default,
+ ...Manipulator__default['default'].getDataAttributes(this._element),
+ ...(typeof config === 'object' ? config : {})
+ };
+ typeCheckConfig(NAME, config, DefaultType);
return config;
- };
+ }
- _proto._handleSwipe = function _handleSwipe() {
- var absDeltax = Math.abs(this.touchDeltaX);
+ _handleSwipe() {
+ const absDeltax = Math.abs(this.touchDeltaX);
if (absDeltax <= SWIPE_THRESHOLD) {
return;
}
- var direction = absDeltax / this.touchDeltaX;
- this.touchDeltaX = 0; // swipe left
-
- if (direction > 0) {
- this.prev();
- } // swipe right
-
+ const direction = absDeltax / this.touchDeltaX;
+ this.touchDeltaX = 0;
- if (direction < 0) {
- this.next();
+ if (!direction) {
+ return;
}
- };
- _proto._addEventListeners = function _addEventListeners() {
- var _this2 = this;
+ this._slide(direction > 0 ? DIRECTION_RIGHT : DIRECTION_LEFT);
+ }
+ _addEventListeners() {
if (this._config.keyboard) {
- $__default['default'](this._element).on(EVENT_KEYDOWN, function (event) {
- return _this2._keydown(event);
- });
+ EventHandler__default['default'].on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
}
if (this._config.pause === 'hover') {
- $__default['default'](this._element).on(EVENT_MOUSEENTER, function (event) {
- return _this2.pause(event);
- }).on(EVENT_MOUSELEAVE, function (event) {
- return _this2.cycle(event);
- });
+ EventHandler__default['default'].on(this._element, EVENT_MOUSEENTER, event => this.pause(event));
+ EventHandler__default['default'].on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event));
}
- if (this._config.touch) {
+ if (this._config.touch && this._touchSupported) {
this._addTouchEventListeners();
}
- };
-
- _proto._addTouchEventListeners = function _addTouchEventListeners() {
- var _this3 = this;
-
- if (!this._touchSupported) {
- return;
- }
+ }
- var start = function start(event) {
- if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
- _this3.touchStartX = event.originalEvent.clientX;
- } else if (!_this3._pointerEvent) {
- _this3.touchStartX = event.originalEvent.touches[0].clientX;
+ _addTouchEventListeners() {
+ const start = event => {
+ if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
+ this.touchStartX = event.clientX;
+ } else if (!this._pointerEvent) {
+ this.touchStartX = event.touches[0].clientX;
}
};
- var move = function move(event) {
+ const move = event => {
// ensure swiping with one touch and not pinching
- if (event.originalEvent.touches && event.originalEvent.touches.length > 1) {
- _this3.touchDeltaX = 0;
- } else {
- _this3.touchDeltaX = event.originalEvent.touches[0].clientX - _this3.touchStartX;
- }
+ this.touchDeltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this.touchStartX;
};
- var end = function end(event) {
- if (_this3._pointerEvent && PointerType[event.originalEvent.pointerType.toUpperCase()]) {
- _this3.touchDeltaX = event.originalEvent.clientX - _this3.touchStartX;
+ const end = event => {
+ if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
+ this.touchDeltaX = event.clientX - this.touchStartX;
}
- _this3._handleSwipe();
+ this._handleSwipe();
- if (_this3._config.pause === 'hover') {
+ if (this._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;
@@ -331,121 +425,94 @@
// (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();
+ this.pause();
- if (_this3.touchTimeout) {
- clearTimeout(_this3.touchTimeout);
+ if (this.touchTimeout) {
+ clearTimeout(this.touchTimeout);
}
- _this3.touchTimeout = setTimeout(function (event) {
- return _this3.cycle(event);
- }, TOUCHEVENT_COMPAT_WAIT + _this3._config.interval);
+ this.touchTimeout = setTimeout(event => this.cycle(event), TOUCHEVENT_COMPAT_WAIT + this._config.interval);
}
};
- $__default['default'](this._element.querySelectorAll(SELECTOR_ITEM_IMG)).on(EVENT_DRAG_START, function (e) {
- return e.preventDefault();
+ SelectorEngine__default['default'].find(SELECTOR_ITEM_IMG, this._element).forEach(itemImg => {
+ EventHandler__default['default'].on(itemImg, EVENT_DRAG_START, e => e.preventDefault());
});
if (this._pointerEvent) {
- $__default['default'](this._element).on(EVENT_POINTERDOWN, function (event) {
- return start(event);
- });
- $__default['default'](this._element).on(EVENT_POINTERUP, function (event) {
- return end(event);
- });
+ EventHandler__default['default'].on(this._element, EVENT_POINTERDOWN, event => start(event));
+ EventHandler__default['default'].on(this._element, EVENT_POINTERUP, event => end(event));
this._element.classList.add(CLASS_NAME_POINTER_EVENT);
} else {
- $__default['default'](this._element).on(EVENT_TOUCHSTART, function (event) {
- return start(event);
- });
- $__default['default'](this._element).on(EVENT_TOUCHMOVE, function (event) {
- return move(event);
- });
- $__default['default'](this._element).on(EVENT_TOUCHEND, function (event) {
- return end(event);
- });
+ EventHandler__default['default'].on(this._element, EVENT_TOUCHSTART, event => start(event));
+ EventHandler__default['default'].on(this._element, EVENT_TOUCHMOVE, event => move(event));
+ EventHandler__default['default'].on(this._element, EVENT_TOUCHEND, event => end(event));
}
- };
+ }
- _proto._keydown = function _keydown(event) {
+ _keydown(event) {
if (/input|textarea/i.test(event.target.tagName)) {
return;
}
- switch (event.which) {
- case ARROW_LEFT_KEYCODE:
- event.preventDefault();
- this.prev();
- break;
+ const direction = KEY_TO_DIRECTION[event.key];
- case ARROW_RIGHT_KEYCODE:
- event.preventDefault();
- this.next();
- break;
+ if (direction) {
+ event.preventDefault();
+
+ this._slide(direction);
}
- };
+ }
- _proto._getItemIndex = function _getItemIndex(element) {
- this._items = element && element.parentNode ? [].slice.call(element.parentNode.querySelectorAll(SELECTOR_ITEM)) : [];
+ _getItemIndex(element) {
+ this._items = element && element.parentNode ? SelectorEngine__default['default'].find(SELECTOR_ITEM, element.parentNode) : [];
return this._items.indexOf(element);
- };
-
- _proto._getItemByDirection = function _getItemByDirection(direction, activeElement) {
- var isNextDirection = direction === DIRECTION_NEXT;
- var isPrevDirection = direction === DIRECTION_PREV;
-
- var activeIndex = this._getItemIndex(activeElement);
-
- var lastItemIndex = this._items.length - 1;
- var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
-
- if (isGoingToWrap && !this._config.wrap) {
- return activeElement;
- }
+ }
- 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];
- };
+ _getItemByOrder(order, activeElement) {
+ const isNext = order === ORDER_NEXT;
+ return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap);
+ }
- _proto._triggerSlideEvent = function _triggerSlideEvent(relatedTarget, eventDirectionName) {
- var targetIndex = this._getItemIndex(relatedTarget);
+ _triggerSlideEvent(relatedTarget, eventDirectionName) {
+ const targetIndex = this._getItemIndex(relatedTarget);
- var fromIndex = this._getItemIndex(this._element.querySelector(SELECTOR_ACTIVE_ITEM));
+ const fromIndex = this._getItemIndex(SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element));
- var slideEvent = $__default['default'].Event(EVENT_SLIDE, {
- relatedTarget: relatedTarget,
+ return EventHandler__default['default'].trigger(this._element, EVENT_SLIDE, {
+ relatedTarget,
direction: eventDirectionName,
from: fromIndex,
to: targetIndex
});
- $__default['default'](this._element).trigger(slideEvent);
- return slideEvent;
- };
+ }
- _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) {
+ _setActiveIndicatorElement(element) {
if (this._indicatorsElement) {
- var indicators = [].slice.call(this._indicatorsElement.querySelectorAll(SELECTOR_ACTIVE));
- $__default['default'](indicators).removeClass(CLASS_NAME_ACTIVE);
-
- var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
-
- if (nextIndicator) {
- $__default['default'](nextIndicator).addClass(CLASS_NAME_ACTIVE);
+ const activeIndicator = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE, this._indicatorsElement);
+ activeIndicator.classList.remove(CLASS_NAME_ACTIVE);
+ activeIndicator.removeAttribute('aria-current');
+ const indicators = SelectorEngine__default['default'].find(SELECTOR_INDICATOR, this._indicatorsElement);
+
+ for (let i = 0; i < indicators.length; i++) {
+ if (Number.parseInt(indicators[i].getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) {
+ indicators[i].classList.add(CLASS_NAME_ACTIVE);
+ indicators[i].setAttribute('aria-current', 'true');
+ break;
+ }
}
}
- };
+ }
- _proto._updateInterval = function _updateInterval() {
- var element = this._activeElement || this._element.querySelector(SELECTOR_ACTIVE_ITEM);
+ _updateInterval() {
+ const element = this._activeElement || SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
if (!element) {
return;
}
- var elementInterval = parseInt(element.getAttribute('data-interval'), 10);
+ const elementInterval = Number.parseInt(element.getAttribute('data-bs-interval'), 10);
if (elementInterval) {
this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
@@ -453,42 +520,38 @@
} else {
this._config.interval = this._config.defaultInterval || this._config.interval;
}
- };
+ }
- _proto._slide = function _slide(direction, element) {
- var _this4 = this;
+ _slide(directionOrOrder, element) {
+ const order = this._directionToOrder(directionOrOrder);
- var activeElement = this._element.querySelector(SELECTOR_ACTIVE_ITEM);
+ const activeElement = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
- var activeElementIndex = this._getItemIndex(activeElement);
+ const activeElementIndex = this._getItemIndex(activeElement);
- var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
+ const nextElement = element || this._getItemByOrder(order, activeElement);
- var nextElementIndex = this._getItemIndex(nextElement);
+ const nextElementIndex = this._getItemIndex(nextElement);
- var isCycling = Boolean(this._interval);
- var directionalClassName;
- var orderClassName;
- var eventDirectionName;
+ const isCycling = Boolean(this._interval);
+ const isNext = order === ORDER_NEXT;
+ const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END;
+ const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV;
- if (direction === DIRECTION_NEXT) {
- directionalClassName = CLASS_NAME_LEFT;
- orderClassName = CLASS_NAME_NEXT;
- eventDirectionName = DIRECTION_LEFT;
- } else {
- directionalClassName = CLASS_NAME_RIGHT;
- orderClassName = CLASS_NAME_PREV;
- eventDirectionName = DIRECTION_RIGHT;
- }
+ const eventDirectionName = this._orderToDirection(order);
- if (nextElement && $__default['default'](nextElement).hasClass(CLASS_NAME_ACTIVE)) {
+ if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
this._isSliding = false;
return;
}
- var slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
+ if (this._isSliding) {
+ return;
+ }
+
+ const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
- if (slideEvent.isDefaultPrevented()) {
+ if (slideEvent.defaultPrevented) {
return;
}
@@ -506,116 +569,128 @@
this._setActiveIndicatorElement(nextElement);
this._activeElement = nextElement;
- var slidEvent = $__default['default'].Event(EVENT_SLID, {
- relatedTarget: nextElement,
- direction: eventDirectionName,
- from: activeElementIndex,
- to: nextElementIndex
- });
- if ($__default['default'](this._element).hasClass(CLASS_NAME_SLIDE)) {
- $__default['default'](nextElement).addClass(orderClassName);
- Util__default['default'].reflow(nextElement);
- $__default['default'](activeElement).addClass(directionalClassName);
- $__default['default'](nextElement).addClass(directionalClassName);
- var transitionDuration = Util__default['default'].getTransitionDurationFromElement(activeElement);
- $__default['default'](activeElement).one(Util__default['default'].TRANSITION_END, function () {
- $__default['default'](nextElement).removeClass(directionalClassName + " " + orderClassName).addClass(CLASS_NAME_ACTIVE);
- $__default['default'](activeElement).removeClass(CLASS_NAME_ACTIVE + " " + orderClassName + " " + directionalClassName);
- _this4._isSliding = false;
- setTimeout(function () {
- return $__default['default'](_this4._element).trigger(slidEvent);
- }, 0);
- }).emulateTransitionEnd(transitionDuration);
+ const triggerSlidEvent = () => {
+ EventHandler__default['default'].trigger(this._element, EVENT_SLID, {
+ relatedTarget: nextElement,
+ direction: eventDirectionName,
+ from: activeElementIndex,
+ to: nextElementIndex
+ });
+ };
+
+ if (this._element.classList.contains(CLASS_NAME_SLIDE)) {
+ nextElement.classList.add(orderClassName);
+ reflow(nextElement);
+ activeElement.classList.add(directionalClassName);
+ nextElement.classList.add(directionalClassName);
+
+ const completeCallBack = () => {
+ nextElement.classList.remove(directionalClassName, orderClassName);
+ nextElement.classList.add(CLASS_NAME_ACTIVE);
+ activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName);
+ this._isSliding = false;
+ setTimeout(triggerSlidEvent, 0);
+ };
+
+ this._queueCallback(completeCallBack, activeElement, true);
} else {
- $__default['default'](activeElement).removeClass(CLASS_NAME_ACTIVE);
- $__default['default'](nextElement).addClass(CLASS_NAME_ACTIVE);
+ activeElement.classList.remove(CLASS_NAME_ACTIVE);
+ nextElement.classList.add(CLASS_NAME_ACTIVE);
this._isSliding = false;
- $__default['default'](this._element).trigger(slidEvent);
+ triggerSlidEvent();
}
if (isCycling) {
this.cycle();
}
- } // Static
- ;
+ }
- Carousel._jQueryInterface = function _jQueryInterface(config) {
- return this.each(function () {
- var data = $__default['default'](this).data(DATA_KEY);
+ _directionToOrder(direction) {
+ if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
+ return direction;
+ }
- var _config = _extends({}, Default, $__default['default'](this).data());
+ if (isRTL()) {
+ return direction === DIRECTION_LEFT ? ORDER_PREV : ORDER_NEXT;
+ }
- if (typeof config === 'object') {
- _config = _extends({}, _config, config);
- }
+ return direction === DIRECTION_LEFT ? ORDER_NEXT : ORDER_PREV;
+ }
- var action = typeof config === 'string' ? config : _config.slide;
+ _orderToDirection(order) {
+ if (![ORDER_NEXT, ORDER_PREV].includes(order)) {
+ return order;
+ }
- if (!data) {
- data = new Carousel(this, _config);
- $__default['default'](this).data(DATA_KEY, data);
- }
+ if (isRTL()) {
+ return order === ORDER_PREV ? DIRECTION_LEFT : DIRECTION_RIGHT;
+ }
- if (typeof config === 'number') {
- data.to(config);
- } else if (typeof action === 'string') {
- if (typeof data[action] === 'undefined') {
- throw new TypeError("No method named \"" + action + "\"");
- }
+ return order === ORDER_PREV ? DIRECTION_RIGHT : DIRECTION_LEFT;
+ } // Static
- data[action]();
- } else if (_config.interval && _config.ride) {
- data.pause();
- data.cycle();
- }
- });
- };
- Carousel._dataApiClickHandler = function _dataApiClickHandler(event) {
- var selector = Util__default['default'].getSelectorFromElement(this);
+ static carouselInterface(element, config) {
+ const data = Carousel.getOrCreateInstance(element, config);
+ let {
+ _config
+ } = data;
- if (!selector) {
- return;
+ if (typeof config === 'object') {
+ _config = { ..._config,
+ ...config
+ };
}
- var target = $__default['default'](selector)[0];
+ const action = typeof config === 'string' ? config : _config.slide;
- if (!target || !$__default['default'](target).hasClass(CLASS_NAME_CAROUSEL)) {
- return;
+ if (typeof config === 'number') {
+ data.to(config);
+ } else if (typeof action === 'string') {
+ if (typeof data[action] === 'undefined') {
+ throw new TypeError(`No method named "${action}"`);
+ }
+
+ data[action]();
+ } else if (_config.interval && _config.ride) {
+ data.pause();
+ data.cycle();
}
+ }
+
+ static jQueryInterface(config) {
+ return this.each(function () {
+ Carousel.carouselInterface(this, config);
+ });
+ }
- var config = _extends({}, $__default['default'](target).data(), $__default['default'](this).data());
+ static dataApiClickHandler(event) {
+ const target = getElementFromSelector(this);
+
+ if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
+ return;
+ }
- var slideIndex = this.getAttribute('data-slide-to');
+ const config = { ...Manipulator__default['default'].getDataAttributes(target),
+ ...Manipulator__default['default'].getDataAttributes(this)
+ };
+ const slideIndex = this.getAttribute('data-bs-slide-to');
if (slideIndex) {
config.interval = false;
}
- Carousel._jQueryInterface.call($__default['default'](target), config);
+ Carousel.carouselInterface(target, config);
if (slideIndex) {
- $__default['default'](target).data(DATA_KEY).to(slideIndex);
+ Carousel.getInstance(target).to(slideIndex);
}
event.preventDefault();
- };
-
- _createClass(Carousel, null, [{
- key: "VERSION",
- get: function get() {
- return VERSION;
- }
- }, {
- key: "Default",
- get: function get() {
- return Default;
- }
- }]);
+ }
- return Carousel;
- }();
+ }
/**
* ------------------------------------------------------------------------
* Data Api implementation
@@ -623,29 +698,22 @@
*/
- $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel._dataApiClickHandler);
- $__default['default'](window).on(EVENT_LOAD_DATA_API, function () {
- var carousels = [].slice.call(document.querySelectorAll(SELECTOR_DATA_RIDE));
-
- for (var i = 0, len = carousels.length; i < len; i++) {
- var $carousel = $__default['default'](carousels[i]);
+ EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler);
+ EventHandler__default['default'].on(window, EVENT_LOAD_DATA_API, () => {
+ const carousels = SelectorEngine__default['default'].find(SELECTOR_DATA_RIDE);
- Carousel._jQueryInterface.call($carousel, $carousel.data());
+ for (let i = 0, len = carousels.length; i < len; i++) {
+ Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i]));
}
});
/**
* ------------------------------------------------------------------------
* jQuery
* ------------------------------------------------------------------------
+ * add .Carousel to jQuery only if jQuery is present
*/
- $__default['default'].fn[NAME] = Carousel._jQueryInterface;
- $__default['default'].fn[NAME].Constructor = Carousel;
-
- $__default['default'].fn[NAME].noConflict = function () {
- $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
- return Carousel._jQueryInterface;
- };
+ defineJQueryPlugin(Carousel);
return Carousel;