mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Tests: move readywait to an iframe test
Close gh-3576 Fixes gh-3573
This commit is contained in:
parent
d33bb9c33a
commit
fcc9a9ec96
@ -23,16 +23,16 @@ jQuery.fn.extend( {
|
|||||||
return arguments.length === 1 ?
|
return arguments.length === 1 ?
|
||||||
this.off( selector, "**" ) :
|
this.off( selector, "**" ) :
|
||||||
this.off( types, selector || "**", fn );
|
this.off( types, selector || "**", fn );
|
||||||
},
|
}
|
||||||
holdReady: function( hold ) {
|
} );
|
||||||
|
|
||||||
|
jQuery.holdReady = function( hold ) {
|
||||||
if ( hold ) {
|
if ( hold ) {
|
||||||
jQuery.readyWait++;
|
jQuery.readyWait++;
|
||||||
} else {
|
} else {
|
||||||
jQuery.ready( true );
|
jQuery.ready( true );
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
} );
|
|
||||||
|
|
||||||
jQuery.isArray = Array.isArray;
|
jQuery.isArray = Array.isArray;
|
||||||
jQuery.parseJSON = JSON.parse;
|
jQuery.parseJSON = JSON.parse;
|
||||||
jQuery.nodeName = nodeName;
|
jQuery.nodeName = nodeName;
|
||||||
|
@ -14,22 +14,28 @@
|
|||||||
#output { background-color: green }
|
#output { background-color: green }
|
||||||
#expectedOutput { background-color: green }
|
#expectedOutput { background-color: green }
|
||||||
</style>
|
</style>
|
||||||
<script src="jquery.js"></script>
|
<script src="../jquery.js"></script>
|
||||||
|
<script src="./iframeTest.js"></script>
|
||||||
|
|
||||||
<!-- Load the script loader that uses
|
<!-- Load the script loader that uses
|
||||||
jQuery.readyWait -->
|
jQuery.readyWait -->
|
||||||
<script src="data/readywaitloader.js"></script>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
(function() {
|
||||||
|
var released = false;
|
||||||
|
// Hold on jQuery!
|
||||||
|
jQuery.holdReady( true );
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
released = true;
|
||||||
|
jQuery.holdReady( false );
|
||||||
|
}, 300 );
|
||||||
|
|
||||||
jQuery(function() {
|
jQuery(function() {
|
||||||
// The delayedMessage is defined by
|
jQuery( "#output" ).text( "Ready called, holdReady released: " + released );
|
||||||
// the readywaitasset.js file, so the
|
startIframeTest( released );
|
||||||
// next line will only work if this DOM
|
|
||||||
// ready callback is called after readyWait
|
|
||||||
// has been decremented by readywaitloader.js
|
|
||||||
// If an error occurs.
|
|
||||||
jQuery("#output").append(delayedMessage);
|
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
@ -1 +0,0 @@
|
|||||||
var delayedMessage = "It worked!";
|
|
@ -1,25 +0,0 @@
|
|||||||
// Simple script loader that uses jQuery.readyWait via jQuery.holdReady()
|
|
||||||
|
|
||||||
//Hold on jQuery!
|
|
||||||
jQuery.holdReady( true );
|
|
||||||
|
|
||||||
var readyRegExp = /^(complete|loaded)$/;
|
|
||||||
|
|
||||||
function assetLoaded( evt ) {
|
|
||||||
var node = evt.currentTarget || evt.srcElement;
|
|
||||||
if ( evt.type === "load" || readyRegExp.test( node.readyState ) ) {
|
|
||||||
jQuery.holdReady( false );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout( function() {
|
|
||||||
var script = document.createElement( "script" );
|
|
||||||
script.type = "text/javascript";
|
|
||||||
if ( script.addEventListener ) {
|
|
||||||
script.addEventListener( "load", assetLoaded, false );
|
|
||||||
} else {
|
|
||||||
script.attachEvent( "onreadystatechange", assetLoaded );
|
|
||||||
}
|
|
||||||
script.src = "data/readywaitasset.js";
|
|
||||||
document.getElementsByTagName( "head" )[ 0 ].appendChild( script );
|
|
||||||
}, 2000 );
|
|
@ -4,6 +4,7 @@ QUnit.module( "ready" );
|
|||||||
var notYetReady, noEarlyExecution,
|
var notYetReady, noEarlyExecution,
|
||||||
whenified = jQuery.when( jQuery.ready ),
|
whenified = jQuery.when( jQuery.ready ),
|
||||||
promisified = Promise.resolve( jQuery.ready ),
|
promisified = Promise.resolve( jQuery.ready ),
|
||||||
|
start = new Date(),
|
||||||
order = [],
|
order = [],
|
||||||
args = {};
|
args = {};
|
||||||
|
|
||||||
@ -147,4 +148,16 @@ QUnit.module( "ready" );
|
|||||||
done();
|
done();
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
testIframe(
|
||||||
|
"holdReady test needs to be a standalone test since it deals with DOM ready",
|
||||||
|
"readywait.html",
|
||||||
|
function( assert, jQuery, window, document, releaseCalled ) {
|
||||||
|
assert.expect( 2 );
|
||||||
|
var now = new Date();
|
||||||
|
assert.ok( now - start >= 300, "Needs to have waited at least half a second" );
|
||||||
|
assert.ok( releaseCalled, "The release function was called, which resulted in ready" );
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
} )();
|
} )();
|
||||||
|
Loading…
Reference in New Issue
Block a user