aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSindre Sorhus <sindresorhus@gmail.com>2012-06-15 22:17:05 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-06-15 22:29:02 -0400
commitea9ec9527647f0cea396ca536e6f34b4a4491d11 (patch)
treec88f8c888103dd5fea810ee94db7dfa2970cf520
parent9c28a320c3fa6dcc06de4919d24da41451843570 (diff)
downloadjquery-ea9ec9527647f0cea396ca536e6f34b4a4491d11.tar.gz
jquery-ea9ec9527647f0cea396ca536e6f34b4a4491d11.zip
Fix #11231, (append|prepend|before|after) w/ array of jQuery objects.
Closes gh-666, thanks to @rkatic!
-rw-r--r--src/manipulation.js4
-rw-r--r--test/unit/manipulation.js29
2 files changed, 29 insertions, 4 deletions
diff --git a/src/manipulation.js b/src/manipulation.js
index a7751ac82..3c64105c0 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -289,6 +289,10 @@ jQuery.fn.extend({
},
domManip: function( args, table, callback ) {
+
+ // Flatten any nested arrays
+ args = [].concat.apply( [], args );
+
var results, first, fragment, iNoClone,
i = 0,
value = args[0],
diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js
index 3c3542ef2..846a8ac67 100644
--- a/test/unit/manipulation.js
+++ b/test/unit/manipulation.js
@@ -325,6 +325,12 @@ var testAppendForObject = function(valueObj, isFragment) {
ok( obj.text().match( /5$/ ), "Check for appending a number" + objType );
QUnit.reset();
+ expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:GoogleYahoo";
+ obj = getObj();
+ obj.append( valueObj( [ jQuery("#first"), jQuery("#yahoo, #google") ] ) );
+ equal( obj.text(), expected, "Check for appending of array of jQuery objects" );
+
+ QUnit.reset();
obj = getObj();
obj.append(valueObj( " text with spaces " ));
ok( obj.text().match(/ text with spaces $/), "Check for appending text with spaces" + objType );
@@ -355,7 +361,7 @@ var testAppendForObject = function(valueObj, isFragment) {
}
var testAppend = function(valueObj) {
- expect(56);
+ expect(58);
testAppendForObject(valueObj, false);
testAppendForObject(valueObj, true);
@@ -743,7 +749,7 @@ test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});
var testPrepend = function(val) {
- expect(5);
+ expect(6);
var defaultText = "Try them out:"
var result = jQuery("#first").prepend(val( "<b>buga</b>" ));
equal( result.text(), "buga" + defaultText, "Check if text prepending works" );
@@ -763,6 +769,11 @@ var testPrepend = function(val) {
expected = "YahooTry them out:This link has class=\"blog\": Simon Willison's Weblog";
jQuery("#sap").prepend(val( jQuery("#yahoo, #first") ));
equal( jQuery("#sap").text(), expected, "Check for prepending of jQuery object" );
+
+ QUnit.reset();
+ expected = "Try them out:GoogleYahooThis link has class=\"blog\": Simon Willison's Weblog";
+ jQuery("#sap").prepend( val( [ jQuery("#first"), jQuery("#yahoo, #google") ] ) );
+ equal( jQuery("#sap").text(), expected, "Check for prepending of array of jQuery objects" );
};
test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
@@ -854,7 +865,7 @@ test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});
var testBefore = function(val) {
- expect(6);
+ expect(7);
var expected = "This is a normal link: bugaYahoo";
jQuery("#yahoo").before(val( "<b>buga</b>" ));
equal( jQuery("#en").text(), expected, "Insert String before" );
@@ -874,6 +885,11 @@ var testBefore = function(val) {
jQuery("#yahoo").before(val( jQuery("#mark, #first") ));
equal( jQuery("#en").text(), expected, "Insert jQuery before" );
+ QUnit.reset();
+ expected = "This is a normal link: Try them out:GooglediveintomarkYahoo";
+ jQuery("#yahoo").before( val( [ jQuery("#first"), jQuery("#mark, #google") ] ) );
+ equal( jQuery("#en").text(), expected, "Insert array of jQuery objects before" );
+
var set = jQuery("<div/>").before("<span>test</span>");
equal( set[0].nodeName.toLowerCase(), "span", "Insert the element before the disconnected node." );
equal( set.length, 2, "Insert the element before the disconnected node." );
@@ -918,7 +934,7 @@ test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
});
var testAfter = function(val) {
- expect(6);
+ expect(7);
var expected = "This is a normal link: Yahoobuga";
jQuery("#yahoo").after(val( "<b>buga</b>" ));
equal( jQuery("#en").text(), expected, "Insert String after" );
@@ -938,6 +954,11 @@ var testAfter = function(val) {
jQuery("#yahoo").after(val( jQuery("#mark, #first") ));
equal( jQuery("#en").text(), expected, "Insert jQuery after" );
+ QUnit.reset();
+ expected = "This is a normal link: YahooTry them out:Googlediveintomark";
+ jQuery("#yahoo").after( val( [ jQuery("#first"), jQuery("#mark, #google") ] ) );
+ equal( jQuery("#en").text(), expected, "Insert array of jQuery objects after" );
+
var set = jQuery("<div/>").after("<span>test</span>");
equal( set[1].nodeName.toLowerCase(), "span", "Insert the element after the disconnected node." );
equal( set.length, 2, "Insert the element after the disconnected node." );