MCPcopy Create free account
hub / github.com/components/jquery / domManip

Function domManip

jquery.js:4491–4574  ·  view source on GitHub ↗
( collection, args, callback, ignored )

Source from the content-addressed store, hash-verified

4489}
4490
4491function domManip( collection, args, callback, ignored ) {
4492
4493 // Flatten any nested arrays
4494 args = flat( args );
4495
4496 var fragment, first, scripts, hasScripts, node, doc,
4497 i = 0,
4498 l = collection.length,
4499 iNoClone = l - 1,
4500 value = args[ 0 ],
4501 valueIsFunction = typeof value === "function";
4502
4503 if ( valueIsFunction ) {
4504 return collection.each( function( index ) {
4505 var self = collection.eq( index );
4506 args[ 0 ] = value.call( this, index, self.html() );
4507 domManip( self, args, callback, ignored );
4508 } );
4509 }
4510
4511 if ( l ) {
4512 fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
4513 first = fragment.firstChild;
4514
4515 if ( fragment.childNodes.length === 1 ) {
4516 fragment = first;
4517 }
4518
4519 // Require either new content or an interest in ignored elements to invoke the callback
4520 if ( first || ignored ) {
4521 scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
4522 hasScripts = scripts.length;
4523
4524 // Use the original fragment for the last item
4525 // instead of the first because it can end up
4526 // being emptied incorrectly in certain situations (trac-8070).
4527 for ( ; i < l; i++ ) {
4528 node = fragment;
4529
4530 if ( i !== iNoClone ) {
4531 node = jQuery.clone( node, true, true );
4532
4533 // Keep references to cloned scripts for later restoration
4534 if ( hasScripts ) {
4535 jQuery.merge( scripts, getAll( node, "script" ) );
4536 }
4537 }
4538
4539 callback.call( collection[ i ], node, i );
4540 }
4541
4542 if ( hasScripts ) {
4543 doc = scripts[ scripts.length - 1 ].ownerDocument;
4544
4545 // Re-enable scripts
4546 jQuery.map( scripts, restoreScript );
4547
4548 // Evaluate executable scripts on first document insertion

Callers 1

jquery.jsFile · 0.70

Calls 3

buildFragmentFunction · 0.70
getAllFunction · 0.70
DOMEvalFunction · 0.70

Tested by

no test coverage detected