jquery_table_export_rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,190 @@
1
+ /*jslint adsafe: false, bitwise: true, browser: true, cap: false, css: false,
2
+ debug: false, devel: true, eqeqeq: true, es5: false, evil: false,
3
+ forin: false, fragment: false, immed: true, laxbreak: false, newcap: true,
4
+ nomen: false, on: false, onevar: true, passfail: false, plusplus: true,
5
+ regexp: false, rhino: true, safe: false, strict: false, sub: false,
6
+ undef: true, white: false, widget: false, windows: false */
7
+ /*global jQuery: false, window: false */
8
+ //"use strict";
9
+
10
+ /*
11
+ * Original code (c) 2010 Nick Galbreath
12
+ * http://code.google.com/p/stringencoders/source/browse/#svn/trunk/javascript
13
+ *
14
+ * jQuery port (c) 2010 Carlo Zottmann
15
+ * http://github.com/carlo/jquery-base64
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person
18
+ * obtaining a copy of this software and associated documentation
19
+ * files (the "Software"), to deal in the Software without
20
+ * restriction, including without limitation the rights to use,
21
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
22
+ * copies of the Software, and to permit persons to whom the
23
+ * Software is furnished to do so, subject to the following
24
+ * conditions:
25
+ *
26
+ * The above copyright notice and this permission notice shall be
27
+ * included in all copies or substantial portions of the Software.
28
+ *
29
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
31
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
33
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
34
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36
+ * OTHER DEALINGS IN THE SOFTWARE.
37
+ */
38
+
39
+ /* base64 encode/decode compatible with window.btoa/atob
40
+ *
41
+ * window.atob/btoa is a Firefox extension to convert binary data (the "b")
42
+ * to base64 (ascii, the "a").
43
+ *
44
+ * It is also found in Safari and Chrome. It is not available in IE.
45
+ *
46
+ * if (!window.btoa) window.btoa = $.base64.encode
47
+ * if (!window.atob) window.atob = $.base64.decode
48
+ *
49
+ * The original spec's for atob/btoa are a bit lacking
50
+ * https://developer.mozilla.org/en/DOM/window.atob
51
+ * https://developer.mozilla.org/en/DOM/window.btoa
52
+ *
53
+ * window.btoa and $.base64.encode takes a string where charCodeAt is [0,255]
54
+ * If any character is not [0,255], then an exception is thrown.
55
+ *
56
+ * window.atob and $.base64.decode take a base64-encoded string
57
+ * If the input length is not a multiple of 4, or contains invalid characters
58
+ * then an exception is thrown.
59
+ */
60
+
61
+ jQuery.base64 = ( function( $ ) {
62
+
63
+ var _PADCHAR = "=",
64
+ _ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
65
+ _VERSION = "1.0";
66
+
67
+
68
+ function _getbyte64( s, i ) {
69
+ // This is oddly fast, except on Chrome/V8.
70
+ // Minimal or no improvement in performance by using a
71
+ // object with properties mapping chars to value (eg. 'A': 0)
72
+
73
+ var idx = _ALPHA.indexOf( s.charAt( i ) );
74
+
75
+ if ( idx === -1 ) {
76
+ throw "Cannot decode base64";
77
+ }
78
+
79
+ return idx;
80
+ }
81
+
82
+
83
+ function _decode( s ) {
84
+ var pads = 0,
85
+ i,
86
+ b10,
87
+ imax = s.length,
88
+ x = [];
89
+
90
+ s = String( s );
91
+
92
+ if ( imax === 0 ) {
93
+ return s;
94
+ }
95
+
96
+ if ( imax % 4 !== 0 ) {
97
+ throw "Cannot decode base64";
98
+ }
99
+
100
+ if ( s.charAt( imax - 1 ) === _PADCHAR ) {
101
+ pads = 1;
102
+
103
+ if ( s.charAt( imax - 2 ) === _PADCHAR ) {
104
+ pads = 2;
105
+ }
106
+
107
+ // either way, we want to ignore this last block
108
+ imax -= 4;
109
+ }
110
+
111
+ for ( i = 0; i < imax; i += 4 ) {
112
+ b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 ) | _getbyte64( s, i + 3 );
113
+ x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff, b10 & 0xff ) );
114
+ }
115
+
116
+ switch ( pads ) {
117
+ case 1:
118
+ b10 = ( _getbyte64( s, i ) << 18 ) | ( _getbyte64( s, i + 1 ) << 12 ) | ( _getbyte64( s, i + 2 ) << 6 );
119
+ x.push( String.fromCharCode( b10 >> 16, ( b10 >> 8 ) & 0xff ) );
120
+ break;
121
+
122
+ case 2:
123
+ b10 = ( _getbyte64( s, i ) << 18) | ( _getbyte64( s, i + 1 ) << 12 );
124
+ x.push( String.fromCharCode( b10 >> 16 ) );
125
+ break;
126
+ }
127
+
128
+ return x.join( "" );
129
+ }
130
+
131
+
132
+ function _getbyte( s, i ) {
133
+ var x = s.charCodeAt( i );
134
+
135
+ if ( x > 255 ) {
136
+ throw "INVALID_CHARACTER_ERR: DOM Exception 5";
137
+ }
138
+
139
+ return x;
140
+ }
141
+
142
+
143
+ function _encode( s ) {
144
+ if ( arguments.length !== 1 ) {
145
+ throw "SyntaxError: exactly one argument required";
146
+ }
147
+
148
+ s = String( s );
149
+
150
+ var i,
151
+ b10,
152
+ x = [],
153
+ imax = s.length - s.length % 3;
154
+
155
+ if ( s.length === 0 ) {
156
+ return s;
157
+ }
158
+
159
+ for ( i = 0; i < imax; i += 3 ) {
160
+ b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 ) | _getbyte( s, i + 2 );
161
+ x.push( _ALPHA.charAt( b10 >> 18 ) );
162
+ x.push( _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) );
163
+ x.push( _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) );
164
+ x.push( _ALPHA.charAt( b10 & 0x3f ) );
165
+ }
166
+
167
+ switch ( s.length - imax ) {
168
+ case 1:
169
+ b10 = _getbyte( s, i ) << 16;
170
+ x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _PADCHAR + _PADCHAR );
171
+ break;
172
+
173
+ case 2:
174
+ b10 = ( _getbyte( s, i ) << 16 ) | ( _getbyte( s, i + 1 ) << 8 );
175
+ x.push( _ALPHA.charAt( b10 >> 18 ) + _ALPHA.charAt( ( b10 >> 12 ) & 0x3F ) + _ALPHA.charAt( ( b10 >> 6 ) & 0x3f ) + _PADCHAR );
176
+ break;
177
+ }
178
+
179
+ return x.join( "" );
180
+ }
181
+
182
+
183
+ return {
184
+ decode: _decode,
185
+ encode: _encode,
186
+ VERSION: _VERSION
187
+ };
188
+
189
+ }( jQuery ) );
190
+
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,303 @@
1
+ /**
2
+ * jsPDF
3
+ * (c) 2009 James Hall
4
+ *
5
+ * Some parts based on FPDF.
6
+ */
7
+
8
+ var jsPDF = function(){
9
+
10
+ // Private properties
11
+ var version = '20090504';
12
+ var buffer = '';
13
+
14
+ var pdfVersion = '1.3'; // PDF Version
15
+ var defaultPageFormat = 'a4';
16
+ var pageFormats = { // Size in mm of various paper formats
17
+ 'a3': [841.89, 1190.55],
18
+ 'a4': [595.28, 841.89],
19
+ 'a5': [420.94, 595.28],
20
+ 'letter': [612, 792],
21
+ 'legal': [612, 1008]
22
+ };
23
+ var textColor = '0 g';
24
+ var page = 0;
25
+ var objectNumber = 2; // 'n' Current object number
26
+ var state = 0; // Current document state
27
+ var pages = new Array();
28
+ var offsets = new Array(); // List of offsets
29
+ var lineWidth = 0.200025; // 2mm
30
+ var pageHeight;
31
+ var k; // Scale factor
32
+ var unit = 'mm'; // Default to mm for units
33
+ var fontNumber; // TODO: This is temp, replace with real font handling
34
+ var documentProperties = {};
35
+ var fontSize = 16; // Default font size
36
+ var pageFontSize = 16;
37
+
38
+ // Initilisation
39
+ if (unit == 'pt') {
40
+ k = 1;
41
+ } else if(unit == 'mm') {
42
+ k = 72/25.4;
43
+ } else if(unit == 'cm') {
44
+ k = 72/2.54;
45
+ } else if(unit == 'in') {
46
+ k = 72;
47
+ }
48
+
49
+ // Private functions
50
+ var newObject = function() {
51
+ //Begin a new object
52
+ objectNumber ++;
53
+ offsets[objectNumber] = buffer.length;
54
+ out(objectNumber + ' 0 obj');
55
+ }
56
+
57
+
58
+ var putHeader = function() {
59
+ out('%PDF-' + pdfVersion);
60
+ }
61
+
62
+ var putPages = function() {
63
+
64
+ // TODO: Fix, hardcoded to a4 portrait
65
+ var wPt = pageWidth * k;
66
+ var hPt = pageHeight * k;
67
+
68
+ for(n=1; n <= page; n++) {
69
+ newObject();
70
+ out('<</Type /Page');
71
+ out('/Parent 1 0 R');
72
+ out('/Resources 2 0 R');
73
+ out('/Contents ' + (objectNumber + 1) + ' 0 R>>');
74
+ out('endobj');
75
+
76
+ //Page content
77
+ p = pages[n];
78
+ newObject();
79
+ out('<</Length ' + p.length + '>>');
80
+ putStream(p);
81
+ out('endobj');
82
+ }
83
+ offsets[1] = buffer.length;
84
+ out('1 0 obj');
85
+ out('<</Type /Pages');
86
+ var kids='/Kids [';
87
+ for (i = 0; i < page; i++) {
88
+ kids += (3 + 2 * i) + ' 0 R ';
89
+ }
90
+ out(kids + ']');
91
+ out('/Count ' + page);
92
+ out(sprintf('/MediaBox [0 0 %.2f %.2f]', wPt, hPt));
93
+ out('>>');
94
+ out('endobj');
95
+ }
96
+
97
+ var putStream = function(str) {
98
+ out('stream');
99
+ out(str);
100
+ out('endstream');
101
+ }
102
+
103
+ var putResources = function() {
104
+ putFonts();
105
+ putImages();
106
+
107
+ //Resource dictionary
108
+ offsets[2] = buffer.length;
109
+ out('2 0 obj');
110
+ out('<<');
111
+ putResourceDictionary();
112
+ out('>>');
113
+ out('endobj');
114
+ }
115
+
116
+ var putFonts = function() {
117
+ // TODO: Only supports core font hardcoded to Helvetica
118
+ newObject();
119
+ fontNumber = objectNumber;
120
+ name = 'Helvetica';
121
+ out('<</Type /Font');
122
+ out('/BaseFont /' + name);
123
+ out('/Subtype /Type1');
124
+ out('/Encoding /WinAnsiEncoding');
125
+ out('>>');
126
+ out('endobj');
127
+ }
128
+
129
+ var putImages = function() {
130
+ // TODO
131
+ }
132
+
133
+ var putResourceDictionary = function() {
134
+ out('/ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
135
+ out('/Font <<');
136
+ // Do this for each font, the '1' bit is the index of the font
137
+ // fontNumber is currently the object number related to 'putFonts'
138
+ out('/F1 ' + fontNumber + ' 0 R');
139
+ out('>>');
140
+ out('/XObject <<');
141
+ putXobjectDict();
142
+ out('>>');
143
+ }
144
+
145
+ var putXobjectDict = function() {
146
+ // TODO
147
+ // Loop through images
148
+ }
149
+
150
+
151
+ var putInfo = function() {
152
+ out('/Producer (jsPDF ' + version + ')');
153
+ if(documentProperties.title != undefined) {
154
+ out('/Title (' + pdfEscape(documentProperties.title) + ')');
155
+ }
156
+ if(documentProperties.subject != undefined) {
157
+ out('/Subject (' + pdfEscape(documentProperties.subject) + ')');
158
+ }
159
+ if(documentProperties.author != undefined) {
160
+ out('/Author (' + pdfEscape(documentProperties.author) + ')');
161
+ }
162
+ if(documentProperties.keywords != undefined) {
163
+ out('/Keywords (' + pdfEscape(documentProperties.keywords) + ')');
164
+ }
165
+ if(documentProperties.creator != undefined) {
166
+ out('/Creator (' + pdfEscape(documentProperties.creator) + ')');
167
+ }
168
+ var created = new Date();
169
+ var year = created.getFullYear();
170
+ var month = (created.getMonth() + 1);
171
+ var day = created.getDate();
172
+ var hour = created.getHours();
173
+ var minute = created.getMinutes();
174
+ var second = created.getSeconds();
175
+ out('/CreationDate (D:' + sprintf('%02d%02d%02d%02d%02d%02d', year, month, day, hour, minute, second) + ')');
176
+ }
177
+
178
+ var putCatalog = function () {
179
+ out('/Type /Catalog');
180
+ out('/Pages 1 0 R');
181
+ // TODO: Add zoom and layout modes
182
+ out('/OpenAction [3 0 R /FitH null]');
183
+ out('/PageLayout /OneColumn');
184
+ }
185
+
186
+ function putTrailer() {
187
+ out('/Size ' + (objectNumber + 1));
188
+ out('/Root ' + objectNumber + ' 0 R');
189
+ out('/Info ' + (objectNumber - 1) + ' 0 R');
190
+ }
191
+
192
+ var endDocument = function() {
193
+ state = 1;
194
+ putHeader();
195
+ putPages();
196
+
197
+ putResources();
198
+ //Info
199
+ newObject();
200
+ out('<<');
201
+ putInfo();
202
+ out('>>');
203
+ out('endobj');
204
+
205
+ //Catalog
206
+ newObject();
207
+ out('<<');
208
+ putCatalog();
209
+ out('>>');
210
+ out('endobj');
211
+
212
+ //Cross-ref
213
+ var o = buffer.length;
214
+ out('xref');
215
+ out('0 ' + (objectNumber + 1));
216
+ out('0000000000 65535 f ');
217
+ for (var i=1; i <= objectNumber; i++) {
218
+ out(sprintf('%010d 00000 n ', offsets[i]));
219
+ }
220
+ //Trailer
221
+ out('trailer');
222
+ out('<<');
223
+ putTrailer();
224
+ out('>>');
225
+ out('startxref');
226
+ out(o);
227
+ out('%%EOF');
228
+ state = 3;
229
+ }
230
+
231
+ var beginPage = function() {
232
+ page ++;
233
+ // Do dimension stuff
234
+ state = 2;
235
+ pages[page] = '';
236
+
237
+ // TODO: Hardcoded at A4 and portrait
238
+ pageHeight = pageFormats['a4'][1] / k;
239
+ pageWidth = pageFormats['a4'][0] / k;
240
+ }
241
+
242
+ var out = function(string) {
243
+ if(state == 2) {
244
+ pages[page] += string + '\n';
245
+ } else {
246
+ buffer += string + '\n';
247
+ }
248
+ }
249
+
250
+ var _addPage = function() {
251
+ beginPage();
252
+ // Set line width
253
+ out(sprintf('%.2f w', (lineWidth * k)));
254
+
255
+ // Set font - TODO
256
+ // 16 is the font size
257
+ pageFontSize = fontSize;
258
+ out('BT /F1 ' + parseInt(fontSize) + '.00 Tf ET');
259
+ }
260
+
261
+ // Add the first page automatically
262
+ _addPage();
263
+
264
+ // Escape text
265
+ var pdfEscape = function(text) {
266
+ return text.replace(/\\/g, '\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)');
267
+ }
268
+
269
+ return {
270
+ addPage: function() {
271
+ _addPage();
272
+ },
273
+ text: function(x, y, text) {
274
+ // need page height
275
+ if(pageFontSize != fontSize) {
276
+ out('BT /F1 ' + parseInt(fontSize) + '.00 Tf ET');
277
+ pageFontSize = fontSize;
278
+ }
279
+ var str = sprintf('BT %.2f %.2f Td (%s) Tj ET', x * k, (pageHeight - y) * k, pdfEscape(text));
280
+ out(str);
281
+ },
282
+ setProperties: function(properties) {
283
+ documentProperties = properties;
284
+ },
285
+ addImage: function(imageData, format, x, y, w, h) {
286
+
287
+ },
288
+ output: function(type, options) {
289
+ endDocument();
290
+ if(type == undefined) {
291
+ return buffer;
292
+ }
293
+ if(type == 'datauri') {
294
+ document.location.href = 'data:application/pdf;base64,' + Base64.encode(buffer);
295
+ }
296
+ // @TODO: Add different output options
297
+ },
298
+ setFontSize: function(size) {
299
+ fontSize = size;
300
+ }
301
+ }
302
+
303
+ };