Skip to content
Permalink
Browse files

Fix #10177. Pass correct index to function-parameter of `.wrap`

  • Loading branch information...
Toby Brain authored and dmethvin committed Nov 6, 2011
1 parent 90c019d commit 47c605f693457412a53c9145cafe55420ab8f236
Showing with 32 additions and 3 deletions.
  1. +4 −2 src/manipulation.js
  2. +28 −1 test/unit/manipulation.js
@@ -117,8 +117,10 @@ jQuery.fn.extend({
},

wrap: function( html ) {
return this.each(function() {
jQuery( this ).wrapAll( html );
var isFunction = jQuery.isFunction( html );

return this.each(function(i) {
jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
});
},

@@ -135,7 +135,34 @@ test("wrap(String|Element)", function() {

test("wrap(Function)", function() {
testWrap(functionReturningObj);
})
});

test("wrap(Function) with index (#10177)", function() {
var expectedIndex = 0,
targets = jQuery("#qunit-fixture p");

expect(targets.length);
targets.wrap(function(i) {
equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
expectedIndex++;

return "<div id='wrap_index_'" + i + "'></div>";
});
});

test("wrap(String) consecutive elements (#10177)", function() {
var targets = jQuery("#qunit-fixture p");

expect(targets.length * 2);
targets.wrap("<div class='wrapper'></div>");

targets.each(function() {
var $this = jQuery(this);

ok( $this.parent().is('.wrapper'), "Check each elements parent is correct (.wrapper)" );
equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
});
});

var testWrapAll = function(val) {
expect(8);

0 comments on commit 47c605f

Please sign in to comment.
You can’t perform that action at this time.