Switch to the "doScroll approach" for the dom:loaded custom event. [#127 state:resolved]

This commit is contained in:
Andrew Dupont 2008-12-16 22:52:24 -06:00
parent bd1d3fa1ff
commit e9e8c7fbe5
2 changed files with 32 additions and 30 deletions

View File

@ -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)

View File

@ -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("<script id=__onDOMContentLoaded defer src=//:><\/script>");
$("__onDOMContentLoaded").onreadystatechange = _IEContentLoadedCheck;
document.observe('readystatechange', checkReadyState);
if (window === top)
timer = pollDoScroll.defer();
}
})();
// Worst-case fallback
Event.observe(window, 'load', fireContentLoadedEvent);
})();