Permalink
Browse files

Added support for array arguments

  • Loading branch information...
1 parent df559a1 commit d9a7704775bcb88ff3c1256128ed3e24905d43eb @kriszyp committed Apr 3, 2012
Showing with 14 additions and 0 deletions.
  1. +8 −0 put.js
  2. +6 −0 test/put.js
View
8 put.js
@@ -49,6 +49,14 @@ define([], forDocument = function(doc, newFragmentFasterHeuristic){
var argument = args[i];
if(typeof argument == "object"){
lastSelectorArg = false;
+ if("length" in argument){
+ // an array
+ returnValue = doc.createDocumentFragment();
+ for(var key = 0; key < argument.length; key++){
+ returnValue.appendChild(put(argument[key]));
+ }
+ argument = returnValue;
+ }
if(argument.nodeType){
current = argument;
insertLastElement();
View
@@ -65,4 +65,10 @@ var checkbox = put(div, "input[type=checkbox][checked]");
console.assert(checkbox.type == "checkbox");
console.assert(checkbox.getAttribute("checked") == "checked");
+var div = put("div");
+var arrayFrag = put(div, ["span.c1", "span.c2", "span.c3"]);
+console.assert(arrayFrag.nodeType == 11);
+console.assert(div.firstChild.className == "c1");
+console.assert(div.lastChild.className == "c3");
+
put(body, "div", {innerHTML: "finished tests, check console for errors"});

1 comment on commit d9a7704

Contributor

neonstalwart commented on d9a7704 Apr 4, 2012

yay...

Please sign in to comment.