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 03:11:14 +0300
committerXhmikosR <xhmikosr@gmail.com>2022-03-09 18:25:47 +0300
commitdd93551914424e577176a6377e1614742aa1018c (patch)
tree7bfc603f0bbbcaff77c70ffe6ea743fcb0853984
parent699402bee5d02659acaab69208549f26f9b3313d (diff)
Carousel: refactor using inline function and move variables to the proper place
-rw-r--r--js/src/carousel.js16
1 files changed, 5 insertions, 11 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index 3a692657ab..0860622514 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -266,11 +266,6 @@ class Carousel extends BaseComponent {
return this._getItems().indexOf(element)
}
- _getItemByOrder(order, activeElement) {
- const isNext = order === ORDER_NEXT
- return getNextActiveElement(this._getItems(), activeElement, isNext, this._config.wrap)
- }
-
_setActiveIndicatorElement(index) {
if (!this._indicatorsElement) {
return
@@ -303,10 +298,8 @@ class Carousel extends BaseComponent {
_slide(order, element = null) {
const activeElement = this._getActive()
- const activeElementIndex = this._getItemIndex(activeElement)
-
- const nextElement = element || this._getItemByOrder(order, activeElement)
- const nextElementIndex = this._getItemIndex(nextElement)
+ const isNext = order === ORDER_NEXT
+ const nextElement = element || getNextActiveElement(this._getItems(), activeElement, isNext, this._config.wrap)
if (nextElement && nextElement.classList.contains(CLASS_NAME_ACTIVE)) {
this._isSliding = false
@@ -317,11 +310,13 @@ class Carousel extends BaseComponent {
return
}
+ const nextElementIndex = this._getItemIndex(nextElement)
+
const triggerEvent = eventName => {
return EventHandler.trigger(this._element, eventName, {
relatedTarget: nextElement,
direction: this._orderToDirection(order),
- from: activeElementIndex,
+ from: this._getItemIndex(activeElement),
to: nextElementIndex
})
}
@@ -347,7 +342,6 @@ 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