diff options
Diffstat (limited to 'js/dist/carousel.js')
-rw-r--r-- | js/dist/carousel.js | 241 |
1 files changed, 131 insertions, 110 deletions
diff --git a/js/dist/carousel.js b/js/dist/carousel.js index 8b1ce3e7d7..ac6e8455b5 100644 --- a/js/dist/carousel.js +++ b/js/dist/carousel.js @@ -1,13 +1,13 @@ /*! - * Bootstrap carousel.js v5.0.0-beta1 (https://getbootstrap.com/) - * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors) + * Bootstrap carousel.js v5.0.0-beta2 (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/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js')) : - typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './dom/manipulator', './dom/selector-engine'], factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine)); -}(this, (function (Data, EventHandler, Manipulator, SelectorEngine) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/event-handler.js'), require('./dom/manipulator.js'), require('./dom/selector-engine.js'), require('./base-component.js')) : + typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler', './dom/manipulator', './dom/selector-engine', './base-component'], factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine, global.Base)); +}(this, (function (Data, EventHandler, Manipulator, SelectorEngine, BaseComponent) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } @@ -15,10 +15,61 @@ var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler); var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator); var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine); + 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); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + if (staticProps) _defineProperties(Constructor, staticProps); + return Constructor; + } + + function _extends() { + _extends = Object.assign || function (target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i]; + + for (var key in source) { + if (Object.prototype.hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + + return target; + }; + + return _extends.apply(this, arguments); + } + + function _inheritsLoose(subClass, superClass) { + subClass.prototype = Object.create(superClass.prototype); + subClass.prototype.constructor = subClass; + + _setPrototypeOf(subClass, superClass); + } + + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta1): util/index.js + * Bootstrap (v5.0.0-beta2): util/index.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ @@ -37,7 +88,20 @@ var selector = element.getAttribute('data-bs-target'); if (!selector || selector === '#') { - var hrefAttr = element.getAttribute('href'); + var 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]; + } + selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null; } @@ -105,7 +169,7 @@ 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 + "\".")); + throw new TypeError(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\".")); } }); }; @@ -149,57 +213,24 @@ var isRTL = document.documentElement.dir === 'rtl'; - 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; } - /** - * ------------------------------------------------------------------------ - * Constants - * ------------------------------------------------------------------------ - */ - - var VERSION = '5.0.0-beta1'; - - var BaseComponent = /*#__PURE__*/function () { - function BaseComponent(element) { - if (!element) { - return; - } - - this._element = element; - Data__default['default'].setData(element, this.constructor.DATA_KEY, this); - } + var defineJQueryPlugin = function defineJQueryPlugin(name, plugin) { + onDOMContentLoaded(function () { + var $ = getjQuery(); + /* istanbul ignore if */ - var _proto = BaseComponent.prototype; - - _proto.dispose = function dispose() { - Data__default['default'].removeData(this._element, this.constructor.DATA_KEY); - this._element = null; - } - /** Static */ - ; - - BaseComponent.getInstance = function getInstance(element) { - return Data__default['default'].getData(element, this.DATA_KEY); - }; + if ($) { + var JQUERY_NO_CONFLICT = $.fn[name]; + $.fn[name] = plugin.jQueryInterface; + $.fn[name].Constructor = plugin; - _createClass(BaseComponent, null, [{ - key: "VERSION", - get: function get() { - return VERSION; + $.fn[name].noConflict = function () { + $.fn[name] = JQUERY_NO_CONFLICT; + return plugin.jQueryInterface; + }; } - }]); - - return BaseComponent; - }(); - - function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } - - function _defineProperties$1(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$1(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties$1(Constructor.prototype, protoProps); if (staticProps) _defineProperties$1(Constructor, staticProps); return Constructor; } + }); + }; - function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } /** * ------------------------------------------------------------------------ * Constants @@ -262,12 +293,11 @@ var SELECTOR_ITEM_IMG = '.carousel-item img'; var SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev'; var SELECTOR_INDICATORS = '.carousel-indicators'; + var SELECTOR_INDICATOR = '[data-bs-target]'; var SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]'; var SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]'; - var PointerType = { - TOUCH: 'touch', - PEN: 'pen' - }; + var POINTER_TYPE_TOUCH = 'touch'; + var POINTER_TYPE_PEN = 'pen'; /** * ------------------------------------------------------------------------ * Class Definition @@ -414,12 +444,20 @@ this.touchDeltaX = 0; // swipe left if (direction > 0) { - this.prev(); + if (isRTL) { + this.next(); + } else { + this.prev(); + } } // swipe right if (direction < 0) { - this.next(); + if (isRTL) { + this.prev(); + } else { + this.next(); + } } }; @@ -450,7 +488,7 @@ var _this4 = this; var start = function start(event) { - if (_this4._pointerEvent && PointerType[event.pointerType.toUpperCase()]) { + if (_this4._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) { _this4.touchStartX = event.clientX; } else if (!_this4._pointerEvent) { _this4.touchStartX = event.touches[0].clientX; @@ -467,7 +505,7 @@ }; var end = function end(event) { - if (_this4._pointerEvent && PointerType[event.pointerType.toUpperCase()]) { + if (_this4._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) { _this4.touchDeltaX = event.clientX - _this4.touchStartX; } @@ -526,16 +564,22 @@ return; } - switch (event.key) { - case ARROW_LEFT_KEY: - event.preventDefault(); + if (event.key === ARROW_LEFT_KEY) { + event.preventDefault(); + + if (isRTL) { + this.next(); + } else { this.prev(); - break; + } + } else if (event.key === ARROW_RIGHT_KEY) { + event.preventDefault(); - case ARROW_RIGHT_KEY: - event.preventDefault(); + if (isRTL) { + this.prev(); + } else { this.next(); - break; + } } }; @@ -577,16 +621,17 @@ _proto._setActiveIndicatorElement = function _setActiveIndicatorElement(element) { if (this._indicatorsElement) { - var indicators = SelectorEngine__default['default'].find(SELECTOR_ACTIVE, this._indicatorsElement); + var activeIndicator = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE, this._indicatorsElement); + activeIndicator.classList.remove(CLASS_NAME_ACTIVE); + activeIndicator.removeAttribute('aria-current'); + var indicators = SelectorEngine__default['default'].find(SELECTOR_INDICATOR, this._indicatorsElement); for (var i = 0; i < indicators.length; i++) { - indicators[i].classList.remove(CLASS_NAME_ACTIVE); - } - - var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)]; - - if (nextIndicator) { - nextIndicator.classList.add(CLASS_NAME_ACTIVE); + 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; + } } } }; @@ -620,19 +665,9 @@ var nextElementIndex = this._getItemIndex(nextElement); var isCycling = Boolean(this._interval); - var directionalClassName; - var orderClassName; - var eventDirectionName; - - if (direction === DIRECTION_NEXT) { - directionalClassName = CLASS_NAME_START; - orderClassName = CLASS_NAME_NEXT; - eventDirectionName = DIRECTION_LEFT; - } else { - directionalClassName = CLASS_NAME_END; - orderClassName = CLASS_NAME_PREV; - eventDirectionName = DIRECTION_RIGHT; - } + var directionalClassName = direction === DIRECTION_NEXT ? CLASS_NAME_START : CLASS_NAME_END; + var orderClassName = direction === DIRECTION_NEXT ? CLASS_NAME_NEXT : CLASS_NAME_PREV; + var eventDirectionName = direction === DIRECTION_NEXT ? DIRECTION_LEFT : DIRECTION_RIGHT; if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) { this._isSliding = false; @@ -666,7 +701,7 @@ activeElement.classList.add(directionalClassName); nextElement.classList.add(directionalClassName); var transitionDuration = getTransitionDurationFromElement(activeElement); - EventHandler__default['default'].one(activeElement, TRANSITION_END, function () { + EventHandler__default['default'].one(activeElement, 'transitionend', function () { nextElement.classList.remove(directionalClassName, orderClassName); nextElement.classList.add(CLASS_NAME_ACTIVE); activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName); @@ -758,7 +793,7 @@ event.preventDefault(); }; - _createClass$1(Carousel, null, [{ + _createClass(Carousel, null, [{ key: "Default", get: function get() { return Default; @@ -771,7 +806,7 @@ }]); return Carousel; - }(BaseComponent); + }(BaseComponent__default['default']); /** * ------------------------------------------------------------------------ * Data Api implementation @@ -794,21 +829,7 @@ * add .Carousel to jQuery only if jQuery is present */ - onDOMContentLoaded(function () { - var $ = getjQuery(); - /* istanbul ignore if */ - - if ($) { - var JQUERY_NO_CONFLICT = $.fn[NAME]; - $.fn[NAME] = Carousel.jQueryInterface; - $.fn[NAME].Constructor = Carousel; - - $.fn[NAME].noConflict = function () { - $.fn[NAME] = JQUERY_NO_CONFLICT; - return Carousel.jQueryInterface; - }; - } - }); + defineJQueryPlugin(NAME, Carousel); return Carousel; |