MCPcopy Index your code
hub / github.com/jquery/jquery / buildFragment

Function buildFragment

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

Source from the content-addressed store, hash-verified

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

Callers 2

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