},
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 );
});
},
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);