diff --git a/CHANGELOG b/CHANGELOG index 1f1aa49..555c80d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Switch to the "doScroll approach" for the dom:loaded custom event. (javier, Diego Perini, Nick Stakenburg, Andrew Dupont) + * Optimize document.viewport.get(Dimensions|Width|Height). (Nick Stakenburg, Andrew Dupont) * Fix issue where Object#isString and Object#isNumber return false for String and Number "wrapper" objects. (atrepp, Samuel Lebeau, Andrew Dupont) diff --git a/src/dom/event.js b/src/dom/event.js index 29b5a29..d1922f6 100644 --- a/src/dom/event.js +++ b/src/dom/event.js @@ -371,42 +371,42 @@ })(); (function() { - /* Support for the DOMContentLoaded event is based on work by Dan Webb, - Matthias Miller, Dean Edwards and John Resig. */ + /* Support for the DOMContentLoaded event is based on work by Dan Webb, + Matthias Miller, Dean Edwards, John Resig, and Diego Perini. */ - var _timer; - - function _fireContentLoadedEvent() { + var timer; + + function fireContentLoadedEvent() { if (document.loaded) return; - if (_timer) window.clearInterval(_timer); - + if (timer) window.clearTimeout(timer); document.loaded = true; - document.fire("dom:loaded"); + document.fire('dom:loaded'); } - - function _webkitContentLoadedCheck() { - var s = document.readyState; - if (s === "loaded" || s === "complete") - _fireContentLoadedEvent(); - } - - function _IEContentLoadedCheck() { - if (this.readyState == "complete") { - this.onreadystatechange = null; - _fireContentLoadedEvent(); + + function checkReadyState() { + if (document.readyState === 'complete') { + document.stopObserving('readystatechange', checkReadyState); + fireContentLoadedEvent(); } } - - if (document.addEventListener) { - if (Prototype.Browser.WebKit) { - _timer = window.setInterval(_webkitContentLoadedCheck, 0); - Event.observe(window, "load", _fireContentLoadedEvent); - } else { - document.addEventListener("DOMContentLoaded", - _fireContentLoadedEvent, false); + + function pollDoScroll() { + try { document.documentElement.doScroll('left'); } + catch(e) { + timer = pollDoScroll.defer(); + return; } + fireContentLoadedEvent(); + } + + if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', fireContentLoadedEvent, false); } else { - document.write("