es6-docready
Version:
Document ready listener using plain javascript and ES6 module syntax
31 lines (23 loc) • 849 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = docReady;
function docReady(callback) {
function completed() {
document.removeEventListener("DOMContentLoaded", completed, false);
window.removeEventListener("load", completed, false);
callback();
}
//Events.on(document, 'DOMContentLoaded', completed)
if (document.readyState === "complete") {
// Handle it asynchronously to allow scripts the opportunity to delay ready
setTimeout(callback);
} else {
// Use the handy event callback
document.addEventListener("DOMContentLoaded", completed, false);
// A fallback to window.onload, that will always work
window.addEventListener("load", completed, false);
}
}
module.exports = exports["default"];
;