blob: d48d708e93e2d9e362179b5f33008d226723aad4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
// borrowed from https://stackoverflow.com/questions/9899372/pure-javascript-equivalent-of-jquerys-ready-how-to-call-a-function-when-t
function docReady(fn) {
// see if DOM is already available
if (document.readyState === "complete" || document.readyState === "interactive") {
// call on next available tick
setTimeout(fn, 1);
} else {
document.addEventListener("DOMContentLoaded", fn);
}
}
function windowLoaded(fn) {
// see if we're already loaded
if (document.readyState === "complete") {
// call on next available tick
setTimeout(fn, 1);
} else {
window.addEventListener("load", fn);
}
}
function onWindowResize(fn) {
windowLoaded(function () {
window.addEventListener('resize', fn);
setTimeout(fn, 1);
});
}
export { docReady, windowLoaded, onWindowResize};
|