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

Function buildFragment

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

Source from the content-addressed store, hash-verified

4812var rhtml = /<|&#?\w+;/;
4813
4814function buildFragment( elems, context, scripts, selection, ignored ) {
4815 var elem, tmp, tag, wrap, attached, j,
4816 fragment = context.createDocumentFragment(),
4817 nodes = [],
4818 i = 0,
4819 l = elems.length;
4820
4821 for ( ; i < l; i++ ) {
4822 elem = elems[ i ];
4823
4824 if ( elem || elem === 0 ) {
4825
4826 // Add nodes directly
4827 if ( toType( elem ) === "object" && ( elem.nodeType || isArrayLike( elem ) ) ) {
4828 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
4829
4830 // Convert non-html into a text node
4831 } else if ( !rhtml.test( elem ) ) {
4832 nodes.push( context.createTextNode( elem ) );
4833
4834 // Convert html into DOM nodes
4835 } else {
4836 tmp = tmp || fragment.appendChild( context.createElement( "div" ) );
4837
4838 // Deserialize a standard representation
4839 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
4840 wrap = wrapMap[ tag ] || arr;
4841
4842 // Create wrappers & descend into them.
4843 j = wrap.length;
4844 while ( --j > -1 ) {
4845 tmp = tmp.appendChild( context.createElement( wrap[ j ] ) );
4846 }
4847
4848 tmp.innerHTML = jQuery.htmlPrefilter( elem );
4849
4850 jQuery.merge( nodes, tmp.childNodes );
4851
4852 // Remember the top-level container
4853 tmp = fragment.firstChild;
4854
4855 // Ensure the created nodes are orphaned (trac-12392)
4856 tmp.textContent = "";
4857 }
4858 }
4859 }
4860
4861 // Remove wrapper from fragment
4862 fragment.textContent = "";
4863
4864 i = 0;
4865 while ( ( elem = nodes[ i++ ] ) ) {
4866
4867 // Skip elements already in the context collection (trac-4087)
4868 if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
4869 if ( ignored ) {
4870 ignored.push( elem );
4871 }

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