diff options
| author | GeoSot <[email protected]> | 2021-09-10 03:33:14 +0300 |
|---|---|---|
| committer | GeoSot <[email protected]> | 2021-09-10 13:27:26 +0300 |
| commit | 83d206cc131bcfcf27ded2bac17d9c3cb0e95705 (patch) | |
| tree | 1f832f52133ad6fd66ac163ed6df3a1c218781e2 | |
| parent | e35d408583d22be69e5fd5e7738829fd93fc5928 (diff) | |
| download | bootstrap-83d206cc131bcfcf27ded2bac17d9c3cb0e95705.tar.xz bootstrap-83d206cc131bcfcf27ded2bac17d9c3cb0e95705.zip | |
transfer logic of `dataApiClickHandler`
| -rw-r--r-- | js/src/carousel.js | 50 |
1 files changed, 23 insertions, 27 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js index 382ef4c5e..f34af9aa7 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -508,8 +508,6 @@ class Carousel extends BaseComponent { } } - const action = typeof config === 'string' ? config : _config.slide - if (typeof config === 'number') { data.to(config) return @@ -535,40 +533,38 @@ class Carousel extends BaseComponent { Carousel.carouselInterface(this, config) }) } +} - static dataApiClickHandler(event) { - const target = getElementFromSelector(this) - - if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) { - return - } +/** + * ------------------------------------------------------------------------ + * Data Api implementation + * ------------------------------------------------------------------------ + */ - const config = { - ...Manipulator.getDataAttributes(this) - } - const slideIndex = Manipulator.getDataAttribute(this, 'slide-to') +EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, function (event) { + const target = getElementFromSelector(this) - if (slideIndex) { - config.interval = 0 - } + if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) { + return + } - Carousel.carouselInterface(target, config) + event.preventDefault() - if (slideIndex) { - Carousel.getInstance(target).to(slideIndex) - } + const carousel = Carousel.getOrCreateInstance(target) - event.preventDefault() + const slideIndex = Manipulator.getDataAttribute(this, 'slide-to') + if (slideIndex) { + carousel.to(slideIndex) + return } -} -/** - * ------------------------------------------------------------------------ - * Data Api implementation - * ------------------------------------------------------------------------ - */ + if (Manipulator.getDataAttribute(this, 'slide') === 'next') { + carousel.next() + return + } -EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler) + carousel.prev() +}) EventHandler.on(window, EVENT_LOAD_DATA_API, () => { const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE) |
