Created
November 20, 2015 11:41
-
-
Save terry-fei/90c62c7fc034a22f52a6 to your computer and use it in GitHub Desktop.
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
/*! | |
* domready (c) Dustin Diaz 2012 - License MIT | |
*/ | |
var domready = (function domready() { | |
var fns = [], | |
listener, | |
doc = document, | |
hack = doc.documentElement.doScroll, | |
domContentLoaded = 'DOMContentLoaded', | |
loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState); | |
if (!loaded) { | |
doc.addEventListener(domContentLoaded, listener = function () { | |
doc.removeEventListener(domContentLoaded, listener); | |
loaded = 1; | |
while (listener = fns.shift()) { // jshint ignore:line | |
listener(); | |
} | |
}); | |
} | |
return function (fn) { | |
if (loaded) { | |
setTimeout(fn, 0); | |
} else { | |
fns.push(fn); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment