domtastic
Version:
Small, fast, and modular DOM and event library for modern browsers.
23 lines (20 loc) • 557 B
JavaScript
/**
* @module Ready
*/
/**
* Execute callback when `DOMContentLoaded` fires for `document`, or immediately if called afterwards.
*
* @param handler Callback to execute when initial DOM content is loaded.
* @return {Object} The wrapped collection
* @chainable
* @example
* $(document).ready(callback);
*/
export const ready = function(handler) {
if(/complete|loaded|interactive/.test(document.readyState) && document.body) {
handler();
} else {
document.addEventListener('DOMContentLoaded', handler, false);
}
return this;
};