Skip to content

Commit 74a132d

Browse files
committed
Fixed jquery#1264. If you read the bug there were many proposed changes. As it turned out most of them had already been implemented. The last ones necessary were in .domManip() with when a <table> was 'this' and for .text(). Adding these last changes seems to make dom and text manipulation in IE frames possible. Unit test cases were added as well.
In addition "submit.gif" was removed from the test suite index.html since it didn't exist.
1 parent c424e79 commit 74a132d

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

src/core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ jQuery.fn = jQuery.prototype = {
202202

203203
text: function( text ) {
204204
if ( typeof text != "object" && text != null )
205-
return this.empty().append( document.createTextNode( text ) );
205+
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
206206

207207
var ret = "";
208208

@@ -468,7 +468,7 @@ jQuery.fn = jQuery.prototype = {
468468
var obj = this;
469469

470470
if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
471-
obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
471+
obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
472472

473473
var scripts = jQuery( [] );
474474

test/data/iframe.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>iframe</title>
4+
</head>
5+
<body>
6+
<div><span>span text</span></div>
7+
</body>
8+
</html>

test/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ <h2 id="userAgent"></h2>
2121

2222
<!-- Test HTML -->
2323
<div id="nothiddendiv" style="height:1px;background:white;"></div>
24+
<!-- this iframe is outside the #main so it won't reload constantly wasting time, but it means the tests must be "safe" and clean up after themselves -->
25+
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
2426
<dl id="dl" style="display:none;">
2527
<div id="main" style="display: none;">
2628
<p id="firstp">See <a id="simon1" href="http://simon.incutio.com/archive/2003/03/25/#getElementsBySelector" rel="bookmark">this blog entry</a> for more information.</p>
@@ -151,7 +153,7 @@ <h2 id="userAgent"></h2>
151153
</select>
152154
<input type="submit" name="sub1" value="NO" />
153155
<input type="submit" name="sub2" value="NO" />
154-
<input type="image" name="sub3" value="NO" src="submit.gif" />
156+
<input type="image" name="sub3" value="NO" />
155157
<button name="sub4" type="submit" value="NO">NO</button>
156158
<input name="D1" type="text" value="NO" disabled="disabled" />
157159
<input type="checkbox" checked="checked" disabled="disabled" name="D2" value="NO" />

test/unit/core.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
551551
reset();
552552
var pass = true;
553553
try {
554-
$( $("iframe")[0].contentWindow.document.body ).append("<div>test</div>");
554+
$( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
555555
} catch(e) {
556556
pass = false;
557557
}
@@ -1188,9 +1188,28 @@ test("map()", function() {
11881188
});
11891189

11901190
test("contents()", function() {
1191-
expect(2);
1191+
expect(10);
11921192
equals( $("#ap").contents().length, 9, "Check element contents" );
11931193
ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1194-
// Disabled, randomly fails
1195-
//ok( $("#iframe").contents()[0].body, "Check existance of IFrame body" );
1194+
var ibody = $("#loadediframe").contents()[0].body;
1195+
ok( ibody, "Check existance of IFrame body" );
1196+
1197+
equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1198+
1199+
$(ibody).append("<div>init text</div>");
1200+
equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1201+
1202+
equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1203+
1204+
$("div:last", ibody).text("div text");
1205+
equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1206+
1207+
$("div:last", ibody).remove();
1208+
equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1209+
1210+
equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1211+
1212+
$("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1213+
$("table", ibody).remove();
1214+
equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
11961215
});

0 commit comments

Comments
 (0)