Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2022-03-02 02:16:25 +0300
committerXhmikosR <xhmikosr@gmail.com>2022-03-09 18:25:47 +0300
commita8142497c79f33bebd13a8b00d8104b324ce5cf7 (patch)
tree9dac2cb93dd188ca4f12b8d27319d829499bffaa /js/src/carousel.js
parente77ae50311366b07225d15b19e330a3871123437 (diff)
Carousel: reorder variables and refactor method to use it inline
Diffstat (limited to 'js/src/carousel.js')
-rw-r--r--js/src/carousel.js44
1 files changed, 19 insertions, 25 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index afe02f5b7b..bc89a404f0 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -277,17 +277,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
@@ -320,17 +309,12 @@ 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 isCycling = Boolean(this._interval)
-
- 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
@@ -341,7 +325,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
}
@@ -353,6 +347,7 @@ class Carousel extends BaseComponent {
this._isSliding = true
+ const isCycling = Boolean(this._interval)
if (isCycling) {
this.pause()
}
@@ -360,6 +355,10 @@ class Carousel extends BaseComponent {
this._setActiveIndicatorElement(nextElementIndex)
this._activeElement = nextElement
+ 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)
reflow(nextElement)
@@ -375,12 +374,7 @@ class Carousel extends BaseComponent {
this._isSliding = false
- EventHandler.trigger(this._element, EVENT_SLID, {
- relatedTarget: nextElement,
- direction: eventDirectionName,
- from: activeElementIndex,
- to: nextElementIndex
- })
+ triggerEvent(EVENT_SLID)
}
this._queueCallback(completeCallBack, activeElement, this._isAnimated())