( collection, args, callback, ignored )
| 4912 | } |
| 4913 | |
| 4914 | function domManip( collection, args, callback, ignored ) { |
| 4915 | |
| 4916 | // Flatten any nested arrays |
| 4917 | args = flat( args ); |
| 4918 | |
| 4919 | var fragment, first, scripts, hasScripts, node, doc, |
| 4920 | i = 0, |
| 4921 | l = collection.length, |
| 4922 | iNoClone = l - 1, |
| 4923 | value = args[ 0 ], |
| 4924 | valueIsFunction = typeof value === "function"; |
| 4925 | |
| 4926 | if ( valueIsFunction ) { |
| 4927 | return collection.each( function( index ) { |
| 4928 | var self = collection.eq( index ); |
| 4929 | args[ 0 ] = value.call( this, index, self.html() ); |
| 4930 | domManip( self, args, callback, ignored ); |
| 4931 | } ); |
| 4932 | } |
| 4933 | |
| 4934 | if ( l ) { |
| 4935 | fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored ); |
| 4936 | first = fragment.firstChild; |
| 4937 | |
| 4938 | if ( fragment.childNodes.length === 1 ) { |
| 4939 | fragment = first; |
| 4940 | } |
| 4941 | |
| 4942 | // Require either new content or an interest in ignored elements to invoke the callback |
| 4943 | if ( first || ignored ) { |
| 4944 | scripts = jQuery.map( getAll( fragment, "script" ), disableScript ); |
| 4945 | hasScripts = scripts.length; |
| 4946 | |
| 4947 | // Use the original fragment for the last item |
| 4948 | // instead of the first because it can end up |
| 4949 | // being emptied incorrectly in certain situations (trac-8070). |
| 4950 | for ( ; i < l; i++ ) { |
| 4951 | node = fragment; |
| 4952 | |
| 4953 | if ( i !== iNoClone ) { |
| 4954 | node = jQuery.clone( node, true, true ); |
| 4955 | |
| 4956 | // Keep references to cloned scripts for later restoration |
| 4957 | if ( hasScripts ) { |
| 4958 | jQuery.merge( scripts, getAll( node, "script" ) ); |
| 4959 | } |
| 4960 | } |
| 4961 | |
| 4962 | callback.call( collection[ i ], node, i ); |
| 4963 | } |
| 4964 | |
| 4965 | if ( hasScripts ) { |
| 4966 | doc = scripts[ scripts.length - 1 ].ownerDocument; |
| 4967 | |
| 4968 | // Re-enable scripts |
| 4969 | jQuery.map( scripts, restoreScript ); |
| 4970 | |
| 4971 | // Evaluate executable scripts on first document insertion |
no test coverage detected