Fix #13741. Make wrap/unwrap methods optional. Close gh-1222.

This commit is contained in:
Dave Methvin 2013-04-05 17:30:48 -04:00
parent 1114611f77
commit 5031c9db4b
5 changed files with 272 additions and 248 deletions

View File

@ -51,6 +51,7 @@ module.exports = function( grunt ) {
"src/event.js", "src/event.js",
"src/traversing.js", "src/traversing.js",
"src/manipulation.js", "src/manipulation.js",
{ flag: "wrap", src: "src/wrap.js" },
{ flag: "css", src: "src/css.js" }, { flag: "css", src: "src/css.js" },
"src/serialize.js", "src/serialize.js",
{ flag: "event-alias", src: "src/event-alias.js" }, { flag: "event-alias", src: "src/event-alias.js" },

View File

@ -86,6 +86,7 @@ For example, an app that only used JSONP for `$.ajax()` and did not need to calc
- **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`. - **effects**: The `.animate()` method and its shorthands such as `.slideUp()` or `.hide("slow")`.
- **event-alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`. - **event-alias**: All event attaching/triggering shorthands like `.click()` or `.mouseover()`.
- **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods. - **offset**: The `.offset()`, `.position()`, `.offsetParent()`, `.scrollLeft()`, and `.scrollTop()` methods.
- **wrap**: The `.wrap()`, `.wrapAll()`, `.wrapInner()`, and `.unwrap()` methods.
- **sizzle**: The Sizzle selector engine. When this module is excluded, it is replaced by a rudimentary selector engine based on the browser's `querySelectorAll` method that does not support jQuery selector extensions or enhanced semantics. See the selector-native.js file for details. - **sizzle**: The Sizzle selector engine. When this module is excluded, it is replaced by a rudimentary selector engine based on the browser's `querySelectorAll` method that does not support jQuery selector extensions or enhanced semantics. See the selector-native.js file for details.
The grunt build process is aware of dependencies across modules. If you explicitly remove a module, its dependent modules will be removed as well. For example, excluding the css module also excludes effects, since the effects module uses `.css()` to animate CSS properties. These dependencies are listed in Gruntfile.js and the build process shows a message for each dependent module it excludes. The grunt build process is aware of dependencies across modules. If you explicitly remove a module, its dependent modules will be removed as well. For example, excluding the css module also excludes effects, since the effects module uses `.css()` to animate CSS properties. These dependencies are listed in Gruntfile.js and the build process shows a message for each dependent module it excludes.

View File

@ -37,74 +37,6 @@ jQuery.fn.extend({
}, null, value, arguments.length ); }, null, value, arguments.length );
}, },
wrapAll: function( html ) {
var wrap;
if ( jQuery.isFunction( html ) ) {
return this.each(function( i ) {
jQuery( this ).wrapAll( html.call(this, i) );
});
}
if ( this[ 0 ] ) {
// The elements to wrap the target around
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
if ( this[ 0 ].parentNode ) {
wrap.insertBefore( this[ 0 ] );
}
wrap.map(function() {
var elem = this;
while ( elem.firstElementChild ) {
elem = elem.firstElementChild;
}
return elem;
}).append( this );
}
return this;
},
wrapInner: function( html ) {
if ( jQuery.isFunction( html ) ) {
return this.each(function( i ) {
jQuery( this ).wrapInner( html.call(this, i) );
});
}
return this.each(function() {
var self = jQuery( this ),
contents = self.contents();
if ( contents.length ) {
contents.wrapAll( html );
} else {
self.append( html );
}
});
},
wrap: function( html ) {
var isFunction = jQuery.isFunction( html );
return this.each(function( i ) {
jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
});
},
unwrap: function() {
return this.parent().each(function() {
if ( !jQuery.nodeName( this, "body" ) ) {
jQuery( this ).replaceWith( this.childNodes );
}
}).end();
},
append: function() { append: function() {
return this.domManip(arguments, true, function( elem ) { return this.domManip(arguments, true, function( elem ) {
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {

69
src/wrap.js Normal file
View File

@ -0,0 +1,69 @@
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 ] ) {
// The elements to wrap the target around
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
if ( this[ 0 ].parentNode ) {
wrap.insertBefore( this[ 0 ] );
}
wrap.map(function() {
var elem = this;
while ( elem.firstElementChild ) {
elem = elem.firstElementChild;
}
return elem;
}).append( this );
}
return this;
},
wrapInner: function( html ) {
if ( jQuery.isFunction( html ) ) {
return this.each(function( i ) {
jQuery( this ).wrapInner( html.call(this, i) );
});
}
return this.each(function() {
var self = jQuery( this ),
contents = self.contents();
if ( contents.length ) {
contents.wrapAll( html );
} else {
self.append( html );
}
});
},
wrap: function( html ) {
var isFunction = jQuery.isFunction( html );
return this.each(function( i ) {
jQuery( this ).wrapAll( isFunction ? html.call(this, i) : html );
});
},
unwrap: function() {
return this.parent().each(function() {
if ( !jQuery.nodeName( this, "body" ) ) {
jQuery( this ).replaceWith( this.childNodes );
}
}).end();
}
});

View File

@ -103,221 +103,233 @@ test( "text(Function) with incoming value", function() {
equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." ); equal( jQuery("#sap").text(), "foobar", "Check for merged text of more then one element." );
}); });
var testWrap = function( val ) { if ( jQuery.fn.wrap ) {
expect( 19 ); var testWrap = function( val ) {
var defaultText, result, j, i, cacheLength; expect( 19 );
defaultText = "Try them out:", var defaultText, result, j, i, cacheLength;
result = jQuery("#first").wrap( val("<div class='red'><span></span></div>") ).text();
equal( defaultText, result, "Check for wrapping of on-the-fly html" ); defaultText = "Try them out:",
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" ); result = jQuery("#first").wrap( val("<div class='red'><span></span></div>") ).text();
QUnit.reset(); equal( defaultText, result, "Check for wrapping of on-the-fly html" );
result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent(); ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
ok( result.is("ol"), "Check for element wrapping" );
equal( result.text(), defaultText, "Check for element wrapping" );
QUnit.reset(); QUnit.reset();
jQuery("#check1").on( "click", function() { result = jQuery("#first").wrap( val(document.getElementById("empty")) ).parent();
var checkbox = this; ok( result.is("ol"), "Check for element wrapping" );
equal( result.text(), defaultText, "Check for element wrapping" );
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); QUnit.reset();
jQuery( checkbox ).wrap( val("<div id='c1' style='display:none;'></div>") ); jQuery("#check1").on( "click", function() {
ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); var checkbox = this;
}).prop( "checked", false )[ 0 ].click();
// using contents will get comments regular, text, and comment nodes ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
j = jQuery("#nonnodes").contents(); jQuery( checkbox ).wrap( val("<div id='c1' style='display:none;'></div>") );
j.wrap( val("<i></i>") ); ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
}).prop( "checked", false )[ 0 ].click();
// Blackberry 4.6 doesn't maintain comments in the DOM // using contents will get comments regular, text, and comment nodes
equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" ); j = jQuery("#nonnodes").contents();
equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" ); j.wrap( val("<i></i>") );
// Try wrapping a disconnected node // Blackberry 4.6 doesn't maintain comments in the DOM
cacheLength = 0; equal( jQuery("#nonnodes > i").length, jQuery("#nonnodes")[ 0 ].childNodes.length, "Check node,textnode,comment wraps ok" );
for ( i in jQuery.cache ) { equal( jQuery("#nonnodes > i").text(), j.text(), "Check node,textnode,comment wraps doesn't hurt text" );
cacheLength++;
}
j = jQuery("<label/>").wrap( val("<li/>") ); // Try wrapping a disconnected node
equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" ); cacheLength = 0;
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" ); for ( i in jQuery.cache ) {
cacheLength++;
}
for ( i in jQuery.cache ) { j = jQuery("<label/>").wrap( val("<li/>") );
cacheLength--; equal( j[ 0 ] .nodeName.toUpperCase(), "LABEL", "Element is a label" );
} equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "LI", "Element has been wrapped" );
equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
// Wrap an element containing a text node for ( i in jQuery.cache ) {
j = jQuery("<span/>").wrap("<div>test</div>"); cacheLength--;
equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" ); }
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." ); equal( cacheLength, 0, "No memory leak in jQuery.cache (bug #7165)" );
// Try to wrap an element with multiple elements (should fail) // Wrap an element containing a text node
j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>"); j = jQuery("<span/>").wrap("<div>test</div>");
equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." ); equal( j[ 0 ].previousSibling.nodeType, 3, "Make sure the previous node is a text element" );
equal( j.length, 1, "There should only be one element (no cloning)." ); equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "DIV", "And that we're in the div element." );
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
// Wrap an element with a jQuery set // Try to wrap an element with multiple elements (should fail)
j = jQuery("<span/>").wrap( jQuery("<div></div>") ); j = jQuery("<div><span></span></div>").children().wrap("<p></p><div></div>");
equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); equal( j[ 0 ].parentNode.parentNode.childNodes.length, 1, "There should only be one element wrapping." );
equal( j.length, 1, "There should only be one element (no cloning)." );
equal( j[ 0 ].parentNode.nodeName.toUpperCase(), "P", "The span should be in the paragraph." );
// Wrap an element with a jQuery set and event // Wrap an element with a jQuery set
result = jQuery("<div></div>").on( "click", function() { j = jQuery("<span/>").wrap( jQuery("<div></div>") );
ok( true, "Event triggered." ); equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
// Remove handlers on detached elements // Wrap an element with a jQuery set and event
result.off(); result = jQuery("<div></div>").on( "click", function() {
jQuery(this).off(); ok( true, "Event triggered." );
// Remove handlers on detached elements
result.off();
jQuery(this).off();
});
j = jQuery("<span/>").wrap( result );
equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." );
j.parent().trigger("click");
// clean up attached elements
QUnit.reset();
};
test( "wrap(String|Element)", function() {
testWrap( manipulationBareObj );
}); });
j = jQuery("<span/>").wrap( result ); test( "wrap(Function)", function() {
equal( j[ 0 ].parentNode.nodeName.toLowerCase(), "div", "Wrapping works." ); testWrap( manipulationFunctionReturningObj );
j.parent().trigger("click");
// clean up attached elements
QUnit.reset();
};
test( "wrap(String|Element)", function() {
testWrap( manipulationBareObj );
});
test( "wrap(Function)", function() {
testWrap( manipulationFunctionReturningObj );
});
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() { test( "wrap(Function) with index (#10177)", function() {
var targets = jQuery("#qunit-fixture p"); var expectedIndex = 0,
targets = jQuery("#qunit-fixture p");
expect( targets.length * 2 ); expect( targets.length );
targets.wrap("<div class='wrapper'></div>"); targets.wrap(function(i) {
equal( i, expectedIndex, "Check if the provided index (" + i + ") is as expected (" + expectedIndex + ")" );
expectedIndex++;
targets.each(function() { return "<div id='wrap_index_'" + i + "'></div>";
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 ) { test( "wrap(String) consecutive elements (#10177)", function() {
var targets = jQuery("#qunit-fixture p");
expect( 8 ); expect( targets.length * 2 );
targets.wrap("<div class='wrapper'></div>");
var prev, p, result; targets.each(function() {
var $this = jQuery(this);
prev = jQuery("#firstp")[ 0 ].previousSibling; ok( $this.parent().is(".wrapper"), "Check each elements parent is correct (.wrapper)" );
p = jQuery("#firstp,#first")[ 0 ].parentNode; equal( $this.siblings().length, 0, "Each element should be wrapped individually" );
result = jQuery("#firstp,#first").wrapAll( val("<div class='red'><div class='tmp'></div></div>") ); });
});
}
equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" ); if ( jQuery.fn.wrapAll ) {
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
equal( jQuery("#first").parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent().parent()[ 0 ].parentNode, p, "Correct Parent" );
QUnit.reset(); var testWrapAll = function( val ) {
prev = jQuery("#firstp")[ 0 ].previousSibling;
p = jQuery("#first")[ 0 ].parentNode;
result = jQuery("#firstp,#first").wrapAll( val(document.getElementById("empty")) );
equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" ); expect( 8 );
equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
};
test( "wrapAll(String|Element)", function() { var prev, p, result;
testWrapAll( manipulationBareObj );
});
var testWrapInner = function( val ) { prev = jQuery("#firstp")[ 0 ].previousSibling;
p = jQuery("#firstp,#first")[ 0 ].parentNode;
result = jQuery("#firstp,#first").wrapAll( val("<div class='red'><div class='tmp'></div></div>") );
expect( 11 ); equal( result.parent().length, 1, "Check for wrapping of on-the-fly html" );
ok( jQuery("#first").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
ok( jQuery("#firstp").parent().parent().is(".red"), "Check if wrapper has class 'red'" );
equal( jQuery("#first").parent().parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent().parent()[ 0 ].parentNode, p, "Correct Parent" );
var num, result; QUnit.reset();
prev = jQuery("#firstp")[ 0 ].previousSibling;
p = jQuery("#first")[ 0 ].parentNode;
result = jQuery("#firstp,#first").wrapAll( val(document.getElementById("empty")) );
num = jQuery("#first").children().length; equal( jQuery("#first").parent()[ 0 ], jQuery("#firstp").parent()[ 0 ], "Same Parent" );
result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") ); equal( jQuery("#first").parent()[ 0 ].previousSibling, prev, "Correct Previous Sibling" );
equal( jQuery("#first").parent()[ 0 ].parentNode, p, "Correct Parent" );
};
equal( jQuery("#first").children().length, 1, "Only one child" ); test( "wrapAll(String|Element)", function() {
ok( jQuery("#first").children().is(".red"), "Verify Right Element" ); testWrapAll( manipulationBareObj );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" ); });
}
QUnit.reset(); if ( jQuery.fn.wrapInner ) {
num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
QUnit.reset(); var testWrapInner = function( val ) {
num = jQuery("#first").children().length;
result = 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" );
var div = jQuery("<div/>"); expect( 11 );
div.wrapInner( val("<span></span>") );
equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
};
test( "wrapInner(String|Element)", function() { var num, result;
testWrapInner( manipulationBareObj );
});
test( "wrapInner(Function)", function() { num = jQuery("#first").children().length;
testWrapInner( manipulationFunctionReturningObj ); result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
});
test( "unwrap()", function() { equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
expect( 9 ); QUnit.reset();
num = jQuery("#first").html("foo<div>test</div><div>test2</div>").children().length;
result = jQuery("#first").wrapInner( val("<div class='red'><div id='tmp'></div></div>") );
equal( jQuery("#first").children().length, 1, "Only one child" );
ok( jQuery("#first").children().is(".red"), "Verify Right Element" );
equal( jQuery("#first").children().children().children().length, num, "Verify Elements Intact" );
jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>"); QUnit.reset();
num = jQuery("#first").children().length;
result = 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" );
var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(), var div = jQuery("<div/>");
abcdef = jQuery("#unwrap span").get(); div.wrapInner( val("<span></span>") );
equal( div.children().length, 1, "The contents were wrapped." );
equal( div.children()[ 0 ].nodeName.toLowerCase(), "span", "A span was inserted." );
};
equal( jQuery("#unwrap1 span").add("#unwrap2 span:first-child").unwrap().length, 3, "make #unwrap1 and #unwrap2 go away" ); test( "wrapInner(String|Element)", function() {
deepEqual( jQuery("#unwrap > span").get(), abcd, "all four spans should still exist" ); testWrapInner( manipulationBareObj );
});
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" ); test( "wrapInner(Function)", function() {
testWrapInner( manipulationFunctionReturningObj );
});
}
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" ); if ( jQuery.fn.unwrap ) {
deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" ); test( "unwrap()", function() {
deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" ); expect( 9 );
deepEqual( jQuery("body > span.unwrap").unwrap().get(), jQuery("body > span.unwrap").get(), "can't unwrap children of body" ); jQuery("body").append(" <div id='unwrap' style='display: none;'> <div id='unwrap1'> <span class='unwrap'>a</span> <span class='unwrap'>b</span> </div> <div id='unwrap2'> <span class='unwrap'>c</span> <span class='unwrap'>d</span> </div> <div id='unwrap3'> <b><span class='unwrap unwrap3'>e</span></b> <b><span class='unwrap unwrap3'>f</span></b> </div> </div>");
deepEqual( jQuery("body > span.unwrap").unwrap().get(), abcdef, "can't unwrap children of body" );
deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" ); var abcd = jQuery("#unwrap1 > span, #unwrap2 > span").get(),
abcdef = jQuery("#unwrap span").get();
jQuery("body > span.unwrap").remove(); 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" );
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap3 > span").get(), "make all b in #unwrap3 go away" );
deepEqual( jQuery("#unwrap3 span").unwrap().get(), jQuery("#unwrap > span.unwrap3").get(), "make #unwrap3 go away" );
deepEqual( jQuery("#unwrap").children().get(), abcdef, "#unwrap only contains 6 child spans" );
deepEqual( jQuery("#unwrap > span").unwrap().get(), jQuery("body > span.unwrap").get(), "make the 6 spans become children of body" );
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" );
deepEqual( jQuery("body > span.unwrap").get(), abcdef, "body contains 6 .unwrap child spans" );
jQuery("body > span.unwrap").remove();
});
}
var testAppendForObject = function( valueObj, isFragment ) { var testAppendForObject = function( valueObj, isFragment ) {
var $base, var $base,
@ -495,7 +507,9 @@ var testAppend = function( valueObj ) {
$radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent ); $radioUnchecked = jQuery("<input type='radio' name='R1' checked='checked'/>").appendTo( $radioParent );
$radioChecked.trigger("click"); $radioChecked.trigger("click");
$radioUnchecked[ 0 ].checked = false; $radioUnchecked[ 0 ].checked = false;
$radioParent.wrap("<div></div>");
jQuery("<div/>").insertBefore($radioParent).append($radioParent);
equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" ); equal( $radioChecked[ 0 ].checked, true, "Reappending radios uphold which radio is checked" );
equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" ); equal( $radioUnchecked[ 0 ].checked, false, "Reappending radios uphold not being checked" );
@ -1926,18 +1940,21 @@ test( "jQuery.clone - no exceptions for object elements #9587", function() {
} }
}); });
test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function() { if ( jQuery.fn.wrapAll ) {
expect( 2 ); test( "jQuery(<tag>) & wrap[Inner/All]() handle unknown elems (#10667)", function() {
var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ), expect( 2 );
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
$wraptarget.wrapAll("<aside style='background-color:green'></aside>"); var $wraptarget = jQuery( "<div id='wrap-target'>Target</div>" ).appendTo( "#qunit-fixture" ),
$section = jQuery( "<section>" ).appendTo( "#qunit-fixture" );
notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" ); $wraptarget.wrapAll("<aside style='background-color:green'></aside>");
notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
}); notEqual( $wraptarget.parent("aside").get( 0 ).style.backgroundColor, "transparent", "HTML5 elements created with wrapAll inherit styles" );
notEqual( $section.get( 0 ).style.backgroundColor, "transparent", "HTML5 elements create with jQuery( string ) inherit styles" );
});
}
test( "Cloned, detached HTML5 elems (#10667,10670)", function() { test( "Cloned, detached HTML5 elems (#10667,10670)", function() {
@ -2135,19 +2152,23 @@ test( "script evaluation (#11795)", function() {
objGlobal.ok = isOk; objGlobal.ok = isOk;
}); });
test( "wrapping scripts (#10470)", function() { if ( jQuery.fn.wrap ) {
expect( 2 ); test( "wrapping scripts (#10470)", function() {
var script = document.createElement("script"); expect( 2 );
script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
document.eval10470 = false; var script = document.createElement("script");
jQuery("#qunit-fixture").empty()[0].appendChild( script ); script.text = script.textContent = "ok( !document.eval10470, 'script evaluated once' ); document.eval10470 = true;";
jQuery("#qunit-fixture script").wrap("<b></b>");
strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" ); document.eval10470 = false;
jQuery( script ).remove(); jQuery("#qunit-fixture").empty()[0].appendChild( script );
}); jQuery("#qunit-fixture script").wrap("<b></b>");
strictEqual( script.parentNode, jQuery("#qunit-fixture > b")[ 0 ], "correctly wrapped" );
jQuery( script ).remove();
});
}
test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function() { test( "insertAfter, insertBefore, etc do not work when destination is original element. Element is removed (#4087)", function() {