Skip to content

Commit

Permalink
Simplifying the DOM ready code, no longer attempting to handle styles…
Browse files Browse the repository at this point in the history
…heet loading. Closes #2614.
  • Loading branch information
jeresig committed Dec 19, 2008
1 parent ba4453d commit 4c1e12e
Showing 1 changed file with 14 additions and 40 deletions.
54 changes: 14 additions & 40 deletions src/event.js
Expand Up @@ -521,27 +521,30 @@ function bindReady(){
if ( readyBound ) return;
readyBound = true;

// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
if ( document.addEventListener && !jQuery.browser.opera)
// Mozilla, Opera and webkit nightlies currently support this event
if ( document.addEventListener ) {
// Use the handy event callback
document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
document.addEventListener( "DOMContentLoaded", function(){
document.removeEventListener( "DOMContentLoaded", arguments.callee, false );
jQuery.ready();
}, false );

// If IE event model is used
if ( document.attachEvent )
} else if ( document.attachEvent ) {
// ensure firing before onload,
// maybe late but safe also for iframes
document.attachEvent("onreadystatechange", function(e) {
if ( document.readyState == "complete" ) {
document.detachEvent("onreadystatechange", arguments.callee );
document.attachEvent("onreadystatechange", function(){
if ( document.readyState === "complete" ) {
document.detachEvent( "onreadystatechange", arguments.callee );
jQuery.ready();
}
});

// If IE and not an iframe
if ( document.documentElement.doScroll && !window.frameElement )
// If IE and not an iframe
// continually check to see if the document is ready
(function(){
if (jQuery.isReady) return;
if ( document.documentElement.doScroll && !window.frameElement ) (function(){
if ( jQuery.isReady ) return;

try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
Expand All @@ -550,36 +553,7 @@ function bindReady(){
setTimeout( arguments.callee, 0 );
return;
}
// and execute any waiting functions
jQuery.ready();
})();

if ( jQuery.browser.opera )
document.addEventListener( "DOMContentLoaded", function () {
if (jQuery.isReady) return;
for (var i = 0; i < document.styleSheets.length; i++)
if (document.styleSheets[i].disabled) {
setTimeout( arguments.callee, 0 );
return;
}
// and execute any waiting functions
jQuery.ready();
}, false);

if ( jQuery.browser.safari ) {
var numStyles;
(function(){
if (jQuery.isReady) return;
if ( document.readyState != "loaded" && document.readyState != "complete" ) {
setTimeout( arguments.callee, 0 );
return;
}
if ( numStyles === undefined )
numStyles = jQuery("style, link[rel=stylesheet]").length;
if ( document.styleSheets.length != numStyles ) {
setTimeout( arguments.callee, 0 );
return;
}
// and execute any waiting functions
jQuery.ready();
})();
Expand Down

0 comments on commit 4c1e12e

Please sign in to comment.