diff --git a/Gruntfile.js b/Gruntfile.js index fbf9b56717..ed2bd77537 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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 } diff --git a/src/traversing.js b/src/traversing.js index 64c7252b9f..426d5b6ea3 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -145,18 +145,18 @@ jQuery.each( { return siblings( elem.firstChild ); }, contents: function( elem ) { - if ( nodeName( elem, "iframe" ) ) { - return elem.contentDocument; - } - - // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only - // Treat the template element as a regular one in browsers that - // don't support it. - if ( nodeName( elem, "template" ) ) { - elem = elem.content || elem; - } - - return jQuery.merge( [], elem.childNodes ); + if ( typeof elem.contentDocument !== "undefined" ) { + return elem.contentDocument; + } + + // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only + // Treat the template element as a regular one in browsers that + // don't support it. + if ( nodeName( elem, "template" ) ) { + elem = elem.content || elem; + } + + return jQuery.merge( [], elem.childNodes ); } }, function( name, fn ) { jQuery.fn[ name ] = function( until, selector ) { diff --git a/test/data/1x1.svg b/test/data/1x1.svg new file mode 100644 index 0000000000..643eeb456a --- /dev/null +++ b/test/data/1x1.svg @@ -0,0 +1,6 @@ + + + diff --git a/test/data/frame.html b/test/data/frame.html new file mode 100644 index 0000000000..98107be1d8 --- /dev/null +++ b/test/data/frame.html @@ -0,0 +1,9 @@ + +
+
" +
- ""
- );
+ jQuery( "#qunit-fixture" ).append(
+ "" +
+ " " +
+ "
" +
+ ""
+ );
- var content = jQuery( "#template" ).contents();
+ var content = jQuery( "#template" ).contents();
- assert.strictEqual( window.testScript, true, "script in template isn't executed" );
- assert.strictEqual( window.testImgOnload, true, "onload of image in template isn't executed" );
- }
-);
+ 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 ", function( assert ) {
+ assert.expect( 2 );
+
+ var svgObject = jQuery( "" );
+ 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 ", function( assert ) {
+ assert.expect( 2 );
+
+ var iframe = jQuery( "" );
+ 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 );
" +
- ""
- );
+ jQuery( "#qunit-fixture" ).append(
+ "" +
+ " " +
+ "
" +
+ ""
+ );
- var content = jQuery( "#template" ).contents();
+ var content = jQuery( "#template" ).contents();
- assert.strictEqual( window.testScript, true, "script in template isn't executed" );
- assert.strictEqual( window.testImgOnload, true, "onload of image in template isn't executed" );
- }
-);
+ 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 ", function( assert ) {
+ assert.expect( 2 );
+
+ var svgObject = jQuery( "" );
+ 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 ", function( assert ) {
+ assert.expect( 2 );
+
+ var iframe = jQuery( "" );
+ 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 );