1 |
efrain |
1 |
/**
|
|
|
2 |
* --------------------------------------------------------------------------
|
|
|
3 |
* Bootstrap (v4.6.2): util.js
|
|
|
4 |
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
|
5 |
* --------------------------------------------------------------------------
|
|
|
6 |
*/
|
|
|
7 |
|
|
|
8 |
import $ from 'jquery'
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Private TransitionEnd Helpers
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
const TRANSITION_END = 'transitionend'
|
|
|
15 |
const MAX_UID = 1000000
|
|
|
16 |
const MILLISECONDS_MULTIPLIER = 1000
|
|
|
17 |
|
|
|
18 |
// Shoutout AngusCroll (https://goo.gl/pxwQGp)
|
|
|
19 |
function toType(obj) {
|
|
|
20 |
if (obj === null || typeof obj === 'undefined') {
|
|
|
21 |
return `${obj}`
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase()
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
function getSpecialTransitionEndEvent() {
|
|
|
28 |
return {
|
|
|
29 |
bindType: TRANSITION_END,
|
|
|
30 |
delegateType: TRANSITION_END,
|
|
|
31 |
handle(event) {
|
|
|
32 |
if ($(event.target).is(this)) {
|
|
|
33 |
return event.handleObj.handler.apply(this, arguments) // eslint-disable-line prefer-rest-params
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
return undefined
|
|
|
37 |
}
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
function transitionEndEmulator(duration) {
|
|
|
42 |
let called = false
|
|
|
43 |
|
|
|
44 |
$(this).one(Util.TRANSITION_END, () => {
|
|
|
45 |
called = true
|
|
|
46 |
})
|
|
|
47 |
|
|
|
48 |
setTimeout(() => {
|
|
|
49 |
if (!called) {
|
|
|
50 |
Util.triggerTransitionEnd(this)
|
|
|
51 |
}
|
|
|
52 |
}, duration)
|
|
|
53 |
|
|
|
54 |
return this
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
function setTransitionEndSupport() {
|
|
|
58 |
$.fn.emulateTransitionEnd = transitionEndEmulator
|
|
|
59 |
$.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent()
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/**
|
|
|
63 |
* Public Util API
|
|
|
64 |
*/
|
|
|
65 |
|
|
|
66 |
const Util = {
|
|
|
67 |
TRANSITION_END: 'bsTransitionEnd',
|
|
|
68 |
|
|
|
69 |
getUID(prefix) {
|
|
|
70 |
do {
|
|
|
71 |
// eslint-disable-next-line no-bitwise
|
|
|
72 |
prefix += ~~(Math.random() * MAX_UID) // "~~" acts like a faster Math.floor() here
|
|
|
73 |
} while (document.getElementById(prefix))
|
|
|
74 |
|
|
|
75 |
return prefix
|
|
|
76 |
},
|
|
|
77 |
|
|
|
78 |
getSelectorFromElement(element) {
|
|
|
79 |
let selector = element.getAttribute('data-target')
|
|
|
80 |
|
|
|
81 |
if (!selector || selector === '#') {
|
|
|
82 |
const hrefAttr = element.getAttribute('href')
|
|
|
83 |
selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : ''
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
try {
|
|
|
87 |
return document.querySelector(selector) ? selector : null
|
|
|
88 |
} catch (_) {
|
|
|
89 |
return null
|
|
|
90 |
}
|
|
|
91 |
},
|
|
|
92 |
|
|
|
93 |
getTransitionDurationFromElement(element) {
|
|
|
94 |
if (!element) {
|
|
|
95 |
return 0
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
// Get transition-duration of the element
|
|
|
99 |
let transitionDuration = $(element).css('transition-duration')
|
|
|
100 |
let transitionDelay = $(element).css('transition-delay')
|
|
|
101 |
|
|
|
102 |
const floatTransitionDuration = parseFloat(transitionDuration)
|
|
|
103 |
const floatTransitionDelay = parseFloat(transitionDelay)
|
|
|
104 |
|
|
|
105 |
// Return 0 if element or transition duration is not found
|
|
|
106 |
if (!floatTransitionDuration && !floatTransitionDelay) {
|
|
|
107 |
return 0
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
// If multiple durations are defined, take the first
|
|
|
111 |
transitionDuration = transitionDuration.split(',')[0]
|
|
|
112 |
transitionDelay = transitionDelay.split(',')[0]
|
|
|
113 |
|
|
|
114 |
return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER
|
|
|
115 |
},
|
|
|
116 |
|
|
|
117 |
reflow(element) {
|
|
|
118 |
return element.offsetHeight
|
|
|
119 |
},
|
|
|
120 |
|
|
|
121 |
triggerTransitionEnd(element) {
|
|
|
122 |
$(element).trigger(TRANSITION_END)
|
|
|
123 |
},
|
|
|
124 |
|
|
|
125 |
supportsTransitionEnd() {
|
|
|
126 |
return Boolean(TRANSITION_END)
|
|
|
127 |
},
|
|
|
128 |
|
|
|
129 |
isElement(obj) {
|
|
|
130 |
return (obj[0] || obj).nodeType
|
|
|
131 |
},
|
|
|
132 |
|
|
|
133 |
typeCheckConfig(componentName, config, configTypes) {
|
|
|
134 |
for (const property in configTypes) {
|
|
|
135 |
if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
|
|
|
136 |
const expectedTypes = configTypes[property]
|
|
|
137 |
const value = config[property]
|
|
|
138 |
const valueType = value && Util.isElement(value) ?
|
|
|
139 |
'element' : toType(value)
|
|
|
140 |
|
|
|
141 |
if (!new RegExp(expectedTypes).test(valueType)) {
|
|
|
142 |
throw new Error(
|
|
|
143 |
`${componentName.toUpperCase()}: ` +
|
|
|
144 |
`Option "${property}" provided type "${valueType}" ` +
|
|
|
145 |
`but expected type "${expectedTypes}".`)
|
|
|
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
},
|
|
|
150 |
|
|
|
151 |
findShadowRoot(element) {
|
|
|
152 |
if (!document.documentElement.attachShadow) {
|
|
|
153 |
return null
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
// Can find the shadow root otherwise it'll return the document
|
|
|
157 |
if (typeof element.getRootNode === 'function') {
|
|
|
158 |
const root = element.getRootNode()
|
|
|
159 |
return root instanceof ShadowRoot ? root : null
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
if (element instanceof ShadowRoot) {
|
|
|
163 |
return element
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
// when we don't find a shadow root
|
|
|
167 |
if (!element.parentNode) {
|
|
|
168 |
return null
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
return Util.findShadowRoot(element.parentNode)
|
|
|
172 |
},
|
|
|
173 |
|
|
|
174 |
jQueryDetection() {
|
|
|
175 |
if (typeof $ === 'undefined') {
|
|
|
176 |
throw new TypeError('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.')
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
const version = $.fn.jquery.split(' ')[0].split('.')
|
|
|
180 |
const minMajor = 1
|
|
|
181 |
const ltMajor = 2
|
|
|
182 |
const minMinor = 9
|
|
|
183 |
const minPatch = 1
|
|
|
184 |
const maxMajor = 4
|
|
|
185 |
|
|
|
186 |
if (version[0] < ltMajor && version[1] < minMinor || version[0] === minMajor && version[1] === minMinor && version[2] < minPatch || version[0] >= maxMajor) {
|
|
|
187 |
throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0')
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
Util.jQueryDetection()
|
|
|
193 |
setTransitionEndSupport()
|
|
|
194 |
|
|
|
195 |
export default Util
|