]> source.dussan.org Git - jquery.git/commitdiff
Fix #13094. Pass index to .before(fn) fn as documented. Close gh-1093.
authorOleg <markelog@gmail.com>
Wed, 19 Dec 2012 23:52:08 +0000 (03:52 +0400)
committerDave Methvin <dave.methvin@gmail.com>
Fri, 21 Dec 2012 01:55:30 +0000 (20:55 -0500)
src/manipulation.js
test/unit/manipulation.js

index 0625277087e57e73283e5e4c8904fa3010dc245d..5fec948cb41f8bc34cd94e3a0cfd00eaa4b50e37 100644 (file)
@@ -286,16 +286,17 @@ jQuery.fn.extend({
                var fragment, first, scripts, hasScripts, node, doc,
                        i = 0,
                        l = this.length,
+                       set = this,
                        iNoClone = l - 1,
                        value = args[0],
                        isFunction = jQuery.isFunction( value );
 
                // We can't cloneNode fragments that contain checked, in WebKit
                if ( isFunction || !( l <= 1 || typeof value !== "string" || jQuery.support.checkClone || !rchecked.test( value ) ) ) {
-                       return this.each(function() {
-                               var self = jQuery( this );
+                       return this.each(function( index ) {
+                               var self = set.eq( index );
                                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 );
                        });
index 35beb52673bf1bb98cff484a8c6bf5f8a550da1d..86b26e040c2d54360df69cb156e017776b838ff3 100644 (file)
@@ -2238,3 +2238,11 @@ test( "insertAfter, insertBefore, etc do not work when destination is original e
                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" );
+    });
+});