Commit 2b0e7204 authored by Sai Wong's avatar Sai Wong Committed by Dave Methvin

Fix #12048. Set attributes for XML fragments. Close gh-965.

parent 144b8bfe
...@@ -523,7 +523,7 @@ if ( !getSetAttribute ) { ...@@ -523,7 +523,7 @@ if ( !getSetAttribute ) {
// Set the existing or create a new attribute node // Set the existing or create a new attribute node
var ret = elem.getAttributeNode( name ); var ret = elem.getAttributeNode( name );
if ( !ret ) { if ( !ret ) {
ret = document.createAttribute( name ); ret = elem.ownerDocument.createAttribute( name );
elem.setAttributeNode( ret ); elem.setAttributeNode( ret );
} }
return ( ret.value = value + "" ); return ( ret.value = value + "" );
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
"testIframe": true, "testIframe": true,
"testIframeWithCallback": true, "testIframeWithCallback": true,
"createDashboardXML": true, "createDashboardXML": true,
"createXMLFragment": true,
"moduleTeardown": true, "moduleTeardown": true,
"testFoo": true, "testFoo": true,
"foobar": true, "foobar": true,
......
...@@ -102,6 +102,21 @@ var createWithFriesXML = function() { ...@@ -102,6 +102,21 @@ var createWithFriesXML = function() {
return jQuery.parseXML(string); return jQuery.parseXML(string);
}; };
var createXMLFragment = function() {
var xml, frag;
if ( window.ActiveXObject ) {
xml = new ActiveXObject("msxml2.domdocument");
} else {
xml = document.implementation.createDocument( "", "", null );
}
if ( xml ) {
frag = xml.createElement("data");
}
return frag;
};
var fireNative; var fireNative;
if ( document.createEvent ) { if ( document.createEvent ) {
fireNative = function( node, type ) { fireNative = function( node, type ) {
......
...@@ -522,6 +522,17 @@ test( "attr(String, Object) - Loaded via XML document", function() { ...@@ -522,6 +522,17 @@ test( "attr(String, Object) - Loaded via XML document", function() {
equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" ); equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" );
}); });
test( "attr(String, Object) - Loaded via XML fragment", function() {
expect( 2 );
var frag = createXMLFragment(),
$frag = jQuery( frag );
$frag.attr( "test", "some value" );
equal( $frag.attr("test"), "some value", "set attribute" );
$frag.attr( "test", null );
equal( $frag.attr("test"), undefined, "remove attribute" );
});
test( "attr('tabindex')", function() { test( "attr('tabindex')", function() {
expect( 8 ); expect( 8 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment