ready.js 804 B

123456789101112131415161718192021222324252627282930
  1. /*!
  2. * domready (c) Dustin Diaz 2014 - License MIT
  3. */
  4. !function (name, definition) {
  5. if (typeof module != 'undefined') module.exports = definition()
  6. else if (typeof define == 'function' && typeof define.amd == 'object') define(definition)
  7. else this[name] = definition()
  8. }('domready', function () {
  9. var fns = [], listener
  10. , doc = document
  11. , hack = doc.documentElement.doScroll
  12. , domContentLoaded = 'DOMContentLoaded'
  13. , loaded = (hack ? /^loaded|^c/ : /^loaded|^i|^c/).test(doc.readyState)
  14. if (!loaded)
  15. doc.addEventListener(domContentLoaded, listener = function () {
  16. doc.removeEventListener(domContentLoaded, listener)
  17. loaded = 1
  18. while (listener = fns.shift()) listener()
  19. })
  20. return function (fn) {
  21. loaded ? setTimeout(fn, 0) : fns.push(fn)
  22. }
  23. });