2019-09-04 22:58:29 +08:00
|
|
|
/**
|
|
|
|
|
* --------------------------------------------------------------------------
|
2021-10-09 14:33:12 +08:00
|
|
|
* Bootstrap (v5.1.3): 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'
|
2021-04-11 07:27:18 +08:00
|
|
|
import {
|
2021-06-03 19:44:16 +08:00
|
|
|
executeAfterTransition,
|
|
|
|
|
getElement
|
2021-04-11 07:27:18 +08:00
|
|
|
} from './util/index'
|
2021-04-11 14:54:48 +08:00
|
|
|
import EventHandler from './dom/event-handler'
|
2019-09-04 22:58:29 +08:00
|
|
|
|
2020-11-25 15:13:33 +08:00
|
|
|
/**
|
|
|
|
|
* Constants
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-09 14:33:12 +08:00
|
|
|
const VERSION = '5.1.3'
|
2020-11-25 15:13:33 +08:00
|
|
|
|
2021-10-13 20:19:28 +08:00
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
|
2019-09-04 22:58:29 +08:00
|
|
|
class BaseComponent {
|
|
|
|
|
constructor(element) {
|
2021-05-13 23:17:20 +08:00
|
|
|
element = getElement(element)
|
2021-02-22 15:01:04 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-10-13 20:19:28 +08:00
|
|
|
// Public
|
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)
|
2021-05-11 15:49:30 +08:00
|
|
|
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
2021-05-11 14:04:42 +08:00
|
|
|
|
2021-07-30 14:28:51 +08:00
|
|
|
for (const propertyName of Object.getOwnPropertyNames(this)) {
|
2021-05-11 14:04:42 +08:00
|
|
|
this[propertyName] = null
|
2021-07-30 14:28:51 +08:00
|
|
|
}
|
2020-11-20 18:13:11 +08:00
|
|
|
}
|
|
|
|
|
|
2021-04-11 07:27:18 +08:00
|
|
|
_queueCallback(callback, element, isAnimated = true) {
|
2021-06-03 19:44:16 +08:00
|
|
|
executeAfterTransition(callback, element, isAnimated)
|
2021-04-11 07:27:18 +08:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 20:19:28 +08:00
|
|
|
// Static
|
2019-09-04 22:58:29 +08:00
|
|
|
static getInstance(element) {
|
2021-06-29 22:45:45 +08:00
|
|
|
return Data.get(getElement(element), this.DATA_KEY)
|
2019-09-04 22:58:29 +08:00
|
|
|
}
|
|
|
|
|
|
2021-06-03 23:53:27 +08:00
|
|
|
static getOrCreateInstance(element, config = {}) {
|
|
|
|
|
return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 15:13:33 +08:00
|
|
|
static get VERSION() {
|
|
|
|
|
return VERSION
|
|
|
|
|
}
|
2021-05-11 15:49:30 +08:00
|
|
|
|
|
|
|
|
static get NAME() {
|
2021-10-13 20:19:28 +08:00
|
|
|
throw new Error('You have to implement the static method "NAME" for each component!')
|
2021-05-11 15:49:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get DATA_KEY() {
|
|
|
|
|
return `bs.${this.NAME}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get EVENT_KEY() {
|
|
|
|
|
return `.${this.DATA_KEY}`
|
|
|
|
|
}
|
2019-09-04 22:58:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BaseComponent
|