Commit 66501469 authored by Richard Gibson's avatar Richard Gibson Committed by timmywil

Close GH-829: no ticket: smaller jQuery.ready.

parent 6cdca88e
...@@ -367,28 +367,30 @@ jQuery.extend({ ...@@ -367,28 +367,30 @@ jQuery.extend({
// Handle when the DOM is ready // Handle when the DOM is ready
ready: function( wait ) { ready: function( wait ) {
// Either a released hold or an DOMready/load event and not yet ready // Abort if there are pending holds or we're already ready
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) { if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). return;
if ( !document.body ) { }
return setTimeout( jQuery.ready, 1 );
}
// Remember that the DOM is ready // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
jQuery.isReady = true; if ( !document.body ) {
return setTimeout( jQuery.ready, 1 );
}
// If a normal DOM Ready event fired, decrement, and wait if need be // Remember that the DOM is ready
if ( wait !== true && --jQuery.readyWait > 0 ) { jQuery.isReady = true;
return;
}
// If there are functions bound, to execute // If a normal DOM Ready event fired, decrement, and wait if need be
readyList.resolveWith( document, [ jQuery ] ); if ( wait !== true && --jQuery.readyWait > 0 ) {
return;
}
// Trigger any bound ready events // If there are functions bound, to execute
if ( jQuery.fn.trigger ) { readyList.resolveWith( document, [ jQuery ] );
jQuery( document ).trigger( "ready" ).off( "ready" );
} // Trigger any bound ready events
if ( jQuery.fn.trigger ) {
jQuery( document ).trigger("ready").off("ready");
} }
}, },
...@@ -853,14 +855,28 @@ jQuery.ready.promise = function( object ) { ...@@ -853,14 +855,28 @@ jQuery.ready.promise = function( object ) {
// If IE and not a frame // If IE and not a frame
// continually check to see if the document is ready // continually check to see if the document is ready
var toplevel = false; var top = false;
try { try {
toplevel = window.frameElement == null; top = window.frameElement == null && document.documentElement;
} catch(e) {} } catch(e) {}
if ( document.documentElement.doScroll && toplevel ) { if ( top && top.doScroll ) {
doScrollCheck(); (function doScrollCheck() {
if ( !jQuery.isReady ) {
try {
// Use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
top.doScroll("left");
} catch(e) {
return setTimeout( doScrollCheck, 1 );
}
// and execute any waiting functions
jQuery.ready();
}
})();
} }
} }
} }
...@@ -891,22 +907,3 @@ if ( core_rnotwhite.test( "\xA0" ) ) { ...@@ -891,22 +907,3 @@ if ( core_rnotwhite.test( "\xA0" ) ) {
// All jQuery objects should point back to these // All jQuery objects should point back to these
rootjQuery = jQuery(document); rootjQuery = jQuery(document);
// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
jQuery.ready();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment