MCPcopy Create free account
hub / github.com/components/jquery / buildFragment

Function buildFragment

jquery.js:4391–4474  ·  view source on GitHub ↗
( elems, context, scripts, selection, ignored )

Source from the content-addressed store, hash-verified

4389var rhtml = /<|&#?\w+;/;
4390
4391function buildFragment( elems, context, scripts, selection, ignored ) {
4392 var elem, tmp, tag, wrap, attached, j,
4393 fragment = context.createDocumentFragment(),
4394 nodes = [],
4395 i = 0,
4396 l = elems.length;
4397
4398 for ( ; i < l; i++ ) {
4399 elem = elems[ i ];
4400
4401 if ( elem || elem === 0 ) {
4402
4403 // Add nodes directly
4404 if ( toType( elem ) === "object" && ( elem.nodeType || isArrayLike( elem ) ) ) {
4405 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
4406
4407 // Convert non-html into a text node
4408 } else if ( !rhtml.test( elem ) ) {
4409 nodes.push( context.createTextNode( elem ) );
4410
4411 // Convert html into DOM nodes
4412 } else {
4413 tmp = tmp || fragment.appendChild( context.createElement( "div" ) );
4414
4415 // Deserialize a standard representation
4416 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
4417 wrap = wrapMap[ tag ] || arr;
4418
4419 // Create wrappers & descend into them.
4420 j = wrap.length;
4421 while ( --j > -1 ) {
4422 tmp = tmp.appendChild( context.createElement( wrap[ j ] ) );
4423 }
4424
4425 tmp.innerHTML = jQuery.htmlPrefilter( elem );
4426
4427 jQuery.merge( nodes, tmp.childNodes );
4428
4429 // Remember the top-level container
4430 tmp = fragment.firstChild;
4431
4432 // Ensure the created nodes are orphaned (trac-12392)
4433 tmp.textContent = "";
4434 }
4435 }
4436 }
4437
4438 // Remove wrapper from fragment
4439 fragment.textContent = "";
4440
4441 i = 0;
4442 while ( ( elem = nodes[ i++ ] ) ) {
4443
4444 // Skip elements already in the context collection (trac-4087)
4445 if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
4446 if ( ignored ) {
4447 ignored.push( elem );
4448 }

Callers 2

domManipFunction · 0.70
jquery.jsFile · 0.70

Calls 5

toTypeFunction · 0.70
isArrayLikeFunction · 0.70
isAttachedFunction · 0.70
getAllFunction · 0.70
setGlobalEvalFunction · 0.70

Tested by

no test coverage detected