Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

jQuery.print: add support for arguments and nodelists

  • Loading branch information...
commit b11bb15921302536956fc0a0d7e4364a47cffbbd 1 parent 45df483
Aman Gupta authored

Showing 2 changed files with 16 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 lib/jquery.print.js
  2. +14 0 spec/print_spec.js
4 lib/jquery.print.js
@@ -90,10 +90,10 @@
90 90 return print_string(obj, opts);
91 91 else if (obj instanceof RegExp)
92 92 return obj.toString();
  93 + else if (obj instanceof Array || obj.callee || obj.item)
  94 + return print_array(obj, opts);
93 95 else if (typeof obj == 'function' || obj instanceof Function)
94 96 return obj.toString().match(/^([^)]*\))/)[1];
95   - else if (obj instanceof Array)
96   - return print_array(obj, opts);
97 97 else if (obj.nodeType)
98 98 return print_element(obj);
99 99 else if (obj instanceof jQuery)
14 spec/print_spec.js
@@ -108,12 +108,26 @@ Screw.Unit(function() {
108 108 });
109 109 });
110 110
  111 + describe('when given arguments', function() {
  112 + it("returns the printed array of elements ", function() {
  113 + var args = null;
  114 + (function(){ args = arguments })(1,2,3);
  115 + expect($.print(args)).to(equal, '[ 1, 2, 3 ]');
  116 + });
  117 + });
  118 +
111 119 describe('when given a jQuery', function() {
112 120 it("returns the printed array of elements engirthed in '$()'", function() {
113 121 expect($.print($('<div>'))).to(equal, '$([ <div> ])');
114 122 });
115 123 });
116 124
  125 + describe('when given a NodeList', function() {
  126 + it("returns the printed array of elements in the list", function() {
  127 + expect($.print(document.getElementsByTagName('body'))).to(equal, '[ <body> ]');
  128 + });
  129 + });
  130 +
117 131 describe('when given an object', function() {
118 132 it("returns the keys and values of the object, enraptured with curly braces", function() {
119 133 expect($.print({})).to(equal, '{}');

0 comments on commit b11bb15

Please sign in to comment.
Something went wrong with that request. Please try again.