mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-26 13:29:06 +02:00
Add getOrCreateInstance
method in base-component (#33276)
Co-authored-by: Rohit Sharma <rohit2sharma95@gmail.com> Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
@@ -15,7 +15,6 @@ import {
|
||||
triggerTransitionEnd,
|
||||
typeCheckConfig
|
||||
} from './util/index'
|
||||
import Data from './dom/data'
|
||||
import EventHandler from './dom/event-handler'
|
||||
import Manipulator from './dom/manipulator'
|
||||
import SelectorEngine from './dom/selector-engine'
|
||||
@@ -219,7 +218,8 @@ class Carousel extends BaseComponent {
|
||||
_getConfig(config) {
|
||||
config = {
|
||||
...Default,
|
||||
...config
|
||||
...Manipulator.getDataAttributes(this._element),
|
||||
...(typeof config === 'object' ? config : {})
|
||||
}
|
||||
typeCheckConfig(NAME, config, DefaultType)
|
||||
return config
|
||||
@@ -496,25 +496,11 @@ class Carousel extends BaseComponent {
|
||||
// Static
|
||||
|
||||
static carouselInterface(element, config) {
|
||||
let data = Data.get(element, DATA_KEY)
|
||||
let _config = {
|
||||
...Default,
|
||||
...Manipulator.getDataAttributes(element)
|
||||
}
|
||||
|
||||
if (typeof config === 'object') {
|
||||
_config = {
|
||||
..._config,
|
||||
...config
|
||||
}
|
||||
}
|
||||
const data = Carousel.getOrCreateInstance(element, config)
|
||||
|
||||
const { _config } = data
|
||||
const action = typeof config === 'string' ? config : _config.slide
|
||||
|
||||
if (!data) {
|
||||
data = new Carousel(element, _config)
|
||||
}
|
||||
|
||||
if (typeof config === 'number') {
|
||||
data.to(config)
|
||||
} else if (typeof action === 'string') {
|
||||
@@ -555,7 +541,7 @@ class Carousel extends BaseComponent {
|
||||
Carousel.carouselInterface(target, config)
|
||||
|
||||
if (slideIndex) {
|
||||
Data.get(target, DATA_KEY).to(slideIndex)
|
||||
Carousel.getInstance(target).to(slideIndex)
|
||||
}
|
||||
|
||||
event.preventDefault()
|
||||
@@ -574,7 +560,7 @@ EventHandler.on(window, EVENT_LOAD_DATA_API, () => {
|
||||
const carousels = SelectorEngine.find(SELECTOR_DATA_RIDE)
|
||||
|
||||
for (let i = 0, len = carousels.length; i < len; i++) {
|
||||
Carousel.carouselInterface(carousels[i], Data.get(carousels[i], DATA_KEY))
|
||||
Carousel.carouselInterface(carousels[i], Carousel.getInstance(carousels[i]))
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user