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

Function buildFragment

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

Source from the content-addressed store, hash-verified

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

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