source: imaps-frontend/node_modules/bootstrap/js/src/base-component.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * --------------------------------------------------------------------------
3 * Bootstrap base-component.js
4 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5 * --------------------------------------------------------------------------
6 */
7
8import Data from './dom/data.js'
9import EventHandler from './dom/event-handler.js'
10import Config from './util/config.js'
11import { executeAfterTransition, getElement } from './util/index.js'
12
13/**
14 * Constants
15 */
16
17const VERSION = '5.3.3'
18
19/**
20 * Class definition
21 */
22
23class BaseComponent extends Config {
24 constructor(element, config) {
25 super()
26
27 element = getElement(element)
28 if (!element) {
29 return
30 }
31
32 this._element = element
33 this._config = this._getConfig(config)
34
35 Data.set(this._element, this.constructor.DATA_KEY, this)
36 }
37
38 // Public
39 dispose() {
40 Data.remove(this._element, this.constructor.DATA_KEY)
41 EventHandler.off(this._element, this.constructor.EVENT_KEY)
42
43 for (const propertyName of Object.getOwnPropertyNames(this)) {
44 this[propertyName] = null
45 }
46 }
47
48 _queueCallback(callback, element, isAnimated = true) {
49 executeAfterTransition(callback, element, isAnimated)
50 }
51
52 _getConfig(config) {
53 config = this._mergeConfigObj(config, this._element)
54 config = this._configAfterMerge(config)
55 this._typeCheckConfig(config)
56 return config
57 }
58
59 // Static
60 static getInstance(element) {
61 return Data.get(getElement(element), this.DATA_KEY)
62 }
63
64 static getOrCreateInstance(element, config = {}) {
65 return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null)
66 }
67
68 static get VERSION() {
69 return VERSION
70 }
71
72 static get DATA_KEY() {
73 return `bs.${this.NAME}`
74 }
75
76 static get EVENT_KEY() {
77 return `.${this.DATA_KEY}`
78 }
79
80 static eventName(name) {
81 return `${name}${this.EVENT_KEY}`
82 }
83}
84
85export default BaseComponent
Note: See TracBrowser for help on using the repository browser.