MCPcopy
hub / github.com/jquery/jquery / buildFragment

Function buildFragment

dist-module/jquery.module.js:4377–4460  ·  view source on GitHub ↗
( elems, context, scripts, selection, ignored )

Source from the content-addressed store, hash-verified

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

Callers 2

domManipFunction · 0.70
jQueryFactoryFunction · 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