mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-13 09:04:14 +02:00
fix(plugins): save instance in constructor
This commit is contained in:
@@ -47,6 +47,9 @@ const ClassName = {
|
|||||||
class Alert {
|
class Alert {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this._element = element
|
this._element = element
|
||||||
|
if (this._element) {
|
||||||
|
Data.setData(element, DATA_KEY, this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -129,7 +132,6 @@ class Alert {
|
|||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Alert(this)
|
data = new Alert(this)
|
||||||
Data.setData(this, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config === 'close') {
|
if (config === 'close') {
|
||||||
@@ -148,7 +150,8 @@ class Alert {
|
|||||||
* Data Api implementation
|
* 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()))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ------------------------------------------------------------------------
|
* ------------------------------------------------------------------------
|
||||||
|
@@ -52,6 +52,7 @@ const Event = {
|
|||||||
class Button {
|
class Button {
|
||||||
constructor(element) {
|
constructor(element) {
|
||||||
this._element = element
|
this._element = element
|
||||||
|
Data.setData(element, DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -112,10 +113,6 @@ class Button {
|
|||||||
if (triggerChangeEvent) {
|
if (triggerChangeEvent) {
|
||||||
this._element.classList.toggle(ClassName.ACTIVE)
|
this._element.classList.toggle(ClassName.ACTIVE)
|
||||||
}
|
}
|
||||||
|
|
||||||
static _getInstance(element) {
|
|
||||||
return Data.getData(element, DATA_KEY)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
@@ -131,7 +128,6 @@ class Button {
|
|||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Button(this)
|
data = new Button(this)
|
||||||
Data.setData(this, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config === 'toggle') {
|
if (config === 'toggle') {
|
||||||
@@ -139,6 +135,10 @@ class Button {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static _getInstance(element) {
|
||||||
|
return Data.getData(element, DATA_KEY)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -119,6 +119,7 @@ class Carousel {
|
|||||||
this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent)
|
this._pointerEvent = Boolean(window.PointerEvent || window.MSPointerEvent)
|
||||||
|
|
||||||
this._addEventListeners()
|
this._addEventListeners()
|
||||||
|
Data.setData(element, DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -526,7 +527,6 @@ class Carousel {
|
|||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Carousel(element, _config)
|
data = new Carousel(element, _config)
|
||||||
Data.setData(element, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config === 'number') {
|
if (typeof config === 'number') {
|
||||||
|
@@ -96,6 +96,8 @@ class Collapse {
|
|||||||
if (this._config.toggle) {
|
if (this._config.toggle) {
|
||||||
this.toggle()
|
this.toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Data.setData(element, DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -358,7 +360,6 @@ class Collapse {
|
|||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Collapse(element, _config)
|
data = new Collapse(element, _config)
|
||||||
Data.setData(element, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
|
@@ -103,6 +103,7 @@ class Dropdown {
|
|||||||
this._inNavbar = this._detectNavbar()
|
this._inNavbar = this._detectNavbar()
|
||||||
|
|
||||||
this._addEventListeners()
|
this._addEventListeners()
|
||||||
|
Data.setData(element, DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
|
@@ -87,6 +87,7 @@ class Modal {
|
|||||||
this._ignoreBackdropClick = false
|
this._ignoreBackdropClick = false
|
||||||
this._isTransitioning = false
|
this._isTransitioning = false
|
||||||
this._scrollbarWidth = 0
|
this._scrollbarWidth = 0
|
||||||
|
Data.setData(element, DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -522,7 +523,6 @@ class Modal {
|
|||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Modal(this, _config)
|
data = new Modal(this, _config)
|
||||||
Data.setData(this, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config === 'string') {
|
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)
|
let data = Data.getData(target, DATA_KEY)
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Modal(target, config)
|
data = new Modal(target, config)
|
||||||
Data.setData(target, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.show(this)
|
data.show(this)
|
||||||
|
@@ -134,10 +134,10 @@ class Popover extends Tooltip {
|
|||||||
_cleanTipClass() {
|
_cleanTipClass() {
|
||||||
const tip = this.getTipElement()
|
const tip = this.getTipElement()
|
||||||
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
|
const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
|
||||||
|
|
||||||
if (tabClass !== null && tabClass.length > 0) {
|
if (tabClass !== null && tabClass.length > 0) {
|
||||||
tabClass.map((token) => token.trim()).forEach((tClass) => {
|
tabClass.map((token) => token.trim())
|
||||||
tip.classList.remove(tClass)
|
.forEach((tClass) => tip.classList.remove(tClass))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,6 +143,7 @@ class Tooltip {
|
|||||||
this.tip = null
|
this.tip = null
|
||||||
|
|
||||||
this._setListeners()
|
this._setListeners()
|
||||||
|
Data.setData(element, this.constructor.DATA_KEY, this)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@@ -779,7 +780,6 @@ class Tooltip {
|
|||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
data = new Tooltip(this, _config)
|
data = new Tooltip(this, _config)
|
||||||
Data.setData(this, DATA_KEY, data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof config === 'string') {
|
if (typeof config === 'string') {
|
||||||
|
Reference in New Issue
Block a user