if ( this[0] ) {
doc = this[0].ownerDocument;
- fragment = doc.createDocumentFragment();
- jQuery.clean( args, doc, fragment, undefined, this );
+ fragment = jQuery.buildFragment( args, doc, false, this );
first = fragment.firstChild;
if ( fragment.childNodes.length === 1 ) {
found;
}
-// Used in clean, fixes the defaultChecked property
+// Used in buildFragment, fixes the defaultChecked property
function fixDefaultChecked( elem ) {
if ( manipulation_rcheckableType.test( elem.type ) ) {
elem.defaultChecked = elem.checked;
return clone;
},
- clean: function( elems, context, fragment, scripts, selection ) {
+ buildFragment: function( elems, context, scripts, selection ) {
var elem, i, j, tmp, tag, wrap, tbody,
ret = [],
+ fragment = context.createDocumentFragment(),
safe = context === document && safeFragment;
// Ensure that context is a document
jQuery.grep( getAll( ret, "input" ), fixDefaultChecked );
}
- if ( fragment ) {
- for ( i = 0; (elem = ret[i]) != null; i++ ) {
- safe = jQuery.contains( elem.ownerDocument, elem );
+ for ( i = 0; (elem = ret[i]) != null; i++ ) {
+ safe = jQuery.contains( elem.ownerDocument, elem );
- // Append to fragment
- // #4087 - If origin and destination elements are the same, and this is
- // that element, do not append to fragment
- if ( !selection || jQuery.inArray( elem, selection ) === -1 ) {
- fragment.appendChild( elem );
- }
- tmp = getAll( elem, "script" );
+ // Append to fragment
+ // #4087 - If origin and destination elements are the same, and this is
+ // that element, do not append to fragment
+ if ( !selection || jQuery.inArray( elem, selection ) === -1 ) {
+ fragment.appendChild( elem );
+ }
+ tmp = getAll( elem, "script" );
- // Preserve script evaluation history
- if ( safe ) {
- setGlobalEval( tmp );
- }
+ // Preserve script evaluation history
+ if ( safe ) {
+ setGlobalEval( tmp );
+ }
- // Capture executables
- if ( scripts ) {
- for ( j = 0; (elem = tmp[j]) != null; j++ ) {
- if ( rscriptType.test( elem.type || "" ) ) {
- scripts.push( elem );
- }
+ // Capture executables
+ if ( scripts ) {
+ for ( j = 0; (elem = tmp[j]) != null; j++ ) {
+ if ( rscriptType.test( elem.type || "" ) ) {
+ scripts.push( elem );
}
}
}
elem = tmp = safe = null;
- return ret;
+ return fragment;
},
cleanData: function( elems, /* internal */ acceptData ) {
});
test("jQuery.parseHTML", function() {
- expect( 13 );
+ expect( 17 );
var html, nodes;
equal( jQuery.parseHTML( "\t<div></div>" )[0].nodeValue, "\t", "Preserve leading whitespace" );
equal( jQuery.parseHTML(" <div/> ")[0].nodeType, 3, "Leading spaces are treated as text nodes (#11290)" );
+
+ html = jQuery.parseHTML( "<div>test div</div>" );
+ equal( html[ 0 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
+ equal( html[ 0 ].innerHTML, "test div", "Content should be preserved" );
+
+ equal( jQuery.parseHTML("<span><span>").length, 1, "Incorrect html-strings should not break anything" );
+ equal( jQuery.parseHTML("<td><td>")[ 1 ].parentNode.nodeType, 11, "parentNode should be documentFragment" );
});
test("jQuery.parseJSON", function(){
equal( aside.length, 1, "HTML5 elements do not collapse their children" );
});
-test( "jQuery.clean, #12392", function() {
-
- expect( 6 );
-
- var elems = jQuery.clean( [ "<div>test div</div>", "<p>test p</p>" ] );
-
- ok( elems[ 0 ].parentNode == null || elems[ 0 ].parentNode.nodeType === 11, "parentNode should be documentFragment or null" );
- ok( elems[ 1 ].parentNode == null || elems[ 1 ].parentNode.nodeType === 11, "parentNode should be documentFragment or null" );
-
- equal( elems[ 0 ].innerHTML, "test div", "Content should be preserved" );
- equal( elems[ 1 ].innerHTML, "test p", "Content should be preserved" );
-
- equal( jQuery.clean([ "<span><span>" ]).length, 1, "Incorrect html-strings should not break anything" );
-
- elems = jQuery.clean([ "<td><td>" ]);
- ok( elems[ 1 ].parentNode == null || elems[ 1 ].parentNode.nodeType === 11, "parentNode should be documentFragment or null" );
-});
-
if ( jQuery.css ) {
test( "HTML5 Elements inherit styles from style rules (Bug #10501)", function() {