MCPcopy
hub / github.com/jquery/jquery / domManip

Function domManip

dist-module/jquery.module.js:4477–4560  ·  view source on GitHub ↗
( collection, args, callback, ignored )

Source from the content-addressed store, hash-verified

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

Callers 1

jQueryFactoryFunction · 0.70

Calls 3

buildFragmentFunction · 0.70
getAllFunction · 0.70
DOMEvalFunction · 0.70

Tested by

no test coverage detected