Skip to content

Commit

Permalink
Fix #13094. Pass index to .before(fn) fn as documented. Close gh-1093.
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog authored and dmethvin committed Dec 21, 2012
1 parent 96a349e commit 5afc93c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/manipulation.js
Expand Up @@ -286,16 +286,17 @@ jQuery.fn.extend({
var fragment, first, scripts, hasScripts, node, doc, var fragment, first, scripts, hasScripts, node, doc,
i = 0, i = 0,
l = this.length, l = this.length,
set = this,
iNoClone = l - 1, iNoClone = l - 1,
value = args[0], value = args[0],
isFunction = jQuery.isFunction( value ); isFunction = jQuery.isFunction( value );


// We can't cloneNode fragments that contain checked, in WebKit // We can't cloneNode fragments that contain checked, in WebKit
if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) { if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) {
return this.each(function() { return this.each(function( index ) {
var self = jQuery( this ); var self = set.eq( index );
if ( isFunction ) { if ( isFunction ) {
args[0] = value.call( this, i, table ? self.html() : undefined ); args[0] = value.call( this, index, table ? self.html() : undefined );
} }
self.domManip( args, table, callback ); self.domManip( args, table, callback );
}); });
Expand Down
8 changes: 8 additions & 0 deletions test/unit/manipulation.js
Expand Up @@ -2238,3 +2238,11 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e
jQuery("#test4087-multiple").remove(); jQuery("#test4087-multiple").remove();
}); });
}); });

test( "Index for function argument should be received (#13094)", 2, function() {
var i = 0;

jQuery("<div/><div/>").before(function( index ) {
equal( index, i++, "Index should be correct" );
});
});

0 comments on commit 5afc93c

Please sign in to comment.