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/src
diff options
context:
space:
mode:
authorGeoSot <geo.sotis@gmail.com>2022-03-02 03:04:03 +0300
committerXhmikosR <xhmikosr@gmail.com>2022-03-09 18:25:47 +0300
commitfcc2c809767525a32357fc4877a6dbbac6ba1370 (patch)
tree257747401f50339ade2dd3ae7becd8ddc9fdf3a0 /js/src
parentb7cce49dbc7d9dd6be1dd49e6764dd6f23f6d758 (diff)
Carousel: add a `getItems` helper
Diffstat (limited to 'js/src')
-rw-r--r--js/src/carousel.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js
index f8ca1d6389..fdc6736ad9 100644
--- a/js/src/carousel.js
+++ b/js/src/carousel.js
@@ -95,7 +95,6 @@ class Carousel extends BaseComponent {
constructor(element, config) {
super(element, config)
- this._items = null
this._interval = null
this._activeElement = null
this._isPaused = false
@@ -165,10 +164,8 @@ class Carousel extends BaseComponent {
}
to(index) {
- this._activeElement = this._getActive()
- const activeIndex = this._getItemIndex(this._activeElement)
-
- if (index > this._items.length - 1 || index < 0) {
+ const items = this._getItems()
+ if (index > items.length - 1 || index < 0) {
return
}
@@ -177,17 +174,16 @@ class Carousel extends BaseComponent {
return
}
+ const activeIndex = this._getItemIndex(this._getActive())
if (activeIndex === index) {
this.pause()
this.cycle()
return
}
- const order = index > activeIndex ?
- ORDER_NEXT :
- ORDER_PREV
+ const order = index > activeIndex ? ORDER_NEXT : ORDER_PREV
- this._slide(order, this._items[index])
+ this._slide(order, items[index])
}
dispose() {
@@ -267,14 +263,12 @@ class Carousel extends BaseComponent {
}
_getItemIndex(element) {
- this._items = SelectorEngine.find(SELECTOR_ITEM, this._element)
-
- return this._items.indexOf(element)
+ return this._getItems().indexOf(element)
}
_getItemByOrder(order, activeElement) {
const isNext = order === ORDER_NEXT
- return getNextActiveElement(this._items, activeElement, isNext, this._config.wrap)
+ return getNextActiveElement(this._getItems(), activeElement, isNext, this._config.wrap)
}
_setActiveIndicatorElement(index) {
@@ -392,6 +386,10 @@ class Carousel extends BaseComponent {
return SelectorEngine.findOne(SELECTOR_ACTIVE_ITEM, this._element)
}
+ _getItems() {
+ return SelectorEngine.find(SELECTOR_ITEM, this._element)
+ }
+
_clearInterval() {
if (this._interval) {
clearInterval(this._interval)