1 | /*!
|
---|
2 | * Bootstrap base-component.js v5.1.3 (https://getbootstrap.com/)
|
---|
3 | * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
|
---|
4 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
5 | */
|
---|
6 | (function (global, factory) {
|
---|
7 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('./dom/data.js'), require('./dom/event-handler.js')) :
|
---|
8 | typeof define === 'function' && define.amd ? define(['./dom/data', './dom/event-handler'], factory) :
|
---|
9 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Base = factory(global.Data, global.EventHandler));
|
---|
10 | })(this, (function (Data, EventHandler) { 'use strict';
|
---|
11 |
|
---|
12 | const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default: e };
|
---|
13 |
|
---|
14 | const Data__default = /*#__PURE__*/_interopDefaultLegacy(Data);
|
---|
15 | const EventHandler__default = /*#__PURE__*/_interopDefaultLegacy(EventHandler);
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * --------------------------------------------------------------------------
|
---|
19 | * Bootstrap (v5.1.3): util/index.js
|
---|
20 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
21 | * --------------------------------------------------------------------------
|
---|
22 | */
|
---|
23 | const MILLISECONDS_MULTIPLIER = 1000;
|
---|
24 | const TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
---|
25 |
|
---|
26 | const getTransitionDurationFromElement = element => {
|
---|
27 | if (!element) {
|
---|
28 | return 0;
|
---|
29 | } // Get transition-duration of the element
|
---|
30 |
|
---|
31 |
|
---|
32 | let {
|
---|
33 | transitionDuration,
|
---|
34 | transitionDelay
|
---|
35 | } = window.getComputedStyle(element);
|
---|
36 | const floatTransitionDuration = Number.parseFloat(transitionDuration);
|
---|
37 | const floatTransitionDelay = Number.parseFloat(transitionDelay); // Return 0 if element or transition duration is not found
|
---|
38 |
|
---|
39 | if (!floatTransitionDuration && !floatTransitionDelay) {
|
---|
40 | return 0;
|
---|
41 | } // If multiple durations are defined, take the first
|
---|
42 |
|
---|
43 |
|
---|
44 | transitionDuration = transitionDuration.split(',')[0];
|
---|
45 | transitionDelay = transitionDelay.split(',')[0];
|
---|
46 | return (Number.parseFloat(transitionDuration) + Number.parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
|
---|
47 | };
|
---|
48 |
|
---|
49 | const triggerTransitionEnd = element => {
|
---|
50 | element.dispatchEvent(new Event(TRANSITION_END));
|
---|
51 | };
|
---|
52 |
|
---|
53 | const isElement = obj => {
|
---|
54 | if (!obj || typeof obj !== 'object') {
|
---|
55 | return false;
|
---|
56 | }
|
---|
57 |
|
---|
58 | if (typeof obj.jquery !== 'undefined') {
|
---|
59 | obj = obj[0];
|
---|
60 | }
|
---|
61 |
|
---|
62 | return typeof obj.nodeType !== 'undefined';
|
---|
63 | };
|
---|
64 |
|
---|
65 | const getElement = obj => {
|
---|
66 | if (isElement(obj)) {
|
---|
67 | // it's a jQuery object or a node element
|
---|
68 | return obj.jquery ? obj[0] : obj;
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (typeof obj === 'string' && obj.length > 0) {
|
---|
72 | return document.querySelector(obj);
|
---|
73 | }
|
---|
74 |
|
---|
75 | return null;
|
---|
76 | };
|
---|
77 |
|
---|
78 | const execute = callback => {
|
---|
79 | if (typeof callback === 'function') {
|
---|
80 | callback();
|
---|
81 | }
|
---|
82 | };
|
---|
83 |
|
---|
84 | const executeAfterTransition = (callback, transitionElement, waitForTransition = true) => {
|
---|
85 | if (!waitForTransition) {
|
---|
86 | execute(callback);
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 | const durationPadding = 5;
|
---|
91 | const emulatedDuration = getTransitionDurationFromElement(transitionElement) + durationPadding;
|
---|
92 | let called = false;
|
---|
93 |
|
---|
94 | const handler = ({
|
---|
95 | target
|
---|
96 | }) => {
|
---|
97 | if (target !== transitionElement) {
|
---|
98 | return;
|
---|
99 | }
|
---|
100 |
|
---|
101 | called = true;
|
---|
102 | transitionElement.removeEventListener(TRANSITION_END, handler);
|
---|
103 | execute(callback);
|
---|
104 | };
|
---|
105 |
|
---|
106 | transitionElement.addEventListener(TRANSITION_END, handler);
|
---|
107 | setTimeout(() => {
|
---|
108 | if (!called) {
|
---|
109 | triggerTransitionEnd(transitionElement);
|
---|
110 | }
|
---|
111 | }, emulatedDuration);
|
---|
112 | };
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * --------------------------------------------------------------------------
|
---|
116 | * Bootstrap (v5.1.3): base-component.js
|
---|
117 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
---|
118 | * --------------------------------------------------------------------------
|
---|
119 | */
|
---|
120 | /**
|
---|
121 | * ------------------------------------------------------------------------
|
---|
122 | * Constants
|
---|
123 | * ------------------------------------------------------------------------
|
---|
124 | */
|
---|
125 |
|
---|
126 | const VERSION = '5.1.3';
|
---|
127 |
|
---|
128 | class BaseComponent {
|
---|
129 | constructor(element) {
|
---|
130 | element = getElement(element);
|
---|
131 |
|
---|
132 | if (!element) {
|
---|
133 | return;
|
---|
134 | }
|
---|
135 |
|
---|
136 | this._element = element;
|
---|
137 | Data__default.default.set(this._element, this.constructor.DATA_KEY, this);
|
---|
138 | }
|
---|
139 |
|
---|
140 | dispose() {
|
---|
141 | Data__default.default.remove(this._element, this.constructor.DATA_KEY);
|
---|
142 | EventHandler__default.default.off(this._element, this.constructor.EVENT_KEY);
|
---|
143 | Object.getOwnPropertyNames(this).forEach(propertyName => {
|
---|
144 | this[propertyName] = null;
|
---|
145 | });
|
---|
146 | }
|
---|
147 |
|
---|
148 | _queueCallback(callback, element, isAnimated = true) {
|
---|
149 | executeAfterTransition(callback, element, isAnimated);
|
---|
150 | }
|
---|
151 | /** Static */
|
---|
152 |
|
---|
153 |
|
---|
154 | static getInstance(element) {
|
---|
155 | return Data__default.default.get(getElement(element), this.DATA_KEY);
|
---|
156 | }
|
---|
157 |
|
---|
158 | static getOrCreateInstance(element, config = {}) {
|
---|
159 | return this.getInstance(element) || new this(element, typeof config === 'object' ? config : null);
|
---|
160 | }
|
---|
161 |
|
---|
162 | static get VERSION() {
|
---|
163 | return VERSION;
|
---|
164 | }
|
---|
165 |
|
---|
166 | static get NAME() {
|
---|
167 | throw new Error('You have to implement the static method "NAME", for each component!');
|
---|
168 | }
|
---|
169 |
|
---|
170 | static get DATA_KEY() {
|
---|
171 | return `bs.${this.NAME}`;
|
---|
172 | }
|
---|
173 |
|
---|
174 | static get EVENT_KEY() {
|
---|
175 | return `.${this.DATA_KEY}`;
|
---|
176 | }
|
---|
177 |
|
---|
178 | }
|
---|
179 |
|
---|
180 | return BaseComponent;
|
---|
181 |
|
---|
182 | }));
|
---|
183 | //# sourceMappingURL=base-component.js.map
|
---|