carousel.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*!
  2. * Bootstrap carousel.js v5.0.2 (https://getbootstrap.com/)
  3. * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  4. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  5. */
  6. (function (global, factory) {
  7. 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')) :
  8. typeof define === 'function' && define.amd ? define(['./dom/selector-engine', './dom/event-handler', './dom/manipulator', './base-component'], factory) :
  9. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Carousel = factory(global.SelectorEngine, global.EventHandler, global.Manipulator, global.Base));
  10. }(this, (function (SelectorEngine, EventHandler, Manipulator, BaseComponent) { 'use strict';
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var SelectorEngine__default = /*#__PURE__*/_interopDefaultLegacy(SelectorEngine);
  13. var EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
  14. var Manipulator__default = /*#__PURE__*/_interopDefaultLegacy(Manipulator);
  15. var BaseComponent__default = /*#__PURE__*/_interopDefaultLegacy(BaseComponent);
  16. const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
  17. const toType = obj => {
  18. if (obj === null || obj === undefined) {
  19. return `${obj}`;
  20. }
  21. return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  22. };
  23. const getSelector = element => {
  24. let selector = element.getAttribute('data-bs-target');
  25. if (!selector || selector === '#') {
  26. let hrefAttr = element.getAttribute('href'); // The only valid content that could double as a selector are IDs or classes,
  27. // so everything starting with `#` or `.`. If a "real" URL is used as the selector,
  28. // `document.querySelector` will rightfully complain it is invalid.
  29. // See https://github.com/twbs/bootstrap/issues/32273
  30. if (!hrefAttr || !hrefAttr.includes('#') && !hrefAttr.startsWith('.')) {
  31. return null;
  32. } // Just in case some CMS puts out a full URL with the anchor appended
  33. if (hrefAttr.includes('#') && !hrefAttr.startsWith('#')) {
  34. hrefAttr = `#${hrefAttr.split('#')[1]}`;
  35. }
  36. selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
  37. }
  38. return selector;
  39. };
  40. const getElementFromSelector = element => {
  41. const selector = getSelector(element);
  42. return selector ? document.querySelector(selector) : null;
  43. };
  44. const triggerTransitionEnd = element => {
  45. element.dispatchEvent(new Event(TRANSITION_END));
  46. };
  47. const isElement = obj => {
  48. if (!obj || typeof obj !== 'object') {
  49. return false;
  50. }
  51. if (typeof obj.jquery !== 'undefined') {
  52. obj = obj[0];
  53. }
  54. return typeof obj.nodeType !== 'undefined';
  55. };
  56. const typeCheckConfig = (componentName, config, configTypes) => {
  57. Object.keys(configTypes).forEach(property => {
  58. const expectedTypes = configTypes[property];
  59. const value = config[property];
  60. const valueType = value && isElement(value) ? 'element' : toType(value);
  61. if (!new RegExp(expectedTypes).test(valueType)) {
  62. throw new TypeError(`${componentName.toUpperCase()}: Option "${property}" provided type "${valueType}" but expected type "${expectedTypes}".`);
  63. }
  64. });
  65. };
  66. const isVisible = element => {
  67. if (!isElement(element) || element.getClientRects().length === 0) {
  68. return false;
  69. }
  70. return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
  71. };
  72. const reflow = element => element.offsetHeight;
  73. const getjQuery = () => {
  74. const {
  75. jQuery
  76. } = window;
  77. if (jQuery && !document.body.hasAttribute('data-bs-no-jquery')) {
  78. return jQuery;
  79. }
  80. return null;
  81. };
  82. const DOMContentLoadedCallbacks = [];
  83. const onDOMContentLoaded = callback => {
  84. if (document.readyState === 'loading') {
  85. // add listener on the first call when the document is in loading state
  86. if (!DOMContentLoadedCallbacks.length) {
  87. document.addEventListener('DOMContentLoaded', () => {
  88. DOMContentLoadedCallbacks.forEach(callback => callback());
  89. });
  90. }
  91. DOMContentLoadedCallbacks.push(callback);
  92. } else {
  93. callback();
  94. }
  95. };
  96. const isRTL = () => document.documentElement.dir === 'rtl';
  97. const defineJQueryPlugin = plugin => {
  98. onDOMContentLoaded(() => {
  99. const $ = getjQuery();
  100. /* istanbul ignore if */
  101. if ($) {
  102. const name = plugin.NAME;
  103. const JQUERY_NO_CONFLICT = $.fn[name];
  104. $.fn[name] = plugin.jQueryInterface;
  105. $.fn[name].Constructor = plugin;
  106. $.fn[name].noConflict = () => {
  107. $.fn[name] = JQUERY_NO_CONFLICT;
  108. return plugin.jQueryInterface;
  109. };
  110. }
  111. });
  112. };
  113. /**
  114. * Return the previous/next element of a list.
  115. *
  116. * @param {array} list The list of elements
  117. * @param activeElement The active element
  118. * @param shouldGetNext Choose to get next or previous element
  119. * @param isCycleAllowed
  120. * @return {Element|elem} The proper element
  121. */
  122. const getNextActiveElement = (list, activeElement, shouldGetNext, isCycleAllowed) => {
  123. 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
  124. if (index === -1) {
  125. return list[!shouldGetNext && isCycleAllowed ? list.length - 1 : 0];
  126. }
  127. const listLength = list.length;
  128. index += shouldGetNext ? 1 : -1;
  129. if (isCycleAllowed) {
  130. index = (index + listLength) % listLength;
  131. }
  132. return list[Math.max(0, Math.min(index, listLength - 1))];
  133. };
  134. /**
  135. * --------------------------------------------------------------------------
  136. * Bootstrap (v5.0.2): carousel.js
  137. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
  138. * --------------------------------------------------------------------------
  139. */
  140. /**
  141. * ------------------------------------------------------------------------
  142. * Constants
  143. * ------------------------------------------------------------------------
  144. */
  145. const NAME = 'carousel';
  146. const DATA_KEY = 'bs.carousel';
  147. const EVENT_KEY = `.${DATA_KEY}`;
  148. const DATA_API_KEY = '.data-api';
  149. const ARROW_LEFT_KEY = 'ArrowLeft';
  150. const ARROW_RIGHT_KEY = 'ArrowRight';
  151. const TOUCHEVENT_COMPAT_WAIT = 500; // Time for mouse compat events to fire after touch
  152. const SWIPE_THRESHOLD = 40;
  153. const Default = {
  154. interval: 5000,
  155. keyboard: true,
  156. slide: false,
  157. pause: 'hover',
  158. wrap: true,
  159. touch: true
  160. };
  161. const DefaultType = {
  162. interval: '(number|boolean)',
  163. keyboard: 'boolean',
  164. slide: '(boolean|string)',
  165. pause: '(string|boolean)',
  166. wrap: 'boolean',
  167. touch: 'boolean'
  168. };
  169. const ORDER_NEXT = 'next';
  170. const ORDER_PREV = 'prev';
  171. const DIRECTION_LEFT = 'left';
  172. const DIRECTION_RIGHT = 'right';
  173. const KEY_TO_DIRECTION = {
  174. [ARROW_LEFT_KEY]: DIRECTION_RIGHT,
  175. [ARROW_RIGHT_KEY]: DIRECTION_LEFT
  176. };
  177. const EVENT_SLIDE = `slide${EVENT_KEY}`;
  178. const EVENT_SLID = `slid${EVENT_KEY}`;
  179. const EVENT_KEYDOWN = `keydown${EVENT_KEY}`;
  180. const EVENT_MOUSEENTER = `mouseenter${EVENT_KEY}`;
  181. const EVENT_MOUSELEAVE = `mouseleave${EVENT_KEY}`;
  182. const EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`;
  183. const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`;
  184. const EVENT_TOUCHEND = `touchend${EVENT_KEY}`;
  185. const EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`;
  186. const EVENT_POINTERUP = `pointerup${EVENT_KEY}`;
  187. const EVENT_DRAG_START = `dragstart${EVENT_KEY}`;
  188. const EVENT_LOAD_DATA_API = `load${EVENT_KEY}${DATA_API_KEY}`;
  189. const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
  190. const CLASS_NAME_CAROUSEL = 'carousel';
  191. const CLASS_NAME_ACTIVE = 'active';
  192. const CLASS_NAME_SLIDE = 'slide';
  193. const CLASS_NAME_END = 'carousel-item-end';
  194. const CLASS_NAME_START = 'carousel-item-start';
  195. const CLASS_NAME_NEXT = 'carousel-item-next';
  196. const CLASS_NAME_PREV = 'carousel-item-prev';
  197. const CLASS_NAME_POINTER_EVENT = 'pointer-event';
  198. const SELECTOR_ACTIVE = '.active';
  199. const SELECTOR_ACTIVE_ITEM = '.active.carousel-item';
  200. const SELECTOR_ITEM = '.carousel-item';
  201. const SELECTOR_ITEM_IMG = '.carousel-item img';
  202. const SELECTOR_NEXT_PREV = '.carousel-item-next, .carousel-item-prev';
  203. const SELECTOR_INDICATORS = '.carousel-indicators';
  204. const SELECTOR_INDICATOR = '[data-bs-target]';
  205. const SELECTOR_DATA_SLIDE = '[data-bs-slide], [data-bs-slide-to]';
  206. const SELECTOR_DATA_RIDE = '[data-bs-ride="carousel"]';
  207. const POINTER_TYPE_TOUCH = 'touch';
  208. const POINTER_TYPE_PEN = 'pen';
  209. /**
  210. * ------------------------------------------------------------------------
  211. * Class Definition
  212. * ------------------------------------------------------------------------
  213. */
  214. class Carousel extends BaseComponent__default['default'] {
  215. constructor(element, config) {
  216. super(element);
  217. this._items = null;
  218. this._interval = null;
  219. this._activeElement = null;
  220. this._isPaused = false;
  221. this._isSliding = false;
  222. this.touchTimeout = null;
  223. this.touchStartX = 0;
  224. this.touchDeltaX = 0;
  225. this._config = this._getConfig(config);
  226. this._indicatorsElement = SelectorEngine__default['default'].findOne(SELECTOR_INDICATORS, this._element);
  227. this._touchSupported = 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
  228. this._pointerEvent = Boolean(window.PointerEvent);
  229. this._addEventListeners();
  230. } // Getters
  231. static get Default() {
  232. return Default;
  233. }
  234. static get NAME() {
  235. return NAME;
  236. } // Public
  237. next() {
  238. this._slide(ORDER_NEXT);
  239. }
  240. nextWhenVisible() {
  241. // Don't call next when the page isn't visible
  242. // or the carousel or its parent isn't visible
  243. if (!document.hidden && isVisible(this._element)) {
  244. this.next();
  245. }
  246. }
  247. prev() {
  248. this._slide(ORDER_PREV);
  249. }
  250. pause(event) {
  251. if (!event) {
  252. this._isPaused = true;
  253. }
  254. if (SelectorEngine__default['default'].findOne(SELECTOR_NEXT_PREV, this._element)) {
  255. triggerTransitionEnd(this._element);
  256. this.cycle(true);
  257. }
  258. clearInterval(this._interval);
  259. this._interval = null;
  260. }
  261. cycle(event) {
  262. if (!event) {
  263. this._isPaused = false;
  264. }
  265. if (this._interval) {
  266. clearInterval(this._interval);
  267. this._interval = null;
  268. }
  269. if (this._config && this._config.interval && !this._isPaused) {
  270. this._updateInterval();
  271. this._interval = setInterval((document.visibilityState ? this.nextWhenVisible : this.next).bind(this), this._config.interval);
  272. }
  273. }
  274. to(index) {
  275. this._activeElement = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
  276. const activeIndex = this._getItemIndex(this._activeElement);
  277. if (index > this._items.length - 1 || index < 0) {
  278. return;
  279. }
  280. if (this._isSliding) {
  281. EventHandler__default['default'].one(this._element, EVENT_SLID, () => this.to(index));
  282. return;
  283. }
  284. if (activeIndex === index) {
  285. this.pause();
  286. this.cycle();
  287. return;
  288. }
  289. const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV;
  290. this._slide(order, this._items[index]);
  291. } // Private
  292. _getConfig(config) {
  293. config = { ...Default,
  294. ...Manipulator__default['default'].getDataAttributes(this._element),
  295. ...(typeof config === 'object' ? config : {})
  296. };
  297. typeCheckConfig(NAME, config, DefaultType);
  298. return config;
  299. }
  300. _handleSwipe() {
  301. const absDeltax = Math.abs(this.touchDeltaX);
  302. if (absDeltax <= SWIPE_THRESHOLD) {
  303. return;
  304. }
  305. const direction = absDeltax / this.touchDeltaX;
  306. this.touchDeltaX = 0;
  307. if (!direction) {
  308. return;
  309. }
  310. this._slide(direction > 0 ? DIRECTION_RIGHT : DIRECTION_LEFT);
  311. }
  312. _addEventListeners() {
  313. if (this._config.keyboard) {
  314. EventHandler__default['default'].on(this._element, EVENT_KEYDOWN, event => this._keydown(event));
  315. }
  316. if (this._config.pause === 'hover') {
  317. EventHandler__default['default'].on(this._element, EVENT_MOUSEENTER, event => this.pause(event));
  318. EventHandler__default['default'].on(this._element, EVENT_MOUSELEAVE, event => this.cycle(event));
  319. }
  320. if (this._config.touch && this._touchSupported) {
  321. this._addTouchEventListeners();
  322. }
  323. }
  324. _addTouchEventListeners() {
  325. const start = event => {
  326. if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
  327. this.touchStartX = event.clientX;
  328. } else if (!this._pointerEvent) {
  329. this.touchStartX = event.touches[0].clientX;
  330. }
  331. };
  332. const move = event => {
  333. // ensure swiping with one touch and not pinching
  334. this.touchDeltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this.touchStartX;
  335. };
  336. const end = event => {
  337. if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
  338. this.touchDeltaX = event.clientX - this.touchStartX;
  339. }
  340. this._handleSwipe();
  341. if (this._config.pause === 'hover') {
  342. // If it's a touch-enabled device, mouseenter/leave are fired as
  343. // part of the mouse compatibility events on first tap - the carousel
  344. // would stop cycling until user tapped out of it;
  345. // here, we listen for touchend, explicitly pause the carousel
  346. // (as if it's the second time we tap on it, mouseenter compat event
  347. // is NOT fired) and after a timeout (to allow for mouse compatibility
  348. // events to fire) we explicitly restart cycling
  349. this.pause();
  350. if (this.touchTimeout) {
  351. clearTimeout(this.touchTimeout);
  352. }
  353. this.touchTimeout = setTimeout(event => this.cycle(event), TOUCHEVENT_COMPAT_WAIT + this._config.interval);
  354. }
  355. };
  356. SelectorEngine__default['default'].find(SELECTOR_ITEM_IMG, this._element).forEach(itemImg => {
  357. EventHandler__default['default'].on(itemImg, EVENT_DRAG_START, e => e.preventDefault());
  358. });
  359. if (this._pointerEvent) {
  360. EventHandler__default['default'].on(this._element, EVENT_POINTERDOWN, event => start(event));
  361. EventHandler__default['default'].on(this._element, EVENT_POINTERUP, event => end(event));
  362. this._element.classList.add(CLASS_NAME_POINTER_EVENT);
  363. } else {
  364. EventHandler__default['default'].on(this._element, EVENT_TOUCHSTART, event => start(event));
  365. EventHandler__default['default'].on(this._element, EVENT_TOUCHMOVE, event => move(event));
  366. EventHandler__default['default'].on(this._element, EVENT_TOUCHEND, event => end(event));
  367. }
  368. }
  369. _keydown(event) {
  370. if (/input|textarea/i.test(event.target.tagName)) {
  371. return;
  372. }
  373. const direction = KEY_TO_DIRECTION[event.key];
  374. if (direction) {
  375. event.preventDefault();
  376. this._slide(direction);
  377. }
  378. }
  379. _getItemIndex(element) {
  380. this._items = element && element.parentNode ? SelectorEngine__default['default'].find(SELECTOR_ITEM, element.parentNode) : [];
  381. return this._items.indexOf(element);
  382. }
  383. _getItemByOrder(order, activeElement) {
  384. const isNext = order === ORDER_NEXT;
  385. return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap);
  386. }
  387. _triggerSlideEvent(relatedTarget, eventDirectionName) {
  388. const targetIndex = this._getItemIndex(relatedTarget);
  389. const fromIndex = this._getItemIndex(SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element));
  390. return EventHandler__default['default'].trigger(this._element, EVENT_SLIDE, {
  391. relatedTarget,
  392. direction: eventDirectionName,
  393. from: fromIndex,
  394. to: targetIndex
  395. });
  396. }
  397. _setActiveIndicatorElement(element) {
  398. if (this._indicatorsElement) {
  399. const activeIndicator = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE, this._indicatorsElement);
  400. activeIndicator.classList.remove(CLASS_NAME_ACTIVE);
  401. activeIndicator.removeAttribute('aria-current');
  402. const indicators = SelectorEngine__default['default'].find(SELECTOR_INDICATOR, this._indicatorsElement);
  403. for (let i = 0; i < indicators.length; i++) {
  404. if (Number.parseInt(indicators[i].getAttribute('data-bs-slide-to'), 10) === this._getItemIndex(element)) {
  405. indicators[i].classList.add(CLASS_NAME_ACTIVE);
  406. indicators[i].setAttribute('aria-current', 'true');
  407. break;
  408. }
  409. }
  410. }
  411. }
  412. _updateInterval() {
  413. const element = this._activeElement || SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
  414. if (!element) {
  415. return;
  416. }
  417. const elementInterval = Number.parseInt(element.getAttribute('data-bs-interval'), 10);
  418. if (elementInterval) {
  419. this._config.defaultInterval = this._config.defaultInterval || this._config.interval;
  420. this._config.interval = elementInterval;
  421. } else {
  422. this._config.interval = this._config.defaultInterval || this._config.interval;
  423. }
  424. }
  425. _slide(directionOrOrder, element) {
  426. const order = this._directionToOrder(directionOrOrder);
  427. const activeElement = SelectorEngine__default['default'].findOne(SELECTOR_ACTIVE_ITEM, this._element);
  428. const activeElementIndex = this._getItemIndex(activeElement);
  429. const nextElement = element || this._getItemByOrder(order, activeElement);
  430. const nextElementIndex = this._getItemIndex(nextElement);
  431. const isCycling = Boolean(this._interval);
  432. const isNext = order === ORDER_NEXT;
  433. const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END;
  434. const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV;
  435. const eventDirectionName = this._orderToDirection(order);
  436. if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
  437. this._isSliding = false;
  438. return;
  439. }
  440. if (this._isSliding) {
  441. return;
  442. }
  443. const slideEvent = this._triggerSlideEvent(nextElement, eventDirectionName);
  444. if (slideEvent.defaultPrevented) {
  445. return;
  446. }
  447. if (!activeElement || !nextElement) {
  448. // Some weirdness is happening, so we bail
  449. return;
  450. }
  451. this._isSliding = true;
  452. if (isCycling) {
  453. this.pause();
  454. }
  455. this._setActiveIndicatorElement(nextElement);
  456. this._activeElement = nextElement;
  457. const triggerSlidEvent = () => {
  458. EventHandler__default['default'].trigger(this._element, EVENT_SLID, {
  459. relatedTarget: nextElement,
  460. direction: eventDirectionName,
  461. from: activeElementIndex,
  462. to: nextElementIndex
  463. });
  464. };
  465. if (this._element.classList.contains(CLASS_NAME_SLIDE)) {
  466. nextElement.classList.add(orderClassName);
  467. reflow(nextElement);
  468. activeElement.classList.add(directionalClassName);
  469. nextElement.classList.add(directionalClassName);
  470. const completeCallBack = () => {
  471. nextElement.classList.remove(directionalClassName, orderClassName);
  472. nextElement.classList.add(CLASS_NAME_ACTIVE);
  473. activeElement.classList.remove(CLASS_NAME_ACTIVE, orderClassName, directionalClassName);
  474. this._isSliding = false;
  475. setTimeout(triggerSlidEvent, 0);
  476. };
  477. this._queueCallback(completeCallBack, activeElement, true);
  478. } else {
  479. activeElement.classList.remove(CLASS_NAME_ACTIVE);
  480. nextElement.classList.add(CLASS_NAME_ACTIVE);
  481. this._isSliding = false;
  482. triggerSlidEvent();
  483. }
  484. if (isCycling) {
  485. this.cycle();
  486. }
  487. }
  488. _directionToOrder(direction) {
  489. if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
  490. return direction;
  491. }
  492. if (isRTL()) {
  493. return direction === DIRECTION_LEFT ? ORDER_PREV : ORDER_NEXT;
  494. }
  495. return direction === DIRECTION_LEFT ? ORDER_NEXT : ORDER_PREV;
  496. }
  497. _orderToDirection(order) {
  498. if (![ORDER_NEXT, ORDER_PREV].includes(order)) {
  499. return order;
  500. }
  501. if (isRTL()) {
  502. return order === ORDER_PREV ? DIRECTION_LEFT : DIRECTION_RIGHT;
  503. }
  504. return order === ORDER_PREV ? DIRECTION_RIGHT : DIRECTION_LEFT;
  505. } // Static
  506. static carouselInterface(element, config) {
  507. const data = Carousel.getOrCreateInstance(element, config);
  508. let {
  509. _config
  510. } = data;
  511. if (typeof config === 'object') {
  512. _config = { ..._config,
  513. ...config
  514. };
  515. }
  516. const action = typeof config === 'string' ? config : _config.slide;
  517. if (typeof config === 'number') {
  518. data.to(config);
  519. } else if (typeof action === 'string') {
  520. if (typeof data[action] === 'undefined') {
  521. throw new TypeError(`No method named "${action}"`);
  522. }
  523. data[action]();
  524. } else if (_config.interval && _config.ride) {
  525. data.pause();
  526. data.cycle();
  527. }
  528. }
  529. static jQueryInterface(config) {
  530. return this.each(function () {
  531. Carousel.carouselInterface(this, config);
  532. });
  533. }
  534. static dataApiClickHandler(event) {
  535. const target = getElementFromSelector(this);
  536. if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
  537. return;
  538. }
  539. const config = { ...Manipulator__default['default'].getDataAttributes(target),
  540. ...Manipulator__default['default'].getDataAttributes(this)
  541. };
  542. const slideIndex = this.getAttribute('data-bs-slide-to');
  543. if (slideIndex) {
  544. config.interval = false;
  545. }
  546. Carousel.carouselInterface(target, config);
  547. if (slideIndex) {
  548. Carousel.getInstance(target).to(slideIndex);
  549. }
  550. event.preventDefault();
  551. }
  552. }
  553. /**
  554. * ------------------------------------------------------------------------
  555. * Data Api implementation
  556. * ------------------------------------------------------------------------
  557. */
  558. EventHandler__default['default'].on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler);
  559. EventHandler__default['default'].on(window, EVENT_LOAD_DATA_API, () => {
  560. const carousels = SelectorEngine__default['default'].find(SELECTOR_DATA_RIDE);
  561. for (let i = 0, len = carousels.length; i < len; i++) {
  562. Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i]));
  563. }
  564. });
  565. /**
  566. * ------------------------------------------------------------------------
  567. * jQuery
  568. * ------------------------------------------------------------------------
  569. * add .Carousel to jQuery only if jQuery is present
  570. */
  571. defineJQueryPlugin(Carousel);
  572. return Carousel;
  573. })));
  574. //# sourceMappingURL=carousel.js.map