Requires

Provides

Contains the custom event domready.

License:
MIT-style license.
  1. 18
  2. 19
  3. 20
  4. 21
  5. 22
  6. 23
  7. 24
  8. 25
(function(window, document){ var ready, loaded, checks = [], shouldPoll, timer, isFramed = true;

Thanks to Rich Dougherty http://www.richdougherty.com/

  1. 28
  2. 29
  3. 30
  4. 31
  5. 32
  6. 33
  7. 34
  8. 35
  9. 36
  10. 37
  11. 38
  12. 39
  13. 40
  14. 41
  15. 42
  16. 43
  17. 44
  18. 45
  19. 46
  20. 47
  21. 48
  22. 49
  23. 50
  24. 51
  25. 52
  26. 53
  27. 54
  28. 55
  29. 56
try { isFramed = window.frameElement != null; } catch(e){} var domready = function(){ clearTimeout(timer); if (ready) return; Browser.loaded = ready = true; document.removeListener('DOMContentLoaded', domready).removeListener('readystatechange', check); document.fireEvent('domready'); window.fireEvent('domready'); }; var check = function(){ for (var i = checks.length; i--;) if (checks[i]()){ domready(); return true; } return false; }; var poll = function(){ clearTimeout(timer); if (!check()) timer = setTimeout(poll, 10); }; document.addListener('DOMContentLoaded', domready);

doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/

  1. 59
  2. 60
  3. 61
  4. 62
  5. 63
  6. 64
  7. 65
  8. 66
  9. 67
  10. 68
  11. 69
  12. 70
  13. 71
  14. 72
  15. 73
  16. 74
  17. 75
  18. 76
  19. 77
  20. 78
  21. 79
  22. 80
  23. 81
  24. 82
  25. 83
  26. 84
  27. 85
  28. 86
var testElement = document.createElement('div'); if (testElement.doScroll && !isFramed){ checks.push(function(){ try { testElement.doScroll(); return true; } catch (e){} return false; }); shouldPoll = true; } if (document.readyState) checks.push(function(){ var state = document.readyState; return (state == 'loaded' || state == 'complete'); }); if ('onreadystatechange' in document) document.addListener('readystatechange', check); else shouldPoll = true; if (shouldPoll) poll(); Element.Events.domready = { onAdd: function(fn){ if (ready) fn.call(this); } };

Make sure that domready fires before load

  1. 89
  2. 90
  3. 91
  4. 92
  5. 93
  6. 94
  7. 95
  8. 96
  9. 97
  10. 98
  11. 99
  12. 100
  13. 101
  14. 102
Element.Events.load = { base: 'load', onAdd: function(fn){ if (loaded && this == window) fn.call(this); }, condition: function(){ if (this == window){ domready(); delete Element.Events.load; } return true; } };

This is based on the custom load event

  1. 105
  2. 106
  3. 107
  4. 108
  5. 109
window.addEvent('load', function(){ loaded = true; }); })(window, document);