Skip to content

Instantly share code, notes, and snippets.

@contra contra/stuff.coffee

Created Apr 24, 2012
Embed
What would you like to do?
Tiny DOMReady javascript/coffee-script
# 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
You can’t perform that action at this time.