From 0ba8e38d0c4ab4a4fb9054e7a713630be9743aff Mon Sep 17 00:00:00 2001 From: Luis Emilio Velasco Sanchez Date: Mon, 14 May 2018 13:36:30 -0400 Subject: [PATCH] Traversing: $.fn.contents() support for object Fixes gh-4045 Closes gh-4046 --- Gruntfile.js | 2 +- src/traversing.js | 20 ++++---- test/data/1x1.svg | 6 +++ test/data/frame.html | 9 ++++ test/unit/traversing.js | 106 ++++++++++++++++++++++++++-------------- 5 files changed, 94 insertions(+), 49 deletions(-) create mode 100644 test/data/1x1.svg create mode 100644 test/data/frame.html diff --git a/Gruntfile.js b/Gruntfile.js index fbf9b5671..ed2bd7753 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 64c7252b9..426d5b6ea 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; - } + 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; - } + // 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 ); + 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 000000000..70b3e7412 --- /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 000000000..98107be1d --- /dev/null +++ b/test/data/frame.html @@ -0,0 +1,9 @@ + + + frame + + + + + + diff --git a/test/unit/traversing.js b/test/unit/traversing.js index dd0554137..9ba66959e 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -744,56 +744,86 @@ QUnit.test( "contents()", function( assert ) { } ); QUnit.test( "contents() for