0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-20 17:54:23 +01:00

fix(plugins): save instance in constructor

This commit is contained in:
Johann-S 2018-06-24 22:02:03 +02:00 committed by XhmikosR
parent 5dcca44fcf
commit 467dd113c5
8 changed files with 19 additions and 15 deletions

View File

@ -47,6 +47,9 @@ const ClassName = {
class Alert {
constructor(element) {
this._element = element
if (this._element) {
Data.setData(element, DATA_KEY, this)
}
}
// Getters
@ -129,7 +132,6 @@ class Alert {
if (!data) {
data = new Alert(this)
Data.setData(this, DATA_KEY, data)
}
if (config === 'close') {
@ -148,7 +150,8 @@ class Alert {
* Data Api implementation
* ------------------------------------------------------------------------
*/
EventHandler.on(document, Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()))
EventHandler
.on(document, Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()))
/**
* ------------------------------------------------------------------------

View File

@ -52,6 +52,7 @@ const Event = {
class Button {
constructor(element) {
this._element = element
Data.setData(element, DATA_KEY, this)
}
// Getters
@ -112,10 +113,6 @@ class Button {
if (triggerChangeEvent) {
this._element.classList.toggle(ClassName.ACTIVE)
}
static _getInstance(element) {
return Data.getData(element, DATA_KEY)
}
}
dispose() {
@ -131,7 +128,6 @@ class Button {
if (!data) {
data = new Button(this)
Data.setData(this, DATA_KEY, data)
}
if (config === 'toggle') {
@ -139,6 +135,10 @@ class Button {
}
})
}
static _getInstance(element) {
return Data.getData(element, DATA_KEY)
}
}
/**

View File

@ -119,6 +119,7 @@ class Carousel {
this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent)
this._addEventListeners()
Data.setData(element, DATA_KEY, this)
}
// Getters
@ -526,7 +527,6 @@ class Carousel {
if (!data) {
data = new Carousel(element, _config)
Data.setData(element, DATA_KEY, data)
}
if (typeof config === 'number') {

View File

@ -96,6 +96,8 @@ class Collapse {
if (this._config.toggle) {
this.toggle()
}
Data.setData(element, DATA_KEY, this)
}
// Getters
@ -358,7 +360,6 @@ class Collapse {
if (!data) {
data = new Collapse(element, _config)
Data.setData(element, DATA_KEY, data)
}
if (typeof config === 'string') {

View File

@ -103,6 +103,7 @@ class Dropdown {
this._inNavbar = this._detectNavbar()
this._addEventListeners()
Data.setData(element, DATA_KEY, this)
}
// Getters

View File

@ -87,6 +87,7 @@ class Modal {
this._ignoreBackdropClick = false
this._isTransitioning = false
this._scrollbarWidth = 0
Data.setData(element, DATA_KEY, this)
}
// Getters
@ -522,7 +523,6 @@ class Modal {
if (!data) {
data = new Modal(this, _config)
Data.setData(this, DATA_KEY, data)
}
if (typeof config === 'string') {
@ -581,7 +581,6 @@ EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (
let data = Data.getData(target, DATA_KEY)
if (!data) {
data = new Modal(target, config)
Data.setData(target, DATA_KEY, data)
}
data.show(this)

View File

@ -134,10 +134,10 @@ class Popover extends Tooltip {
_cleanTipClass() {
const tip = this.getTipElement()
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
if (tabClass !== null && tabClass.length > 0) {
tabClass.map((token) => token.trim()).forEach((tClass) => {
tip.classList.remove(tClass)
})
tabClass.map((token) => token.trim())
.forEach((tClass) => tip.classList.remove(tClass))
}
}

View File

@ -143,6 +143,7 @@ class Tooltip {
this.tip = null
this._setListeners()
Data.setData(element, this.constructor.DATA_KEY, this)
}
// Getters
@ -779,7 +780,6 @@ class Tooltip {
if (!data) {
data = new Tooltip(this, _config)
Data.setData(this, DATA_KEY, data)
}
if (typeof config === 'string') {