2019-09-04 17:58:29 +03:00
|
|
|
/**
|
|
|
|
* --------------------------------------------------------------------------
|
2021-05-05 22:32:12 +03:00
|
|
|
* Bootstrap (v5.0.0): base-component.js
|
2019-09-04 17:58:29 +03:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
|
|
* --------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Data from './dom/data'
|
2021-04-11 02:27:18 +03:00
|
|
|
import {
|
|
|
|
emulateTransitionEnd,
|
|
|
|
execute,
|
|
|
|
getTransitionDurationFromElement
|
|
|
|
} from './util/index'
|
2021-04-11 09:54:48 +03:00
|
|
|
import EventHandler from './dom/event-handler'
|
2019-09-04 17:58:29 +03:00
|
|
|
|
2020-11-25 12:43:33 +05:30
|
|
|
/**
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
* Constants
|
|
|
|
* ------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2021-05-05 22:32:12 +03:00
|
|
|
const VERSION = '5.0.0'
|
2020-11-25 12:43:33 +05:30
|
|
|
|
2019-09-04 17:58:29 +03:00
|
|
|
class BaseComponent {
|
|
|
|
constructor(element) {
|
2021-02-22 12:31:04 +05:30
|
|
|
element = typeof element === 'string' ? document.querySelector(element) : element
|
|
|
|
|
2019-09-04 17:58:29 +03:00
|
|
|
if (!element) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this._element = element
|
2021-03-02 15:55:44 +01:00
|
|
|
Data.set(this._element, this.constructor.DATA_KEY, this)
|
2019-09-04 17:58:29 +03:00
|
|
|
}
|
|
|
|
|
2020-11-20 11:13:11 +01:00
|
|
|
dispose() {
|
2021-03-02 15:55:44 +01:00
|
|
|
Data.remove(this._element, this.constructor.DATA_KEY)
|
2021-05-11 10:49:30 +03:00
|
|
|
EventHandler.off(this._element, this.constructor.EVENT_KEY)
|
2021-05-11 09:04:42 +03:00
|
|
|
|
|
|
|
Object.getOwnPropertyNames(this).forEach(propertyName => {
|
|
|
|
this[propertyName] = null
|
|
|
|
})
|
2020-11-20 11:13:11 +01:00
|
|
|
}
|
|
|
|
|
2021-04-11 02:27:18 +03:00
|
|
|
_queueCallback(callback, element, isAnimated = true) {
|
|
|
|
if (!isAnimated) {
|
|
|
|
execute(callback)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const transitionDuration = getTransitionDurationFromElement(element)
|
|
|
|
EventHandler.one(element, 'transitionend', () => execute(callback))
|
|
|
|
|
|
|
|
emulateTransitionEnd(element, transitionDuration)
|
|
|
|
}
|
|
|
|
|
2019-09-04 17:58:29 +03:00
|
|
|
/** Static */
|
|
|
|
|
|
|
|
static getInstance(element) {
|
2021-03-02 15:55:44 +01:00
|
|
|
return Data.get(element, this.DATA_KEY)
|
2019-09-04 17:58:29 +03:00
|
|
|
}
|
|
|
|
|
2020-11-25 12:43:33 +05:30
|
|
|
static get VERSION() {
|
|
|
|
return VERSION
|
|
|
|
}
|
2021-05-11 10:49:30 +03:00
|
|
|
|
|
|
|
static get NAME() {
|
|
|
|
throw new Error('You have to implement the static method "NAME", for each component!')
|
|
|
|
}
|
|
|
|
|
|
|
|
static get DATA_KEY() {
|
|
|
|
return `bs.${this.NAME}`
|
|
|
|
}
|
|
|
|
|
|
|
|
static get EVENT_KEY() {
|
|
|
|
return `.${this.DATA_KEY}`
|
|
|
|
}
|
2019-09-04 17:58:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default BaseComponent
|