source: trip-planner-front/node_modules/bootstrap/js/src/base-component.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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