2019-09-04 22:58:29 +08:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2021-02-11 00:14:51 +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'
|
|
|
|
|
2020-11-25 15:13:33 +08:00
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Constants
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2021-02-11 00:14:51 +08:00
|
|
|
const VERSION = '5.0.0-beta2'
|
2020-11-25 15:13:33 +08:00
|
|
|
|
2019-09-04 22:58:29 +08:00
|
|
|
class BaseComponent {
|
|
|
|
constructor(element) {
|
2021-02-22 15:01:04 +08:00
|
|
|
element = typeof element === 'string' ? document.querySelector(element) : element
|
|
|
|
|
2019-09-04 22:58:29 +08:00
|
|
|
if (!element) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this._element = element
|
2021-03-02 22:55:44 +08:00
|
|
|
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() {
|
2021-03-02 22:55:44 +08:00
|
|
|
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) {
|
2021-03-02 22:55:44 +08:00
|
|
|
return Data.get(element, this.DATA_KEY)
|
2019-09-04 22:58:29 +08:00
|
|
|
}
|
|
|
|
|
2020-11-25 15:13:33 +08:00
|
|
|
static get VERSION() {
|
|
|
|
return VERSION
|
|
|
|
}
|
2019-09-04 22:58:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default BaseComponent
|