diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-13 16:41:51 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-11-13 20:04:24 +0300 |
commit | 276282146ad6b847bb7bec2cfaab8efc327e86b8 (patch) | |
tree | c74cfb129e6217d2e2345fff5c9f583dfba9bb93 | |
parent | 3655260866cdcfe42a1117bfb9603144c9e4d829 (diff) | |
download | jquery-276282146ad6b847bb7bec2cfaab8efc327e86b8.tar.gz jquery-276282146ad6b847bb7bec2cfaab8efc327e86b8.zip |
Revert "Manipulation: make wrapAll funarg execute only once"
This reverts commit 359b03cac74d7336676a6992f14b7ccab9b28659.
-rw-r--r-- | src/wrap.js | 9 | ||||
-rw-r--r-- | test/unit/wrap.js | 51 |
2 files changed, 6 insertions, 54 deletions
diff --git a/src/wrap.js b/src/wrap.js index 32d1d331f..e43794448 100644 --- a/src/wrap.js +++ b/src/wrap.js @@ -9,10 +9,13 @@ jQuery.fn.extend( { wrapAll: function( html ) { var wrap; + if ( jQuery.isFunction( html ) ) { + return this.each(function( i ) { + jQuery( this ).wrapAll( html.call(this, i) ); + }); + } + if ( this[ 0 ] ) { - if ( jQuery.isFunction( html ) ) { - html = html.call( this[ 0 ] ); - } // The elements to wrap the target around wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true ); diff --git a/test/unit/wrap.js b/test/unit/wrap.js index d7ba80d17..84f827db3 100644 --- a/test/unit/wrap.js +++ b/test/unit/wrap.js @@ -206,58 +206,7 @@ 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(Element)", function( assert ) { - assert.expect( 3 ); var prev, p; |