Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix(demos): Fix ready.js to avoid false positive before document load (
Browse files Browse the repository at this point in the history
  • Loading branch information
kfranqueiro authored Feb 3, 2018
1 parent 13b5605 commit 2fe4dcd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion demos/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ window.demoReady = (function(root) {
var POLL_MAX_WAIT_MS = 60 * 1000;

var isReadyCached = false;
var isDomLoaded = false;
var handlers = [];
var testDom = null;
var startTimeMs = null;
Expand All @@ -38,7 +39,7 @@ window.demoReady = (function(root) {
}
ensureDetectionDom();
isReadyCached = getComputedStyle(testDom).position === 'relative' &&
(Boolean(window.mdc) || !root.querySelector('script[src*="material-components-web.js"]'));
(Boolean(window.mdc) || (isDomLoaded && !root.querySelector('script[src*="material-components-web.js"]')));
return isReadyCached;
}

Expand Down Expand Up @@ -94,6 +95,10 @@ window.demoReady = (function(root) {
handlers.length = 0;
}

root.addEventListener('DOMContentLoaded', function() {
isDomLoaded = true;
});

return function addHandler(handler) {
if (isReady()) {
handler(root);
Expand Down

0 comments on commit 2fe4dcd

Please sign in to comment.