diff options
Diffstat (limited to 'js/src/base-component.js')
| -rw-r--r-- | js/src/base-component.js | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/js/src/base-component.js b/js/src/base-component.js index 3c5eb460a..82bf77030 100644 --- a/js/src/base-component.js +++ b/js/src/base-component.js @@ -1,36 +1,37 @@ /** * -------------------------------------------------------------------------- - * Bootstrap (v5.1.3): base-component.js + * Bootstrap 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' +import Data from './dom/data.js' +import EventHandler from './dom/event-handler.js' +import Config from './util/config.js' +import { executeAfterTransition, getElement } from './util/index.js' /** * Constants */ -const VERSION = '5.1.3' +const VERSION = '5.3.3' /** * Class definition */ -class BaseComponent { - constructor(element) { - element = getElement(element) +class BaseComponent extends Config { + constructor(element, config) { + super() + element = getElement(element) if (!element) { return } this._element = element + this._config = this._getConfig(config) + Data.set(this._element, this.constructor.DATA_KEY, this) } @@ -48,6 +49,13 @@ class BaseComponent { executeAfterTransition(callback, element, isAnimated) } + _getConfig(config) { + config = this._mergeConfigObj(config, this._element) + config = this._configAfterMerge(config) + this._typeCheckConfig(config) + return config + } + // Static static getInstance(element) { return Data.get(getElement(element), this.DATA_KEY) @@ -61,10 +69,6 @@ class BaseComponent { 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}` } @@ -72,6 +76,10 @@ class BaseComponent { static get EVENT_KEY() { return `.${this.DATA_KEY}` } + + static eventName(name) { + return `${name}${this.EVENT_KEY}` + } } export default BaseComponent |
