mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "Manipulation: make wrapAll funarg execute only once"
This reverts commit 3dcee02160
.
This commit is contained in:
parent
c463327a5d
commit
04d6895b7b
18
src/wrap.js
18
src/wrap.js
@ -7,18 +7,18 @@ define( [
|
|||||||
|
|
||||||
jQuery.fn.extend( {
|
jQuery.fn.extend( {
|
||||||
wrapAll: function( html ) {
|
wrapAll: function( html ) {
|
||||||
var wrap;
|
if ( jQuery.isFunction( html ) ) {
|
||||||
|
return this.each(function(i) {
|
||||||
if ( this[ 0 ] ) {
|
jQuery(this).wrapAll( html.call(this, i) );
|
||||||
if ( jQuery.isFunction( html ) ) {
|
});
|
||||||
html = html.call( this[ 0 ] );
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( this[0] ) {
|
||||||
// The elements to wrap the target around
|
// The elements to wrap the target around
|
||||||
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
|
var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
|
||||||
|
|
||||||
if ( this[ 0 ].parentNode ) {
|
if ( this[0].parentNode ) {
|
||||||
wrap.insertBefore( this[ 0 ] );
|
wrap.insertBefore( this[0] );
|
||||||
}
|
}
|
||||||
|
|
||||||
wrap.map( function() {
|
wrap.map( function() {
|
||||||
|
@ -212,106 +212,6 @@ QUnit.test( "wrapAll(String)", function( assert ) {
|
|||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "wrapAll(Function)", function( assert ) {
|
|
||||||
assert.expect( 5 );
|
|
||||||
|
|
||||||
var prev = jQuery( "#firstp" )[ 0 ].previousSibling,
|
|
||||||
p = jQuery( "#firstp,#first" )[ 0 ].parentNode,
|
|
||||||
result = jQuery( "#firstp,#first" ).wrapAll( function() {
|
|
||||||
return "<div class='red'><div class='tmp'></div></div>";
|
|
||||||
} );
|
|
||||||
|
|
||||||
assert.equal(
|
|
||||||
result.parent().length, 1, "Check for wrapping of on-the-fly html"
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent"
|
|
||||||
);
|
|
||||||
assert.strictEqual(
|
|
||||||
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
||||||
);
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "wrapAll(Function) check execution characteristics", function( assert ) {
|
|
||||||
assert.expect( 3 );
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
jQuery( "non-existent" ).wrapAll( function() {
|
|
||||||
i++;
|
|
||||||
return "";
|
|
||||||
} );
|
|
||||||
|
|
||||||
assert.ok(
|
|
||||||
!i, "should not execute function argument if target element does not exist"
|
|
||||||
);
|
|
||||||
|
|
||||||
jQuery( "#firstp" ).wrapAll( function( index ) {
|
|
||||||
assert.strictEqual(
|
|
||||||
this, jQuery( "#firstp" )[ 0 ], "context must be the first found element"
|
|
||||||
);
|
|
||||||
assert.strictEqual(
|
|
||||||
index, undefined, "index argument should not be included in function execution"
|
|
||||||
);
|
|
||||||
} );
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "wrapAll(Function)", function( assert ) {
|
|
||||||
assert.expect( 5 );
|
|
||||||
|
|
||||||
var prev = jQuery( "#firstp" )[ 0 ].previousSibling,
|
|
||||||
p = jQuery( "#firstp,#first" )[ 0 ].parentNode,
|
|
||||||
result = jQuery( "#firstp,#first" ).wrapAll( function() {
|
|
||||||
return "<div class='red'><div class='tmp'></div></div>";
|
|
||||||
} );
|
|
||||||
|
|
||||||
assert.equal(
|
|
||||||
result.parent().length, 1, "Check for wrapping of on-the-fly html"
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
jQuery( "#first" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
jQuery( "#firstp" ).parent().parent().is( ".red" ), "Check if wrapper has class 'red'"
|
|
||||||
);
|
|
||||||
assert.ok(
|
|
||||||
jQuery( "#first" ).parent().parent().parent().is( p ), "Correct Parent"
|
|
||||||
);
|
|
||||||
assert.strictEqual(
|
|
||||||
jQuery( "#first" ).parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling"
|
|
||||||
);
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "wrapAll(Function) check execution characteristics", function( assert ) {
|
|
||||||
assert.expect( 3 );
|
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
jQuery( "non-existent" ).wrapAll( function() {
|
|
||||||
i++;
|
|
||||||
return "";
|
|
||||||
} );
|
|
||||||
|
|
||||||
assert.ok(
|
|
||||||
!i, "should not execute function argument if target element does not exist"
|
|
||||||
);
|
|
||||||
|
|
||||||
jQuery( "#firstp" ).wrapAll( function( index ) {
|
|
||||||
assert.strictEqual(
|
|
||||||
this, jQuery( "#firstp" )[ 0 ], "context must be the first found element"
|
|
||||||
);
|
|
||||||
assert.strictEqual(
|
|
||||||
index, undefined, "index argument should not be included in function execution"
|
|
||||||
);
|
|
||||||
} );
|
|
||||||
} );
|
|
||||||
|
|
||||||
QUnit.test( "wrapAll(Element)", function( assert ) {
|
QUnit.test( "wrapAll(Element)", function( assert ) {
|
||||||
|
|
||||||
assert.expect( 3 );
|
assert.expect( 3 );
|
||||||
|
Loading…
Reference in New Issue
Block a user