From 380663ee3bc343b4044a5bc5ed12ffdcbdea76a6 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Thu, 6 Mar 2014 16:53:19 -0500 Subject: [PATCH] Correct arguments for 'replaceWith' callback Ensure that when `replaceWith` is invoked with a function, that function is invoked with both the iteration index *and* element. --- lib/api/manipulation.js | 2 +- test/api.manipulation.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/api/manipulation.js b/lib/api/manipulation.js index dfd3237bc5..4ae89db05f 100644 --- a/lib/api/manipulation.js +++ b/lib/api/manipulation.js @@ -165,7 +165,7 @@ var replaceWith = exports.replaceWith = function(content) { index; if (_.isFunction(content)) { - dom = makeDomArray(content.call(el, i)); + dom = makeDomArray(content.call(el, i, el)); } // In the case that `dom` contains nodes that already exist in other diff --git a/test/api.manipulation.js b/test/api.manipulation.js index 7d84b6444c..1e5cce9fc5 100644 --- a/test/api.manipulation.js +++ b/test/api.manipulation.js @@ -595,7 +595,11 @@ describe('$(...)', function() { return '
  • '; }); - expect(args).to.eql([[0], [1], [2]]); + expect(args).to.eql([ + [0, origChildren[0]], + [1, origChildren[1]], + [2, origChildren[2]] + ]); expect(thisValues).to.eql([ origChildren[0], origChildren[1],