Skip to content

Commit

Permalink
Merge pull request madrobby#1053 from altbdoor/master
Browse files Browse the repository at this point in the history
Return contentDocument on iframe contents

Fixes madrobby#821
  • Loading branch information
mislav committed Dec 19, 2014
2 parents fddde41 + 76ab3ce commit f2a4b6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ var Zepto = (function() {
return filtered(this.map(function(){ return children(this) }), selector)
},
contents: function() {
return this.map(function() { return slice.call(this.childNodes) })
return this.map(function() { return this.contentDocument || slice.call(this.childNodes) })
},
siblings: function(selector){
return filtered(this.map(function(i, el){
Expand Down
9 changes: 8 additions & 1 deletion test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ <h1>Zepto Core unit tests</h1>
</ul>

<ul id="contentsTest">1<span>2</span><span id="contentsEmptyTest"></span></ul>

<iframe id="contentsIframeTest" src="fixtures/iframe_document.html"></iframe>

<ul id="siblingsTest">
<ul id="siblingsTest">
<li class="child one"><span class="b"></span><em></em><b></b></li>
<li class="child two"><span class="c"></span><em></em><b></b></li>
<li class="child three"><span class="d"></span><em></em><b></b></li>
Expand Down Expand Up @@ -1248,6 +1250,11 @@ <h1>Zepto Core unit tests</h1>
t.assertLength(2, $contents.filter('span'))
t.assertLength(0, $("#contentsEmptyTest").contents())
},

testIframeContents: function(t){
var el = $("#contentsIframeTest")
t.assertEqual("Hello from iframe!", el.contents().find("b").first().text())
},

testSiblings: function(t){
var el=$("#siblingsTest")
Expand Down

0 comments on commit f2a4b6c

Please sign in to comment.