aboutsummaryrefslogtreecommitdiff
path: root/js/src/util/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/util/index.js')
-rw-r--r--js/src/util/index.js30
1 files changed, 24 insertions, 6 deletions
diff --git a/js/src/util/index.js b/js/src/util/index.js
index 6edfaa580..136b13cb5 100644
--- a/js/src/util/index.js
+++ b/js/src/util/index.js
@@ -1,8 +1,6 @@
-import SelectorEngine from '../dom/selector-engine'
-
/**
* --------------------------------------------------------------------------
- * Bootstrap (v5.0.1): util/index.js
+ * Bootstrap (v5.0.2): util/index.js
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
* --------------------------------------------------------------------------
*/
@@ -120,7 +118,7 @@ const getElement = obj => {
}
if (typeof obj === 'string' && obj.length > 0) {
- return SelectorEngine.findOne(obj)
+ return document.querySelector(obj)
}
return null
@@ -189,7 +187,18 @@ const findShadowRoot = element => {
const noop = () => {}
-const reflow = element => element.offsetHeight
+/**
+ * Trick to restart an element's animation
+ *
+ * @param {HTMLElement} element
+ * @return void
+ *
+ * @see https://www.charistheo.io/blog/2021/02/restart-a-css-animation-with-javascript/#restarting-a-css-animation
+ */
+const reflow = element => {
+ // eslint-disable-next-line no-unused-expressions
+ element.offsetHeight
+}
const getjQuery = () => {
const { jQuery } = window
@@ -201,9 +210,18 @@ const getjQuery = () => {
return null
}
+const DOMContentLoadedCallbacks = []
+
const onDOMContentLoaded = callback => {
if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', callback)
+ // add listener on the first call when the document is in loading state
+ if (!DOMContentLoadedCallbacks.length) {
+ document.addEventListener('DOMContentLoaded', () => {
+ DOMContentLoadedCallbacks.forEach(callback => callback())
+ })
+ }
+
+ DOMContentLoadedCallbacks.push(callback)
} else {
callback()
}