From 71c7c8d0ba2dbf8a2a8f160248bc6fa5be25cc32 Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Tue, 22 Dec 2015 21:20:16 +0300 Subject: [PATCH] Revert "Wrap: Support .unwrap( selector) for selective unwrapping" This reverts commit e38138af6ac3fa850a092adf09366a68850189a8. --- src/wrap.js | 11 ++-- test/unit/wrap.js | 142 +++++++++------------------------------------- 2 files changed, 32 insertions(+), 121 deletions(-) diff --git a/src/wrap.js b/src/wrap.js index e50431116..b377a8739 100644 --- a/src/wrap.js +++ b/src/wrap.js @@ -64,11 +64,12 @@ jQuery.fn.extend( { } ); }, - unwrap: function( selector ) { - this.parent( selector ).not( "body" ).each( function() { - jQuery( this ).replaceWith( this.childNodes ); - } ); - return this; + unwrap: function() { + return this.parent().each(function() { + if ( !jQuery.nodeName( this, "body" ) ) { + jQuery( this ).replaceWith( this.childNodes ); + } + }).end(); } } ); diff --git a/test/unit/wrap.js b/test/unit/wrap.js index 3fa9c438a..2348f2d47 100644 --- a/test/unit/wrap.js +++ b/test/unit/wrap.js @@ -332,136 +332,46 @@ QUnit.test( "wrapInner(Function) returns Element", function( assert ) { var num, val = manipulationFunctionReturningObj, - div = jQuery( "
" ); + div = jQuery("
"); - num = jQuery( "#first" ).children().length; - jQuery( "#first" ).wrapInner( val( document.getElementById( "empty" ) ) ); - assert.equal( - jQuery( "#first" ).children().length, 1, "Only one child" - ); - assert.ok( - jQuery( "#first" ).children().is( "#empty" ), "Verify Right Element" - ); - assert.equal( - jQuery( "#first" ).children().children().length, num, "Verify Elements Intact" - ); + num = jQuery("#first").children().length; + jQuery("#first").wrapInner( val(document.getElementById("empty")) ); + equal( jQuery("#first").children().length, 1, "Only one child" ); + ok( jQuery("#first").children().is("#empty"), "Verify Right Element" ); + equal( jQuery("#first").children().children().length, num, "Verify Elements Intact" ); - div.wrapInner( val( "" ) ); - assert.equal( - div.children().length, 1, "The contents were wrapped." - ); - assert.equal( - div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." - ); -} ); + div.wrapInner( val("") ); + equal( div.children().length, 1, "The contents were wrapped." ); + equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." ); +}); -QUnit.test( "unwrap()", function( assert ) { +test( "unwrap()", function() { - assert.expect( 9 ); + expect( 9 ); - jQuery( "body" ).append( - " " - ); + jQuery("body").append(" "); - var abcd = jQuery( "#unwrap1 > span, #unwrap2 > span" ).get(), - abcdef = jQuery( "#unwrap span" ).get(); + var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), + abcdef = jQuery("#unwrap span").get(); - assert.equal( - jQuery( "#unwrap1 span" ).add( "#unwrap2 span:first-child" ).unwrap().length, - 3, - "make #unwrap1 and #unwrap2 go away" - ); - assert.deepEqual( - jQuery( "#unwrap > span" ).get(), abcd, "all four spans should still exist" - ); + equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); + deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" ); - assert.deepEqual( - jQuery( "#unwrap3 span" ).unwrap().get(), - jQuery( "#unwrap3 > span" ).get(), - "make all b in #unwrap3 go away" - ); + deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" ); - assert.deepEqual( - jQuery( "#unwrap3 span" ).unwrap().get(), - jQuery( "#unwrap > span.unwrap3" ).get(), - "make #unwrap3 go away" - ); + deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" ); - assert.deepEqual( - jQuery( "#unwrap" ).children().get(), - abcdef, - "#unwrap only contains 6 child spans" - ); + deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" ); - assert.deepEqual( - jQuery( "#unwrap > span" ).unwrap().get(), - jQuery( "body > span.unwrap" ).get(), - "make the 6 spans become children of body" - ); - - assert.deepEqual( - jQuery( "body > span.unwrap" ).unwrap().get(), - jQuery( "body > span.unwrap" ).get(), - "can't unwrap children of body" - ); - assert.deepEqual( - jQuery( "body > span.unwrap" ).unwrap().get(), abcdef, "can't unwrap children of body" - ); - - assert.deepEqual( - jQuery( "body > span.unwrap" ).get(), abcdef, "body contains 6 .unwrap child spans" - ); - - jQuery( "body > span.unwrap" ).remove(); -} ); - -QUnit.test( "unwrap( selector )", function( assert ) { - - assert.expect( 5 ); - - jQuery( "body" ).append( - " " - ); - - // Shouldn't unwrap, no match - jQuery( "#unwrap1 span" ) .unwrap( "#unwrap2" ); - assert.equal( - jQuery( "#unwrap1" ).length, 1, "still wrapped" - ); - - // Shouldn't unwrap, no match - jQuery( "#unwrap1 span" ) .unwrap( "span" ); - assert.equal( - jQuery( "#unwrap1" ).length, 1, "still wrapped" - ); + deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" ); - // Unwraps - jQuery( "#unwrap1 span" ) .unwrap( "#unwrap1" ); - assert.equal( - jQuery( "#unwrap1" ).length, 0, "unwrapped match" - ); + deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" ); + deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" ); - // Check return values - assert.deepEqual( - jQuery( "#unwrap2 span" ).get(), - jQuery( "#unwrap2 span" ).unwrap( "quote" ).get(), - "return on unmatched unwrap" - ); - assert.deepEqual( - jQuery( "#unwrap2 span" ).get(), - jQuery( "#unwrap2 span" ).unwrap( "#unwrap2" ).get(), - "return on matched unwrap" - ); + deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" ); - jQuery( "body > span.unwrap" ).remove(); -} ); + jQuery("body > span.unwrap").remove(); +}); QUnit.test( "jQuery() & wrap[Inner/All]() handle unknown elems (#10667)", function( assert ) { -- 2.39.5