Skip to content

Commit

Permalink
refactor(js/profile-w3c-common): DOMready
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored and Marcos Cáceres committed Jun 22, 2017
1 parent cc02b86 commit 78ca7b8
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions js/profile-w3c-common.js
Expand Up @@ -3,13 +3,9 @@
if (document.body) {
document.body.hidden = true;
} else {
document.addEventListener(
"DOMContentLoaded",
function() {
document.body.hidden = true;
},
{ once: true }
);
document.addEventListener("DOMContentLoaded", function() {
document.body.hidden = true;
});
}

// In case everything else fails, we always want to show the document
Expand Down Expand Up @@ -41,9 +37,16 @@ require.config({
});

const domReady = new Promise(function(resolve) {
return document.readyState === "complete"
? resolve()
: document.addEventListener("DOMContentLoaded", resolve);
if (document.readyState === "interactive" || document.readyState === "complete" ) {
return resolve();
}
document.addEventListener("readystatechange", function listener() {
if (document.readyState === "interactive" || document.readyState === "complete" ) {
return;
}
document.removeEventListener("readystatechange", listener);
resolve();
});
});

define(
Expand Down

0 comments on commit 78ca7b8

Please sign in to comment.