diff options
| author | GeoSot <[email protected]> | 2021-06-03 18:53:27 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-06-03 18:53:27 +0300 |
| commit | c98657b8303150bfda3bdea750055b83a29b27a3 (patch) | |
| tree | 6f7b347461e3fdd380f0d4e990440e6fc427af61 /js/src/carousel.js | |
| parent | 4a5029ea29ac75243dfec68153051292fc70f5cf (diff) | |
| download | bootstrap-c98657b8303150bfda3bdea750055b83a29b27a3.tar.xz bootstrap-c98657b8303150bfda3bdea750055b83a29b27a3.zip | |
Add `getOrCreateInstance` method in base-component (#33276)
Co-authored-by: Rohit Sharma <[email protected]>
Co-authored-by: XhmikosR <[email protected]>
Diffstat (limited to 'js/src/carousel.js')
| -rw-r--r-- | js/src/carousel.js | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/js/src/carousel.js b/js/src/carousel.js index 7d197ab1e..a956ebc8b 100644 --- a/js/src/carousel.js +++ b/js/src/carousel.js @@ -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])) } }) |
