diff options
| author | XhmikosR <[email protected]> | 2021-08-18 07:29:56 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-18 07:29:56 +0300 |
| commit | 433a148c9e61aa942801fd8101dfa5c4045fdaed (patch) | |
| tree | f41db59fd06019169df5ea0338213ec0e298f226 /js/src/base-component.js | |
| parent | b97cfa163b5098db70e03b27c91fca5dde9c267e (diff) | |
| parent | 18b3e1ac71f73d006756684a285c5a818e2d1454 (diff) | |
| download | bootstrap-global-focus-vars.tar.xz bootstrap-global-focus-vars.zip | |
Merge branch 'main' into global-focus-varsglobal-focus-vars
Diffstat (limited to 'js/src/base-component.js')
| -rw-r--r-- | js/src/base-component.js | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/js/src/base-component.js b/js/src/base-component.js index 9de274bd0..e7b4112a9 100644 --- a/js/src/base-component.js +++ b/js/src/base-component.js @@ -1,11 +1,16 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.0.0-beta2): base-component.js + * Bootstrap (v5.1.0): base-component.js * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * -------------------------------------------------------------------------- */ import Data from './dom/data' +import { + executeAfterTransition, + getElement +} from './util/index' +import EventHandler from './dom/event-handler' /** * ------------------------------------------------------------------------ @@ -13,32 +18,58 @@ import Data from './dom/data' * ------------------------------------------------------------------------ */ -const VERSION = '5.0.0-beta2' +const VERSION = '5.1.0' class BaseComponent { constructor(element) { + element = getElement(element) + if (!element) { return } this._element = element - Data.setData(element, this.constructor.DATA_KEY, this) + Data.set(this._element, this.constructor.DATA_KEY, this) } dispose() { - Data.removeData(this._element, this.constructor.DATA_KEY) - this._element = null + Data.remove(this._element, this.constructor.DATA_KEY) + EventHandler.off(this._element, this.constructor.EVENT_KEY) + + Object.getOwnPropertyNames(this).forEach(propertyName => { + this[propertyName] = null + }) + } + + _queueCallback(callback, element, isAnimated = true) { + executeAfterTransition(callback, element, isAnimated) } /** Static */ static getInstance(element) { - return Data.getData(element, this.DATA_KEY) + return Data.get(getElement(element), this.DATA_KEY) + } + + static getOrCreateInstance(element, config = {}) { + return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null) } static get VERSION() { return VERSION } + + 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}` + } } export default BaseComponent |
