Skip to content

Instantly share code, notes, and snippets.

@ranaroussi
Created January 29, 2014 09:29
Show Gist options
  • Save ranaroussi/8684488 to your computer and use it in GitHub Desktop.
Save ranaroussi/8684488 to your computer and use it in GitHub Desktop.
standalone document "ready" function
function docReady(callback, bubble) {
var addListener = this.addEventListener || this.attachEvent,
removeListener = this.removeEventListener || this.detachEvent
if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
callback();
return;
}
bubble = bubble || false;
var eventName = document.addEventListener ? "DOMContentLoaded" : "onreadystatechange";
addListener.call(document, eventName, function(event) {
removeListener(eventName, arguments.callee, bubble);
callback();
}, bubble);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment