mirror of
https://github.com/jquery/jquery.git
synced 2026-02-06 16:04:59 -05:00
Fix #10067. Create jQuery.quickReady; closes gh-736.
Allows us to get to the ready state sooner by not waiting for iframes to load. If that causes backcompat pain, use `jQuery.quickReady = false` as prescribed by your developer.
This commit is contained in:
committed by
Dave Methvin
parent
58ed62ed12
commit
54fab3174c
16
src/core.js
16
src/core.js
@@ -375,6 +375,9 @@ jQuery.extend({
|
||||
// the ready event fires. See #6781
|
||||
readyWait: 1,
|
||||
|
||||
// should we fire ready on readyState "interactive" ?
|
||||
quickReady: true,
|
||||
|
||||
// Hold (or release) the ready event
|
||||
holdReady: function( hold ) {
|
||||
if ( hold ) {
|
||||
@@ -386,6 +389,12 @@ jQuery.extend({
|
||||
|
||||
// Handle when the DOM is ready
|
||||
ready: function( wait ) {
|
||||
// user wasn't necessarily given the chance to set jQuery.quickReady before bindReady
|
||||
// so we check here for quickReady instead
|
||||
if ( !jQuery.quickReady && document.readyState === "interactive" ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Either a released hold or an DOMready/load event and not yet ready
|
||||
if ( (wait === true && !--jQuery.readyWait) || (wait !== true && !jQuery.isReady) ) {
|
||||
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
|
||||
@@ -420,9 +429,9 @@ jQuery.extend({
|
||||
|
||||
// Catch cases where $(document).ready() is called after the
|
||||
// browser event has already occurred.
|
||||
if ( document.readyState === "complete" ) {
|
||||
if ( document.readyState !== "loading" ) {
|
||||
// Handle it asynchronously to allow scripts the opportunity to delay ready
|
||||
return setTimeout( jQuery.ready, 1 );
|
||||
setTimeout( jQuery.ready, 1 );
|
||||
}
|
||||
|
||||
// Mozilla, Opera and webkit nightlies currently support this event
|
||||
@@ -915,6 +924,7 @@ rootjQuery = jQuery(document);
|
||||
// Cleanup functions for the document ready method
|
||||
if ( document.addEventListener ) {
|
||||
DOMContentLoaded = function() {
|
||||
jQuery.quickReady = true;
|
||||
document.removeEventListener( "DOMContentLoaded", DOMContentLoaded, false );
|
||||
jQuery.ready();
|
||||
};
|
||||
@@ -922,7 +932,7 @@ if ( document.addEventListener ) {
|
||||
} else if ( document.attachEvent ) {
|
||||
DOMContentLoaded = function() {
|
||||
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
|
||||
if ( document.readyState === "complete" ) {
|
||||
if ( document.readyState === "complete" || ( jQuery.quickReady && document.readyState === "interactive" ) ) {
|
||||
document.detachEvent( "onreadystatechange", DOMContentLoaded );
|
||||
jQuery.ready();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user