Created
April 24, 2012 07:55
-
-
Save yocontra/2477661 to your computer and use it in GitHub Desktop.
Tiny DOMReady javascript/coffee-script
This file contains 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
# DOM ready | |
window.ready ?= (fn) -> | |
fire = -> | |
unless window.ready.fired | |
window.ready.fired = true | |
fn() | |
return fire() if document.readyState is "complete" | |
# Mozilla, Opera, WebKit | |
if document.addEventListener | |
document.addEventListener "DOMContentLoaded", fire, false | |
window.addEventListener "load", fire, false | |
# IE | |
else if document.attachEvent | |
check = -> | |
try | |
document.documentElement.doScroll "left" | |
catch e | |
setTimeout check, 1 | |
return | |
fire() | |
document.attachEvent "onreadystatechange", fire | |
window.attachEvent "onload", fire | |
check() if document.documentElement and document.documentElement.doScroll and !window.frameElement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment