( collection, args, callback, ignored )
| 5209 | } |
| 5210 | |
| 5211 | function domManip( collection, args, callback, ignored ) { |
| 5212 | |
| 5213 | // Flatten any nested arrays |
| 5214 | args = concat.apply( [], args ); |
| 5215 | |
| 5216 | var fragment, first, scripts, hasScripts, node, doc, |
| 5217 | i = 0, |
| 5218 | l = collection.length, |
| 5219 | iNoClone = l - 1, |
| 5220 | value = args[ 0 ], |
| 5221 | isFunction = jQuery.isFunction( value ); |
| 5222 | |
| 5223 | // We can't cloneNode fragments that contain checked, in WebKit |
| 5224 | if ( isFunction || |
| 5225 | ( l > 1 && typeof value === "string" && |
| 5226 | !support.checkClone && rchecked.test( value ) ) ) { |
| 5227 | return collection.each( function( index ) { |
| 5228 | var self = collection.eq( index ); |
| 5229 | if ( isFunction ) { |
| 5230 | args[ 0 ] = value.call( this, index, self.html() ); |
| 5231 | } |
| 5232 | domManip( self, args, callback, ignored ); |
| 5233 | } ); |
| 5234 | } |
| 5235 | |
| 5236 | if ( l ) { |
| 5237 | fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored ); |
| 5238 | first = fragment.firstChild; |
| 5239 | |
| 5240 | if ( fragment.childNodes.length === 1 ) { |
| 5241 | fragment = first; |
| 5242 | } |
| 5243 | |
| 5244 | // Require either new content or an interest in ignored elements to invoke the callback |
| 5245 | if ( first || ignored ) { |
| 5246 | scripts = jQuery.map( getAll( fragment, "script" ), disableScript ); |
| 5247 | hasScripts = scripts.length; |
| 5248 | |
| 5249 | // Use the original fragment for the last item |
| 5250 | // instead of the first because it can end up |
| 5251 | // being emptied incorrectly in certain situations (#8070). |
| 5252 | for ( ; i < l; i++ ) { |
| 5253 | node = fragment; |
| 5254 | |
| 5255 | if ( i !== iNoClone ) { |
| 5256 | node = jQuery.clone( node, true, true ); |
| 5257 | |
| 5258 | // Keep references to cloned scripts for later restoration |
| 5259 | if ( hasScripts ) { |
| 5260 | |
| 5261 | // Support: Android<4.1, PhantomJS<2 |
| 5262 | // push.apply(_, arraylike) throws on ancient WebKit |
| 5263 | jQuery.merge( scripts, getAll( node, "script" ) ); |
| 5264 | } |
| 5265 | } |
| 5266 | |
| 5267 | callback.call( collection[ i ], node, i ); |
| 5268 | } |
no test coverage detected