legend: [ 1, "<fieldset>" ],
area: [ 1, "<map>" ],
param: [ 1, "<object>" ],
- thead: [ 1, "<table>" ],
+ thead: [ 1, "<table>" ],
tr: [ 2, "<table><tbody>" ],
col: [ 2, "<table><tbody></tbody><colgroup>", "</table>" ],
td: [ 3, "<table><tbody><tr>" ],
});
}
- if ( this[0] ) {
- doc = this[0].ownerDocument;
- fragment = jQuery.buildFragment( args, doc, false, this );
+ if ( l ) {
+ fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this );
first = fragment.firstChild;
if ( fragment.childNodes.length === 1 ) {
},
buildFragment: function( elems, context, scripts, selection ) {
- var elem, j, tmp, tag, wrap, tbody,
- nodes = [],
- i = 0,
+ var contains, elem, tag, tmp, wrap, tbody, j,
l = elems.length,
- fragment = context.createDocumentFragment(),
- safe = context === document && safeFragment;
- // Ensure that context is a document
- if ( !context || typeof context.createDocumentFragment === "undefined" ) {
- context = document;
- }
+ // Ensure a safe fragment
+ safe = createSafeFragment( context ),
+
+ nodes = [],
+ i = 0;
for ( ; i < l; i++ ) {
elem = elems[ i ];
+
if ( elem || elem === 0 ) {
+
// Add nodes directly
if ( jQuery.type( elem ) === "object" ) {
jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
// Convert html into DOM nodes
} else {
- // Ensure a safe container
- safe = safe || createSafeFragment( context );
tmp = tmp || safe.appendChild( context.createElement("div") );
// Deserialize a standard representation
}
}
- // Fix #11356: Clear elements from safeFragment
+ // Fix #11356: Clear elements from fragment
if ( tmp ) {
safe.removeChild( tmp );
}
i = 0;
while ( (elem = nodes[ 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 );
+ // that element, do not do anything
+ if ( selection && jQuery.inArray( elem, selection ) !== -1 ) {
+ continue;
}
- tmp = getAll( elem, "script" );
+
+ contains = jQuery.contains( elem.ownerDocument, elem );
+
+ // Append to fragment
+ tmp = getAll( safe.appendChild( elem ), "script" );
// Preserve script evaluation history
- if ( safe ) {
+ if ( contains ) {
setGlobalEval( tmp );
}
}
}
- elem = tmp = safe = null;
+ tmp = null;
- return fragment;
+ return safe;
},
cleanData: function( elems, /* internal */ acceptData ) {
var testAppend = function( valueObj ) {
- expect( 60 );
+ expect( 78 );
testAppendForObject( valueObj, false );
testAppendForObject( valueObj, true );
var defaultText, result, message, iframe, iframeDoc, j, d,
- $input, $radioChecked, $radioUnchecked, $radioParent;
+ $input, $radioChecked, $radioUnchecked, $radioParent, $map, $table;
defaultText = "Try them out:";
result = jQuery("#first").append( valueObj("<b>buga</b>") );
jQuery("<fieldset/>").appendTo("#form").append( valueObj("<legend id='legend'>test</legend>") );
t( "Append legend", "#legend", [ "legend" ] );
+ $map = jQuery("<map/>").append( valueObj("<area id='map01' shape='rect' coords='50,50,150,150' href='http://www.jquery.com/' alt='jQuery'>") );
+
+ equal( $map[ 0 ].childNodes.length, 1, "The area was inserted." );
+ equal( $map[ 0 ].firstChild.nodeName.toLowerCase(), "area", "The area was inserted." );
+
jQuery("#select1").append( valueObj("<OPTION>Test</OPTION>") );
equal( jQuery("#select1 option:last").text(), "Test", "Appending OPTION (all caps)" );
- jQuery("#table").append( valueObj("<colgroup></colgroup>") );
- equal( jQuery("#table colgroup").length, 1, "Append colgroup" );
+ jQuery("#select1").append( valueObj("<optgroup label='optgroup'><option>optgroup</option></optgroup>") );
+ equal( jQuery("#select1 optgroup").attr("label"), "optgroup", "Label attribute in newly inserted optgroup is correct" );
+ equal( jQuery("#select1 option:last").text(), "optgroup", "Appending optgroup" );
+
+ $table = jQuery("#table").empty();
+
+ jQuery.each( "thead tbody tfoot colgroup caption tr th td".split(" "), function( i, name ) {
+ $table.append( valueObj( "<" + name + "/>" ) );
+ ok( $table.find( name ).length >= 1, "Append " + name );
+ ok( jQuery.parseHTML( "<" + name + "/>" ).length, name + " wrapped correctly" );
+ });
jQuery("#table colgroup").append( valueObj("<col/>") );
equal( jQuery("#table colgroup col").length, 1, "Append col" );
- jQuery("#table").append( valueObj("<caption></caption>") );
- equal( jQuery("#table caption").length, 1, "Append caption" );
-
jQuery("#form")
.append( valueObj("<select id='appendSelect1'></select>") )
.append( valueObj("<select id='appendSelect2'><option>Test</option></select>") );
});
test( "Index for function argument should be received (#13094)", 2, function() {
- var i = 0;
+ var i = 0;
+
+ jQuery("<div/><div/>").before(function( index ) {
+ equal( index, i++, "Index should be correct" );
+ });
+
+});
+
+test( "Make sure jQuery.fn.remove can work on elements in documentFragment", 1, function() {
+ var fragment = document.createDocumentFragment(),
+ div = fragment.appendChild( document.createElement("div") );
+
+ jQuery( div ).remove();
- jQuery("<div/><div/>").before(function( index ) {
- equal( index, i++, "Index should be correct" );
- });
+ equal( fragment.childNodes.length, 0, "div element was removed from documentFragment" );
});