mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Traversing: $.fn.contents() support for object
Fixes gh-4045 Closes gh-4046
This commit is contained in:
parent
821bf34353
commit
0ba8e38d0c
@ -209,7 +209,7 @@ module.exports = function( grunt ) {
|
||||
{ pattern: "dist/*.map", included: false, served: true },
|
||||
{ pattern: "external/qunit/qunit.css", included: false, served: true },
|
||||
{
|
||||
pattern: "test/**/*.@(js|css|jpg|html|xml)",
|
||||
pattern: "test/**/*.@(js|css|jpg|html|xml|svg)",
|
||||
included: false,
|
||||
served: true
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ jQuery.each( {
|
||||
return siblings( elem.firstChild );
|
||||
},
|
||||
contents: function( elem ) {
|
||||
if ( nodeName( elem, "iframe" ) ) {
|
||||
if ( typeof elem.contentDocument !== "undefined" ) {
|
||||
return elem.contentDocument;
|
||||
}
|
||||
|
||||
|
6
test/data/1x1.svg
Normal file
6
test/data/1x1.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<svg width="1px" height="1px"
|
||||
xmlns="http://www.w3.org/2000/svg">
|
||||
</svg>
|
After Width: | Height: | Size: 225 B |
9
test/data/frame.html
Normal file
9
test/data/frame.html
Normal file
@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>frame</title>
|
||||
</head>
|
||||
<frameset cols="20%, 80%">
|
||||
<frame id="test-frame" src="iframe.html">
|
||||
<frame src="iframe.html">
|
||||
</frameset>
|
||||
</html>
|
@ -773,9 +773,7 @@ QUnit.test( "contents() for <template />", function( assert ) {
|
||||
assert.equal( contents.filter( "div" ).length, 3, "Count cloned elements from template" );
|
||||
} );
|
||||
|
||||
QUnit[ "content" in document.createElement( "template" ) ? "test" : "skip" ](
|
||||
"contents() for <template /> remains inert",
|
||||
function( assert ) {
|
||||
QUnit[ "content" in document.createElement( "template" ) ? "test" : "skip" ]( "contents() for <template /> remains inert", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
Globals.register( "testScript" );
|
||||
@ -792,8 +790,40 @@ QUnit[ "content" in document.createElement( "template" ) ? "test" : "skip" ](
|
||||
|
||||
assert.strictEqual( window.testScript, true, "script in template isn't executed" );
|
||||
assert.strictEqual( window.testImgOnload, true, "onload of image in template isn't executed" );
|
||||
}
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit.test( "contents() for <object />", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var svgObject = jQuery( "<object id='svg-object' data='" + baseURL + "1x1.svg'></object>" );
|
||||
var done = assert.async();
|
||||
|
||||
svgObject.on( "load", function() {
|
||||
var contents = jQuery( "#svg-object" ).contents();
|
||||
assert.equal( contents.length, 1, "Check object contents" );
|
||||
assert.equal( contents.find( "svg" ).length, 1, "Find svg within object" );
|
||||
done();
|
||||
} );
|
||||
|
||||
jQuery( "#qunit-fixture" ).append( svgObject );
|
||||
} );
|
||||
|
||||
QUnit.test( "contents() for <frame />", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var iframe = jQuery( "<iframe id='frame-contents' src='" + baseURL + "frame.html'></iframe>" );
|
||||
var done = assert.async();
|
||||
|
||||
iframe.on( "load", function() {
|
||||
var container = jQuery( "#frame-contents" ).contents();
|
||||
var contents = container.find( "#test-frame" ).contents();
|
||||
assert.equal( contents.length, 1, "Check frame contents" );
|
||||
assert.equal( contents.find( "body" ).length, 1, "Find body within frame" );
|
||||
done();
|
||||
} );
|
||||
|
||||
jQuery( "#qunit-fixture" ).append( iframe );
|
||||
} );
|
||||
|
||||
QUnit.test( "sort direction", function( assert ) {
|
||||
assert.expect( 12 );
|
||||
|
Loading…
Reference in New Issue
Block a user