mirror of
https://github.com/twbs/bootstrap.git
synced 2025-02-21 18:54:30 +01:00
Carousel: move logic of dataApiClickHandler
This commit is contained in:
parent
631cec4f70
commit
13042d25ca
@ -464,38 +464,36 @@ class Carousel extends BaseComponent {
|
|||||||
Carousel.carouselInterface(this, config)
|
Carousel.carouselInterface(this, config)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
static dataApiClickHandler(event) {
|
|
||||||
const target = getElementFromSelector(this)
|
|
||||||
|
|
||||||
if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
event.preventDefault()
|
|
||||||
|
|
||||||
const carousel = Carousel.getOrCreateInstance(target)
|
|
||||||
const slideIndex = this.getAttribute('data-bs-slide-to')
|
|
||||||
|
|
||||||
if (slideIndex) {
|
|
||||||
carousel.to(slideIndex)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Manipulator.getDataAttribute(this, 'slide') === 'next') {
|
|
||||||
carousel.next()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
carousel.prev()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data API implementation
|
* Data API implementation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, Carousel.dataApiClickHandler)
|
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_SLIDE, function (event) {
|
||||||
|
const target = getElementFromSelector(this)
|
||||||
|
|
||||||
|
if (!target || !target.classList.contains(CLASS_NAME_CAROUSEL)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
const carousel = Carousel.getOrCreateInstance(target)
|
||||||
|
const slideIndex = this.getAttribute('data-bs-slide-to')
|
||||||
|
|
||||||
|
if (slideIndex) {
|
||||||
|
carousel.to(slideIndex)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Manipulator.getDataAttribute(this, 'slide') === 'next') {
|
||||||
|
carousel.next()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
carousel.prev()
|
||||||
|
})
|
||||||
|
|
||||||
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
||||||
const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE)
|
const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user