aboutsummaryrefslogtreecommitdiff
path: root/js/src/carousel.js
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-09-10 13:24:15 +0300
committerGeoSot <[email protected]>2021-09-10 13:27:26 +0300
commit63b4db14aa82bcf14922cf3d7af5929fccd3ace0 (patch)
tree3abef43a79045bc6a102a1d4d55a90ea63a8e916 /js/src/carousel.js
parenta172f8fc54127d8a9089067744bb5e839ee32d5a (diff)
downloadbootstrap-gs-carousel-cleanup.tar.xz
bootstrap-gs-carousel-cleanup.zip
transfer some code blocks, to where we use themgs-carousel-cleanup
Diffstat (limited to 'js/src/carousel.js')
-rw-r--r--js/src/carousel.js44
1 files changed, 17 insertions, 27 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index 027882db8..fb7f6d615 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -335,17 +335,6 @@ class Carousel extends BaseComponent {
return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap)
}
- _triggerSlideEvent(relatedTarget, fromIndex, eventDirectionName) {
- const targetIndex = this._getItemIndex(relatedTarget)
-
- return EventHandler.trigger(this._element, EVENT_SLIDE, {
- relatedTarget,
- direction: eventDirectionName,
- from: fromIndex,
- to: targetIndex
- })
- }
-
_setActiveIndicatorElement(index) {
if (!this._indicatorsElement) {
return
@@ -378,17 +367,13 @@ class Carousel extends BaseComponent {
_slide(directionOrOrder, element) {
const order = this._directionToOrder(directionOrOrder)
+
const activeElement = this._getActive()
const activeElementIndex = this._getItemIndex(activeElement)
- const nextElement = element || this._getItemByOrder(order, activeElement)
+ const nextElement = element || this._getItemByOrder(order, activeElement)
const nextElementIndex = this._getItemIndex(nextElement)
- const isNext = order === ORDER_NEXT
- const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END
- const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV
- const eventDirectionName = this._orderToDirection(order)
-
if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
this._isSliding = false
return
@@ -398,7 +383,17 @@ class Carousel extends BaseComponent {
return
}
- const slideEvent = this._triggerSlideEvent(nextElement, activeElementIndex, eventDirectionName)
+ const triggerEvent = eventName => {
+ return EventHandler.trigger(this._element, eventName, {
+ relatedTarget: nextElement,
+ direction: this._orderToDirection(order),
+ from: activeElementIndex,
+ to: nextElementIndex
+ })
+ }
+
+ const slideEvent = triggerEvent(EVENT_SLIDE)
+
if (slideEvent.defaultPrevented) {
return
}
@@ -415,14 +410,9 @@ class Carousel extends BaseComponent {
this._setActiveIndicatorElement(nextElementIndex)
this._activeElement = nextElement
- const triggerSlidEvent = () => {
- EventHandler.trigger(this._element, EVENT_SLID, {
- relatedTarget: nextElement,
- direction: eventDirectionName,
- from: activeElementIndex,
- to: nextElementIndex
- })
- }
+ const isNext = order === ORDER_NEXT
+ const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END
+ const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV
nextElement.classList.add(orderClassName)
@@ -439,7 +429,7 @@ class Carousel extends BaseComponent {
this._isSliding = false
- setTimeout(triggerSlidEvent, 0)
+ triggerEvent(EVENT_SLID)
}
this._queueCallback(completeCallBack, activeElement, this._isAnimated())