firefly-iii/resources/assets/v4/util/index.js

25 lines
609 B
JavaScript
Raw Normal View History

2023-07-11 04:45:55 -05:00
const domContentLoadedCallbacks = [];
// from admin LTE
const onDOMContentLoaded = (callback) => {
if (document.readyState === 'loading') {
// add listener on the first call when the document is in loading state
if (!domContentLoadedCallbacks.length) {
document.addEventListener('DOMContentLoaded', () => {
for (const callback of domContentLoadedCallbacks) {
callback()
}
})
}
domContentLoadedCallbacks.push(callback)
} else {
callback()
}
}
export {
onDOMContentLoaded,
}