#35 fixed DOM ready event

This commit is contained in:
Serraniel 2020-08-29 16:20:53 +02:00
parent 98cc32cae4
commit 75f8869f7f
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3
2 changed files with 11 additions and 1 deletions

View file

@ -1,3 +1,5 @@
import * as helper from './helpers';
let __scripts = []; let __scripts = [];
let __afterLoadScripts = []; let __afterLoadScripts = [];
@ -16,7 +18,7 @@ export function initCore() {
attributes: true attributes: true
}); });
document.addEventListener("DOMContentLoaded", event => awaitPageLoaded(), false); helper.onReady(() => awaitPageLoaded());
} }
export function registerScript(func, pattern = '.*') { export function registerScript(func, pattern = '.*') {

View file

@ -10,6 +10,14 @@ export function initHelpers() {
document.addEventListener('keyup', event => handleKeyUp(event)); document.addEventListener('keyup', event => handleKeyUp(event));
} }
export function onReady(fn) {
if (document.readyState != 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
function handleKeyDown(event) { function handleKeyDown(event) {
handleKeyToggle(event, true); handleKeyToggle(event, true);
} }