Skip to content

Commit

Permalink
Merge pull request madrobby#1095 from caricati/master
Browse files Browse the repository at this point in the history
Better support for array argument to `append`
  • Loading branch information
madrobby authored Jul 11, 2016
2 parents 98f0d34 + 10efcf5 commit ad084d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,17 @@ var Zepto = (function() {
$.fn[operator] = function(){
// arguments can be nodes, arrays of nodes, Zepto objects and HTML strings
var argType, nodes = $.map(arguments, function(arg) {
var arr = []
argType = type(arg)
return argType == "object" || argType == "array" || arg == null ?
if (argType == "array") {
arg.forEach(function(el) {
if (el.nodeType !== undefined) return arr.push(el)
else if ($.zepto.isZ(el)) return arr = arr.concat(el.get())
arr = arr.concat(zepto.fragment(el))
})
return arr
}
return argType == "object" || arg == null ?
arg : zepto.fragment(arg)
}),
parent, copyByClone = this.length > 1
Expand Down
13 changes: 13 additions & 0 deletions test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,19 @@ <h1>Zepto Core unit tests</h1>
$.map(el.children(), function(c){ return $(c).text() }).join(' '))
},

testAppendWithArrayParams: function(t){
var zpElement = $('<b>five</b>')
var multElements = $('<b>six</b><b>seven</b>')
var node = document.createElement('b')
node.appendChild(document.createTextNode('four'))

// append elements on this array
var arrElements = ['<b>one</b><b>two</b>', '<b>three</b>', node, zpElement, multElements ]
var el = $('<div></div>')
el.append(arrElements)
t.assertEqual('<b>one</b><b>two</b><b>three</b><b>four</b><b>five</b><b>six</b><b>seven</b>', el.html())
},

testAppendToPrependTo: function(t){
// testing with Zepto object
function div(contents){
Expand Down

0 comments on commit ad084d4

Please sign in to comment.