Browse files

jQuery.print: add support for arguments and nodelists

  • Loading branch information...
1 parent 45df483 commit b11bb15921302536956fc0a0d7e4364a47cffbbd @tmm1 committed May 20, 2008
Showing with 16 additions and 2 deletions.
  1. +2 −2 lib/jquery.print.js
  2. +14 −0 spec/print_spec.js
View
4 lib/jquery.print.js
@@ -90,10 +90,10 @@
return print_string(obj, opts);
else if (obj instanceof RegExp)
return obj.toString();
+ else if (obj instanceof Array || obj.callee || obj.item)
+ return print_array(obj, opts);
else if (typeof obj == 'function' || obj instanceof Function)
return obj.toString().match(/^([^)]*\))/)[1];
- else if (obj instanceof Array)
- return print_array(obj, opts);
else if (obj.nodeType)
return print_element(obj);
else if (obj instanceof jQuery)
View
14 spec/print_spec.js
@@ -108,12 +108,26 @@ Screw.Unit(function() {
});
});
+ describe('when given arguments', function() {
+ it("returns the printed array of elements ", function() {
+ var args = null;
+ (function(){ args = arguments })(1,2,3);
+ expect($.print(args)).to(equal, '[ 1, 2, 3 ]');
+ });
+ });
+
describe('when given a jQuery', function() {
it("returns the printed array of elements engirthed in '$()'", function() {
expect($.print($('<div>'))).to(equal, '$([ <div> ])');
});
});
+ describe('when given a NodeList', function() {
+ it("returns the printed array of elements in the list", function() {
+ expect($.print(document.getElementsByTagName('body'))).to(equal, '[ <body> ]');
+ });
+ });
+
describe('when given an object', function() {
it("returns the keys and values of the object, enraptured with curly braces", function() {
expect($.print({})).to(equal, '{}');

0 comments on commit b11bb15

Please sign in to comment.