mirror of
https://github.com/twbs/bootstrap.git
synced 2025-01-30 22:52:24 +01:00
Carousel: add a getItems
helper
This commit is contained in:
parent
b7cce49dbc
commit
fcc2c80976
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user