Merge branch 'bugfix/#23-runAfterLoad-only-works-if-called-before-page-loaded' into feature/#19-notifications-tab-title
This commit is contained in:
commit
9bb9f50013
|
@ -29,16 +29,34 @@ observer.observe(document.documentElement || document.body, {
|
||||||
attributes: true
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function findPreloader() {
|
||||||
|
return document.getElementById('preloader');
|
||||||
|
}
|
||||||
|
|
||||||
function runAfterLoad(func, pattern = '.*') {
|
function runAfterLoad(func, pattern = '.*') {
|
||||||
|
let preloader = findPreloader();
|
||||||
|
if (typeof preloader !== undefined && preloader.style.display !== "none") {
|
||||||
__afterLoadScripts.push({ "function": func, "pattern": pattern });
|
__afterLoadScripts.push({ "function": func, "pattern": pattern });
|
||||||
|
} else {
|
||||||
|
func();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false);
|
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false);
|
||||||
|
|
||||||
function awaitPageLoaded() {
|
function awaitPageLoaded() {
|
||||||
let preLoader = document.getElementById('preloader');
|
let preLoader = findPreloader();
|
||||||
|
|
||||||
|
let runScripts = () => {
|
||||||
|
__afterLoadScripts.forEach(script => {
|
||||||
|
if (window.location.pathname.match(script.pattern)) {
|
||||||
|
script.function();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (typeof preLoader === 'undefined') {
|
if (typeof preLoader === 'undefined') {
|
||||||
|
runScripts();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,11 +64,7 @@ function awaitPageLoaded() {
|
||||||
if (preLoader.style.display === "none") {
|
if (preLoader.style.display === "none") {
|
||||||
clearInterval(loop);
|
clearInterval(loop);
|
||||||
|
|
||||||
__afterLoadScripts.forEach(script => {
|
runScripts();
|
||||||
if (window.location.pathname.match(script.pattern)) {
|
|
||||||
script.function();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue