Skip to content

Commit

Permalink
Fixed a bug in clone where it wouldn't work on an XML node in IE. Als…
Browse files Browse the repository at this point in the history
…o added unit test for it.
  • Loading branch information
davids549 committed Dec 12, 2007
1 parent c6a44c7 commit 279f77e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ jQuery.fn = jQuery.prototype = {
clone: function( events ) { clone: function( events ) {
// Do the clone // Do the clone
var ret = this.map(function(){ var ret = this.map(function(){
if ( jQuery.browser.msie ) { if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) {
// IE copies events bound via attachEvent when // IE copies events bound via attachEvent when
// using cloneNode. Calling detachEvent on the // using cloneNode. Calling detachEvent on the
// clone will also remove the events from the orignal // clone will also remove the events from the orignal
Expand Down
12 changes: 11 additions & 1 deletion test/unit/core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -864,14 +864,24 @@ test("find(String)", function() {
}); });


test("clone()", function() { test("clone()", function() {
expect(4); expect(6);
ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' ); ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
var clone = $('#yahoo').clone(); var clone = $('#yahoo').clone();
ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' ); ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' ); ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
// using contents will get comments regular, text, and comment nodes // using contents will get comments regular, text, and comment nodes
var cl = $("#nonnodes").contents().clone(); var cl = $("#nonnodes").contents().clone();
ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" ); ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );

stop();
$.get("data/dashboard.xml", function (xml) {
var root = $(xml.documentElement).clone();
$("tab:first", xml).text("origval");
$("tab:first", root).text("cloneval");
equals($("tab:first", xml).text(), "origval", "Check original XML node was correctly set");
equals($("tab:first", root).text(), "cloneval", "Check cloned XML node was correctly set");
start();
});
}); });


test("is(String)", function() { test("is(String)", function() {
Expand Down

0 comments on commit 279f77e

Please sign in to comment.