0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-03-15 15:29:22 +01:00

Carousel: refactor using inline function and move variables to the proper place

This commit is contained in:
GeoSot 2022-03-02 02:11:14 +02:00 committed by XhmikosR
parent 699402bee5
commit dd93551914

View File

@ -266,11 +266,6 @@ class Carousel extends BaseComponent {
return this._getItems().indexOf(element) return this._getItems().indexOf(element)
} }
_getItemByOrder(order, activeElement) {
const isNext = order === ORDER_NEXT
return getNextActiveElement(this._getItems(), activeElement, isNext, this._config.wrap)
}
_setActiveIndicatorElement(index) { _setActiveIndicatorElement(index) {
if (!this._indicatorsElement) { if (!this._indicatorsElement) {
return return
@ -303,10 +298,8 @@ class Carousel extends BaseComponent {
_slide(order, element = null) { _slide(order, element = null) {
const activeElement = this._getActive() const activeElement = this._getActive()
const activeElementIndex = this._getItemIndex(activeElement) const isNext = order === ORDER_NEXT
const nextElement = element || getNextActiveElement(this._getItems(), activeElement, isNext, this._config.wrap)
const nextElement = element || this._getItemByOrder(order, activeElement)
const nextElementIndex = this._getItemIndex(nextElement)
if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) { if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
this._isSliding = false this._isSliding = false
@ -317,11 +310,13 @@ class Carousel extends BaseComponent {
return return
} }
const nextElementIndex = this._getItemIndex(nextElement)
const triggerEvent = eventName => { const triggerEvent = eventName => {
return EventHandler.trigger(this._element, eventName, { return EventHandler.trigger(this._element, eventName, {
relatedTarget: nextElement, relatedTarget: nextElement,
direction: this._orderToDirection(order), direction: this._orderToDirection(order),
from: activeElementIndex, from: this._getItemIndex(activeElement),
to: nextElementIndex to: nextElementIndex
}) })
} }
@ -347,7 +342,6 @@ class Carousel extends BaseComponent {
this._setActiveIndicatorElement(nextElementIndex) this._setActiveIndicatorElement(nextElementIndex)
this._activeElement = nextElement this._activeElement = nextElement
const isNext = order === ORDER_NEXT
const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END const directionalClassName = isNext ? CLASS_NAME_START : CLASS_NAME_END
const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV const orderClassName = isNext ? CLASS_NAME_NEXT : CLASS_NAME_PREV