Skip to content

Instantly share code, notes, and snippets.

@joyrexus
Created May 8, 2013 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joyrexus/5541992 to your computer and use it in GitHub Desktop.
Save joyrexus/5541992 to your computer and use it in GitHub Desktop.
$(document).ready( ... ) sans jquery.
// see https://github.com/ded/domready and http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
!function(a,ctx,b){typeof module!="undefined"?module.exports=b():typeof
define=="function"&&typeof define.amd=="object"?define(b):ctx[a]=b()}("domready",this,
function(a){function m(a){l=1;while(a=b.shift())a()}var b=[],c,d=!1,e=document,f=e.
documentElement,g=f.doScroll,h="DOMContentLoaded",i="addEventListener",
j="onreadystatechange",k="readyState",l=/^loade|c/.test(e[k]);return e[i]&&e[i](h,
c=function(){e.removeEventListener(h,c,d),m()},d),g&&e.attachEvent(j,c=function(){/^c/.
test(e[k])&&(e.detachEvent(j,c),m())}),a=g?function(c){self!=top?l?c():b.push(c):
function(){try{f.doScroll("left")}catch(b){return setTimeout(function(){a(c)},50)}c()}()}:
function(a){l?a():b.push(a)}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment