Created
January 29, 2014 09:29
-
-
Save ranaroussi/8684488 to your computer and use it in GitHub Desktop.
standalone document "ready" function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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