1 import { jQuery } from "../core.js";
2 import { toType } from "../core/toType.js";
3 import { isAttached } from "../core/isAttached.js";
4 import { arr } from "../var/arr.js";
5 import { rtagName } from "./var/rtagName.js";
6 import { rscriptType } from "./var/rscriptType.js";
7 import { wrapMap } from "./wrapMap.js";
8 import { getAll } from "./getAll.js";
9 import { setGlobalEval } from "./setGlobalEval.js";
10 import { isArrayLike } from "../core/isArrayLike.js";
12 var rhtml = /<|&#?\w+;/;
14 export function buildFragment( elems, context, scripts, selection, ignored ) {
15 var elem, tmp, tag, wrap, attached, j,
16 fragment = context.createDocumentFragment(),
21 for ( ; i < l; i++ ) {
24 if ( elem || elem === 0 ) {
27 if ( toType( elem ) === "object" && ( elem.nodeType || isArrayLike( elem ) ) ) {
28 jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
30 // Convert non-html into a text node
31 } else if ( !rhtml.test( elem ) ) {
32 nodes.push( context.createTextNode( elem ) );
34 // Convert html into DOM nodes
36 tmp = tmp || fragment.appendChild( context.createElement( "div" ) );
38 // Deserialize a standard representation
39 tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
40 wrap = wrapMap[ tag ] || arr;
42 // Create wrappers & descend into them.
45 tmp = tmp.appendChild( context.createElement( wrap[ j ] ) );
48 tmp.innerHTML = jQuery.htmlPrefilter( elem );
50 jQuery.merge( nodes, tmp.childNodes );
52 // Remember the top-level container
53 tmp = fragment.firstChild;
55 // Ensure the created nodes are orphaned (trac-12392)
61 // Remove wrapper from fragment
62 fragment.textContent = "";
65 while ( ( elem = nodes[ i++ ] ) ) {
67 // Skip elements already in the context collection (trac-4087)
68 if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
75 attached = isAttached( elem );
78 tmp = getAll( fragment.appendChild( elem ), "script" );
80 // Preserve script evaluation history
85 // Capture executables
88 while ( ( elem = tmp[ j++ ] ) ) {
89 if ( rscriptType.test( elem.type || "" ) ) {