Changed the $(document).ready() code to try and solve some problems in Safari, Opera, and IE.
This commit is contained in:
parent
ba9c14a589
commit
0419455473
1 changed files with 39 additions and 8 deletions
45
src/event.js
45
src/event.js
|
@ -489,27 +489,58 @@ function bindReady(){
|
||||||
if ( readyBound ) return;
|
if ( readyBound ) return;
|
||||||
readyBound = true;
|
readyBound = true;
|
||||||
|
|
||||||
// Mozilla, Opera and webkit nightlies currently support this event
|
// Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
|
||||||
if ( document.addEventListener )
|
if ( document.addEventListener && !jQuery.browser.opera)
|
||||||
// Use the handy event callback
|
// Use the handy event callback
|
||||||
document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
|
document.addEventListener( "DOMContentLoaded", jQuery.ready, false );
|
||||||
|
|
||||||
// If Safari or IE is used
|
// If IE is used and is not in a frame
|
||||||
// Continually check to see if the document is ready
|
// Continually check to see if the document is ready
|
||||||
if (jQuery.browser.msie || jQuery.browser.safari ) (function(){
|
if ( jQuery.browser.msie && window == top ) (function(){
|
||||||
|
if (jQuery.isReady) return;
|
||||||
try {
|
try {
|
||||||
// If IE is used, use the trick by Diego Perini
|
// If IE is used, use the trick by Diego Perini
|
||||||
// http://javascript.nwbox.com/IEContentLoaded/
|
// http://javascript.nwbox.com/IEContentLoaded/
|
||||||
if ( jQuery.browser.msie || document.readyState != "loaded" && document.readyState != "complete" )
|
|
||||||
document.documentElement.doScroll("left");
|
document.documentElement.doScroll("left");
|
||||||
} catch( error ) {
|
} catch( error ) {
|
||||||
return setTimeout( arguments.callee, 0 );
|
setTimeout( arguments.callee, 0 );
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// and execute any waiting functions
|
// and execute any waiting functions
|
||||||
jQuery.ready();
|
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();
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
|
||||||
// A fallback to window.onload, that will always work
|
// A fallback to window.onload, that will always work
|
||||||
jQuery.event.add( window, "load", jQuery.ready );
|
jQuery.event.add( window, "load", jQuery.ready );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue