From 83d206cc131bcfcf27ded2bac17d9c3cb0e95705 Mon Sep 17 00:00:00 2001 From: GeoSot Date: Fri, 10 Sep 2021 03:33:14 +0300 Subject: transfer logic of `dataApiClickHandler` --- js/src/carousel.js | 50 +++++++++++++++++++++++--------------------------- 1 file 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) -- cgit v1.2.3