From: Yehuda Katz Date: Sun, 12 Jul 2009 21:08:54 +0000 (+0000) Subject: Add tests for replaceAll(fn) and wrap(fn) -- mark wrapAll and wrapWithin as TODO X-Git-Url: http://git.asbjorn.biz/?p=jquery.git;a=commitdiff_plain;h=35951021545a3ae88018fc5ea3bebd1bc7d09c6a Add tests for replaceAll(fn) and wrap(fn) -- mark wrapAll and wrapWithin as TODO --- diff --git a/src/manipulation.js b/src/manipulation.js index 59973de..57b607a 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -18,6 +18,10 @@ jQuery.fn.extend({ }, wrapAll: function( html ) { + if(jQuery.isFunction(html)) { + return this.each(function() { jQuery(this).wrapAll(html.call(this)); }); + } + if ( this[0] ) { // The elements to wrap the target around var wrap = jQuery( html, this[0].ownerDocument ).clone(); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index da82e67..d8dbca9 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -9,16 +9,16 @@ test("text()", function() { equals( jQuery('#sap').text(), expected, 'Check for merged text of more then one element.' ); }); -test("wrap(String|Element)", function() { +var testWrap = function(val) { expect(10); var defaultText = 'Try them out:' - var result = jQuery('#first').wrap('
').text(); + var result = jQuery('#first').wrap(val( '
' )).text(); equals( defaultText, result, 'Check for wrapping of on-the-fly html' ); ok( jQuery('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' ); reset(); var defaultText = 'Try them out:' - var result = jQuery('#first').wrap(document.getElementById('empty')).parent(); + var result = jQuery('#first').wrap(val( document.getElementById('empty') )).parent(); ok( result.is('ol'), 'Check for element wrapping' ); equals( result.text(), defaultText, 'Check for element wrapping' ); @@ -26,27 +26,36 @@ test("wrap(String|Element)", function() { jQuery('#check1').click(function() { var checkbox = this; ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); - jQuery(checkbox).wrap( '' ); + jQuery(checkbox).wrap(val( '' )); ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" ); }).click(); // using contents will get comments regular, text, and comment nodes var j = jQuery("#nonnodes").contents(); - j.wrap(""); + j.wrap(val( "" )); equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" ); equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" ); // Try wrapping a disconnected node - j = jQuery("