Browse Source

Woops

jpeg-test
Luke Childs 8 years ago
parent
commit
71a40bd81c
  1. 1
      .gitignore
  2. 40
      dist/index.js

1
.gitignore

@ -1,4 +1,5 @@
## Node
dist
# Logs
logs

40
dist/index.js

@ -1,40 +0,0 @@
// Loaded ready states
const loadedStates = ['interactive', 'complete'];
// Return Promise
const whenDomReady = function (cb, doc) {
return new Promise(function (resolve) {
// Allow doc to be passed in as the lone first param
if (cb && typeof cb !== 'function') {
doc = cb;
cb = null;
}
// Use global document if we don't have one
doc = doc || window.document;
// Handle DOM load
const done = function () {
return resolve(cb && cb());
};
// Resolve now if DOM has already loaded
// Otherwise wait for DOMContentLoaded
if (loadedStates.indexOf(doc.readyState) !== -1) {
setTimeout(done, 0);
} else {
doc.addEventListener('DOMContentLoaded', done);
}
});
};
// Promise chain helper
whenDomReady.resume = function (doc) {
return function (val) {
return whenDomReady(doc).then(function () {
return val;
});
};
};
module.exports = whenDomReady;
Loading…
Cancel
Save