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
path: root/js
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2021-07-08 01:29:25 +0300
committerXhmikosR <xhmikosr@gmail.com>2021-12-21 18:37:24 +0300
commitd60f146507c94bd889f7049d77a4b3725a6fa0a9 (patch)
tree759ba6fd3d655f5ed76cb891a9162f902224dea1 /js
parent65cf77ae3ef676a5d9e2ea640393ec8055e8b953 (diff)
Carousel: add a helper to get the active element
Diffstat (limited to 'js')
-rw-r--r--js/src/carousel.js12
1 files changed, 8 insertions, 4 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index e50894aa81..14a0bd40b2 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -173,7 +173,7 @@ class Carousel extends BaseComponent {
}
to(index) {
- this._activeElement = SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
+ this._activeElement = this._getActive()
const activeIndex = this._getItemIndex(this._activeElement)
if (index > this._items.length - 1 || index < 0) {
@@ -282,7 +282,7 @@ class Carousel extends BaseComponent {
_triggerSlideEvent(relatedTarget, eventDirectionName) {
const targetIndex = this._getItemIndex(relatedTarget)
- const fromIndex = this._getItemIndex(SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element))
+ const fromIndex = this._getItemIndex(this._getActive())
return EventHandler.trigger(this._element, EVENT_SLIDE, {
relatedTarget,
@@ -312,7 +312,7 @@ class Carousel extends BaseComponent {
}
_updateInterval() {
- const element = this._activeElement || SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
+ const element = this._activeElement || this._getActive()
if (!element) {
return
@@ -330,7 +330,7 @@ class Carousel extends BaseComponent {
_slide(directionOrOrder, element) {
const order = this._directionToOrder(directionOrOrder)
- const activeElement = SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
+ const activeElement = this._getActive()
const activeElementIndex = this._getItemIndex(activeElement)
const nextElement = element || this._getItemByOrder(order, activeElement)
@@ -412,6 +412,10 @@ class Carousel extends BaseComponent {
}
}
+ _getActive() {
+ return SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
+ }
+
_directionToOrder(direction) {
if (![DIRECTION_RIGHT, DIRECTION_LEFT].includes(direction)) {
return direction