Skip to content
Permalink
Browse files
Fix #11231, (append|prepend|before|after) w/ array of jQuery objects.
Closes gh-666, thanks to @rkatic!
  • Loading branch information
sindresorhus authored and dmethvin committed Jun 16, 2012
1 parent 9c28a32 commit ea9ec95
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
@@ -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],
@@ -324,6 +324,12 @@ var testAppendForObject = function(valueObj, isFragment) {
obj.append(valueObj( 5 ));
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 " ));
@@ -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<Element>|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." );

0 comments on commit ea9ec95

Please sign in to comment.