Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.9] Fixes #9960, Append function not working for parent nodes that are nodeType === 9 #924

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,19 @@ jQuery.fn.extend({

append: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 ) {
// you can only append to a XMLDocument node if it's empty, otherwise you'll receive an exception
// this happens usually from replaceWith
if ( this.nodeType === 1 || this.nodeType === 11 || ( this.nodeType === 9 && !this.documentElement ) ) {
this.appendChild( elem );
}
});
},

prepend: function() {
return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 ) {
// you can only prepend to a XMLDocument node if it's empty, otherwise you'll receive an exception
// this happens usually from replaceWith
if ( this.nodeType === 1 || this.nodeType === 11 || ( this.nodeType === 9 && !this.documentElement ) ) {
this.insertBefore( elem, this.firstChild );
}
});
Expand Down
24 changes: 24 additions & 0 deletions test/unit/manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,30 @@ test("append(Function) with incoming value", function() {
QUnit.reset();
});

test("manipulation functions on XMLDocument nodes, see #9960", function () {
expect( 3 );

var xml1 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state x='100' y='100' initial='actions' id='provisioning1'></state><state x='100' y='100' id='error'></state><state x='100' y='100' id='finished' final='true'></state></scxml>"),
xml2 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning2'></state></scxml>"),
xml3 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning3'></state></scxml>"),
xml4 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning4'></state></scxml>"),
xml5 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning5'></state></scxml>"),
xml6 = jQuery.parseXML("<scxml xmlns='http://www.w3.org/2005/07/scxml' version='1.0'><state id='provisioning6'></state></scxml>"),
scxml1 = jQuery( ":first", xml1 ),
scxml2 = jQuery( ":first", xml2 ),
scxml4 = jQuery( ":first", xml4 ),
scxml6 = jQuery( ":first", xml6 );

scxml1.replaceWith( scxml2 );
equal( jQuery( "state[id='provisioning2']", xml1 ).length, 1, "ReplaceWith not working on document nodes." );

// append and prepend only work with empty, detached XMLDocuments, (this is how replaceWith works!)
jQuery( xml3 ).empty().append( scxml4.detach() );
equal( jQuery( "state[id='provisioning4']", xml3 ).length, 1, "Append not working on document nodes." );
jQuery( xml5 ).empty().prepend( scxml6.detach() );
equal( jQuery( "state[id='provisioning6']", xml5 ).length, 1, "Prepend not working on document nodes." );
});

test("append the same fragment with events (Bug #6997, 5566)", function () {
var doExtra = !jQuery.support.noCloneEvent && document["fireEvent"];
expect(2 + (doExtra ? 1 : 0));
Expand Down