Fixed #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.
This commit is contained in:
David Serduke 2007-12-05 00:26:13 +00:00
parent c424e79ccb
commit 74a132d944
4 changed files with 36 additions and 7 deletions

View file

@ -202,7 +202,7 @@ jQuery.fn = jQuery.prototype = {
text: function( text ) {
if ( typeof text != "object" && text != null )
return this.empty().append( document.createTextNode( text ) );
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
var ret = "";
@ -468,7 +468,7 @@ jQuery.fn = jQuery.prototype = {
var obj = this;
if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )
obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") );
obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );
var scripts = jQuery( [] );

8
test/data/iframe.html Normal file
View file

@ -0,0 +1,8 @@
<html>
<head>
<title>iframe</title>
</head>
<body>
<div><span>span text</span></div>
</body>
</html>

View file

@ -21,6 +21,8 @@
<!-- Test HTML -->
<div id="nothiddendiv" style="height:1px;background:white;"></div>
<!-- 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 -->
<iframe id="loadediframe" name="loadediframe" style="display:none;" src="data/iframe.html"></iframe>
<dl id="dl" style="display:none;">
<div id="main" style="display: none;">
<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 @@ Z</textarea>
</select>
<input type="submit" name="sub1" value="NO" />
<input type="submit" name="sub2" value="NO" />
<input type="image" name="sub3" value="NO" src="submit.gif" />
<input type="image" name="sub3" value="NO" />
<button name="sub4" type="submit" value="NO">NO</button>
<input name="D1" type="text" value="NO" disabled="disabled" />
<input type="checkbox" checked="checked" disabled="disabled" name="D2" value="NO" />

View file

@ -551,7 +551,7 @@ test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
reset();
var pass = true;
try {
$( $("iframe")[0].contentWindow.document.body ).append("<div>test</div>");
$( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
} catch(e) {
pass = false;
}
@ -1188,9 +1188,28 @@ test("map()", function() {
});
test("contents()", function() {
expect(2);
expect(10);
equals( $("#ap").contents().length, 9, "Check element contents" );
ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
// Disabled, randomly fails
//ok( $("#iframe").contents()[0].body, "Check existance of IFrame body" );
var ibody = $("#loadediframe").contents()[0].body;
ok( ibody, "Check existance of IFrame body" );
equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
$(ibody).append("<div>init text</div>");
equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
$("div:last", ibody).text("div text");
equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
$("div:last", ibody).remove();
equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
$("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
$("table", ibody).remove();
equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
});