2019-09-04 14:58:29 +00:00
|
|
|
/**
|
|
|
|
|
* --------------------------------------------------------------------------
|
2022-10-03 07:44:02 +00:00
|
|
|
* Bootstrap (v5.2.2): base-component.js
|
2019-09-04 14:58:29 +00:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import Data from './dom/data'
|
2021-12-10 16:18:18 +00:00
|
|
|
import { executeAfterTransition, getElement } from './util/index'
|
2021-04-11 06:54:48 +00:00
|
|
|
import EventHandler from './dom/event-handler'
|
2021-12-10 16:18:18 +00:00
|
|
|
import Config from './util/config'
|
2019-09-04 14:58:29 +00:00
|
|
|
|
2020-11-25 07:13:33 +00:00
|
|
|
/**
|
|
|
|
|
* Constants
|
|
|
|
|
*/
|
|
|
|
|
|
2022-10-03 07:44:02 +00:00
|
|
|
const VERSION = '5.2.2'
|
2020-11-25 07:13:33 +00:00
|
|
|
|
2021-10-13 12:19:28 +00:00
|
|
|
/**
|
|
|
|
|
* Class definition
|
|
|
|
|
*/
|
|
|
|
|
|
2021-12-10 16:18:18 +00:00
|
|
|
class BaseComponent extends Config {
|
|
|
|
|
constructor(element, config) {
|
|
|
|
|
super()
|
2021-02-22 07:01:04 +00:00
|
|
|
|
2021-12-10 16:18:18 +00:00
|
|
|
element = getElement(element)
|
2019-09-04 14:58:29 +00:00
|
|
|
if (!element) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this._element = element
|
2021-12-10 16:18:18 +00:00
|
|
|
this._config = this._getConfig(config)
|
|
|
|
|
|
2021-03-02 14:55:44 +00:00
|
|
|
Data.set(this._element, this.constructor.DATA_KEY, this)
|
2019-09-04 14:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 12:19:28 +00:00
|
|
|
// Public
|
2020-11-20 10:13:11 +00:00
|
|
|
dispose() {
|
2021-03-02 14:55:44 +00:00
|
|
|
Data.remove(this._element, this.constructor.DATA_KEY)
|
2021-05-11 07:49:30 +00:00
|
|
|
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
2021-05-11 06:04:42 +00:00
|
|
|
|
2021-07-30 06:28:51 +00:00
|
|
|
for (const propertyName of Object.getOwnPropertyNames(this)) {
|
2021-05-11 06:04:42 +00:00
|
|
|
this[propertyName] = null
|
2021-07-30 06:28:51 +00:00
|
|
|
}
|
2020-11-20 10:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-10 23:27:18 +00:00
|
|
|
_queueCallback(callback, element, isAnimated = true) {
|
2021-06-03 11:44:16 +00:00
|
|
|
executeAfterTransition(callback, element, isAnimated)
|
2021-04-10 23:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-10 16:18:18 +00:00
|
|
|
_getConfig(config) {
|
|
|
|
|
config = this._mergeConfigObj(config, this._element)
|
|
|
|
|
config = this._configAfterMerge(config)
|
|
|
|
|
this._typeCheckConfig(config)
|
|
|
|
|
return config
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 12:19:28 +00:00
|
|
|
// Static
|
2019-09-04 14:58:29 +00:00
|
|
|
static getInstance(element) {
|
2021-06-29 14:45:45 +00:00
|
|
|
return Data.get(getElement(element), this.DATA_KEY)
|
2019-09-04 14:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-03 15:53:27 +00:00
|
|
|
static getOrCreateInstance(element, config = {}) {
|
|
|
|
|
return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 07:13:33 +00:00
|
|
|
static get VERSION() {
|
|
|
|
|
return VERSION
|
|
|
|
|
}
|
2021-05-11 07:49:30 +00:00
|
|
|
|
|
|
|
|
static get DATA_KEY() {
|
|
|
|
|
return `bs.${this.NAME}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get EVENT_KEY() {
|
|
|
|
|
return `.${this.DATA_KEY}`
|
|
|
|
|
}
|
2022-02-19 13:10:47 +00:00
|
|
|
|
|
|
|
|
static eventName(name) {
|
|
|
|
|
return `${name}${this.EVENT_KEY}`
|
|
|
|
|
}
|
2019-09-04 14:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BaseComponent
|