bootstrap/js/src/base-component.js

47 lines
1.0 KiB
JavaScript
Raw Normal View History

2019-09-04 22:58:29 +08:00
/**
* --------------------------------------------------------------------------
* Bootstrap (v5.0.0-beta2): base-component.js
2019-09-04 22:58:29 +08:00
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
import Data from './dom/data'
/**
* ------------------------------------------------------------------------
* Constants
* ------------------------------------------------------------------------
*/
const VERSION = '5.0.0-beta2'
2019-09-04 22:58:29 +08:00
class BaseComponent {
constructor(element) {
element = typeof element === 'string' ? document.querySelector(element) : element
2019-09-04 22:58:29 +08:00
if (!element) {
return
}
this._element = element
Data.set(this._element, this.constructor.DATA_KEY, this)
2019-09-04 22:58:29 +08:00
}
2020-11-20 18:13:11 +08:00
dispose() {
Data.remove(this._element, this.constructor.DATA_KEY)
2020-11-20 18:13:11 +08:00
this._element = null
}
2019-09-04 22:58:29 +08:00
/** Static */
static getInstance(element) {
return Data.get(element, this.DATA_KEY)
2019-09-04 22:58:29 +08:00
}
static get VERSION() {
return VERSION
}
2019-09-04 22:58:29 +08:00
}
export default BaseComponent