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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/html2canvas.js +3010 -0
- data/app/assets/javascripts/jquery.base64.js +190 -0
- data/app/assets/javascripts/jquery_table_export.js +1 -0
- data/app/assets/javascripts/jspdf/jspdf.js +303 -0
- data/app/assets/javascripts/jspdf/libs/base64.js +143 -0
- data/app/assets/javascripts/jspdf/libs/sprintf.js +152 -0
- data/app/assets/javascripts/tableExport.js +2090 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/jquery_table_export_rails.gemspec +28 -0
- data/lib/jquery_table_export_rails.rb +6 -0
- data/lib/jquery_table_export_rails/engine.rb +4 -0
- data/lib/jquery_table_export_rails/version.rb +3 -0
- metadata +95 -0
@@ -0,0 +1,143 @@
|
|
1
|
+
|
2
|
+
/**
|
3
|
+
*
|
4
|
+
* Base64 encode / decode
|
5
|
+
* http://www.webtoolkit.info/
|
6
|
+
*
|
7
|
+
**/
|
8
|
+
|
9
|
+
var Base64 = {
|
10
|
+
|
11
|
+
// private property
|
12
|
+
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
13
|
+
|
14
|
+
// public method for encoding
|
15
|
+
encode : function (input) {
|
16
|
+
var output = "";
|
17
|
+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
18
|
+
var i = 0;
|
19
|
+
|
20
|
+
input = Base64._utf8_encode(input);
|
21
|
+
|
22
|
+
while (i < input.length) {
|
23
|
+
|
24
|
+
chr1 = input.charCodeAt(i++);
|
25
|
+
chr2 = input.charCodeAt(i++);
|
26
|
+
chr3 = input.charCodeAt(i++);
|
27
|
+
|
28
|
+
enc1 = chr1 >> 2;
|
29
|
+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
30
|
+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
31
|
+
enc4 = chr3 & 63;
|
32
|
+
|
33
|
+
if (isNaN(chr2)) {
|
34
|
+
enc3 = enc4 = 64;
|
35
|
+
} else if (isNaN(chr3)) {
|
36
|
+
enc4 = 64;
|
37
|
+
}
|
38
|
+
|
39
|
+
output = output +
|
40
|
+
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
|
41
|
+
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
return output;
|
46
|
+
},
|
47
|
+
|
48
|
+
// public method for decoding
|
49
|
+
decode : function (input) {
|
50
|
+
var output = "";
|
51
|
+
var chr1, chr2, chr3;
|
52
|
+
var enc1, enc2, enc3, enc4;
|
53
|
+
var i = 0;
|
54
|
+
|
55
|
+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
56
|
+
|
57
|
+
while (i < input.length) {
|
58
|
+
|
59
|
+
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
60
|
+
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
61
|
+
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
62
|
+
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
63
|
+
|
64
|
+
chr1 = (enc1 << 2) | (enc2 >> 4);
|
65
|
+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
66
|
+
chr3 = ((enc3 & 3) << 6) | enc4;
|
67
|
+
|
68
|
+
output = output + String.fromCharCode(chr1);
|
69
|
+
|
70
|
+
if (enc3 != 64) {
|
71
|
+
output = output + String.fromCharCode(chr2);
|
72
|
+
}
|
73
|
+
if (enc4 != 64) {
|
74
|
+
output = output + String.fromCharCode(chr3);
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
output = Base64._utf8_decode(output);
|
80
|
+
|
81
|
+
return output;
|
82
|
+
|
83
|
+
},
|
84
|
+
|
85
|
+
// private method for UTF-8 encoding
|
86
|
+
_utf8_encode : function (string) {
|
87
|
+
string = string.replace(/\r\n/g,"\n");
|
88
|
+
var utftext = "";
|
89
|
+
|
90
|
+
for (var n = 0; n < string.length; n++) {
|
91
|
+
|
92
|
+
var c = string.charCodeAt(n);
|
93
|
+
|
94
|
+
if (c < 128) {
|
95
|
+
utftext += String.fromCharCode(c);
|
96
|
+
}
|
97
|
+
else if((c > 127) && (c < 2048)) {
|
98
|
+
utftext += String.fromCharCode((c >> 6) | 192);
|
99
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
100
|
+
}
|
101
|
+
else {
|
102
|
+
utftext += String.fromCharCode((c >> 12) | 224);
|
103
|
+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
104
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
return utftext;
|
110
|
+
},
|
111
|
+
|
112
|
+
// private method for UTF-8 decoding
|
113
|
+
_utf8_decode : function (utftext) {
|
114
|
+
var string = "";
|
115
|
+
var i = 0;
|
116
|
+
var c = c1 = c2 = 0;
|
117
|
+
|
118
|
+
while ( i < utftext.length ) {
|
119
|
+
|
120
|
+
c = utftext.charCodeAt(i);
|
121
|
+
|
122
|
+
if (c < 128) {
|
123
|
+
string += String.fromCharCode(c);
|
124
|
+
i++;
|
125
|
+
}
|
126
|
+
else if((c > 191) && (c < 224)) {
|
127
|
+
c2 = utftext.charCodeAt(i+1);
|
128
|
+
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
129
|
+
i += 2;
|
130
|
+
}
|
131
|
+
else {
|
132
|
+
c2 = utftext.charCodeAt(i+1);
|
133
|
+
c3 = utftext.charCodeAt(i+2);
|
134
|
+
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
135
|
+
i += 3;
|
136
|
+
}
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
return string;
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
@@ -0,0 +1,152 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
function sprintf( ) {
|
4
|
+
// Return a formatted string
|
5
|
+
//
|
6
|
+
// version: 903.3016
|
7
|
+
// discuss at: http://phpjs.org/functions/sprintf
|
8
|
+
// + original by: Ash Searle (http://hexmen.com/blog/)
|
9
|
+
// + namespaced by: Michael White (http://getsprink.com)
|
10
|
+
// + tweaked by: Jack
|
11
|
+
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
12
|
+
// + input by: Paulo Ricardo F. Santos
|
13
|
+
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
14
|
+
// + input by: Brett Zamir (http://brettz9.blogspot.com)
|
15
|
+
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
|
16
|
+
// * example 1: sprintf("%01.2f", 123.1);
|
17
|
+
// * returns 1: 123.10
|
18
|
+
// * example 2: sprintf("[%10s]", 'monkey');
|
19
|
+
// * returns 2: '[ monkey]'
|
20
|
+
// * example 3: sprintf("[%'#10s]", 'monkey');
|
21
|
+
// * returns 3: '[####monkey]'
|
22
|
+
var regex = /%%|%(\d+\$)?([-+\'#0 ]*)(\*\d+\$|\*|\d+)?(\.(\*\d+\$|\*|\d+))?([scboxXuidfegEG])/g;
|
23
|
+
var a = arguments, i = 0, format = a[i++];
|
24
|
+
|
25
|
+
// pad()
|
26
|
+
var pad = function(str, len, chr, leftJustify) {
|
27
|
+
if (!chr) chr = ' ';
|
28
|
+
var padding = (str.length >= len) ? '' : Array(1 + len - str.length >>> 0).join(chr);
|
29
|
+
return leftJustify ? str + padding : padding + str;
|
30
|
+
};
|
31
|
+
|
32
|
+
// justify()
|
33
|
+
var justify = function(value, prefix, leftJustify, minWidth, zeroPad, customPadChar) {
|
34
|
+
var diff = minWidth - value.length;
|
35
|
+
if (diff > 0) {
|
36
|
+
if (leftJustify || !zeroPad) {
|
37
|
+
value = pad(value, minWidth, customPadChar, leftJustify);
|
38
|
+
} else {
|
39
|
+
value = value.slice(0, prefix.length) + pad('', diff, '0', true) + value.slice(prefix.length);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
return value;
|
43
|
+
};
|
44
|
+
|
45
|
+
// formatBaseX()
|
46
|
+
var formatBaseX = function(value, base, prefix, leftJustify, minWidth, precision, zeroPad) {
|
47
|
+
// Note: casts negative numbers to positive ones
|
48
|
+
var number = value >>> 0;
|
49
|
+
prefix = prefix && number && {'2': '0b', '8': '0', '16': '0x'}[base] || '';
|
50
|
+
value = prefix + pad(number.toString(base), precision || 0, '0', false);
|
51
|
+
return justify(value, prefix, leftJustify, minWidth, zeroPad);
|
52
|
+
};
|
53
|
+
|
54
|
+
// formatString()
|
55
|
+
var formatString = function(value, leftJustify, minWidth, precision, zeroPad, customPadChar) {
|
56
|
+
if (precision != null) {
|
57
|
+
value = value.slice(0, precision);
|
58
|
+
}
|
59
|
+
return justify(value, '', leftJustify, minWidth, zeroPad, customPadChar);
|
60
|
+
};
|
61
|
+
|
62
|
+
// doFormat()
|
63
|
+
var doFormat = function(substring, valueIndex, flags, minWidth, _, precision, type) {
|
64
|
+
var number;
|
65
|
+
var prefix;
|
66
|
+
var method;
|
67
|
+
var textTransform;
|
68
|
+
var value;
|
69
|
+
|
70
|
+
if (substring == '%%') return '%';
|
71
|
+
|
72
|
+
// parse flags
|
73
|
+
var leftJustify = false, positivePrefix = '', zeroPad = false, prefixBaseX = false, customPadChar = ' ';
|
74
|
+
var flagsl = flags.length;
|
75
|
+
for (var j = 0; flags && j < flagsl; j++) switch (flags.charAt(j)) {
|
76
|
+
case ' ': positivePrefix = ' '; break;
|
77
|
+
case '+': positivePrefix = '+'; break;
|
78
|
+
case '-': leftJustify = true; break;
|
79
|
+
case "'": customPadChar = flags.charAt(j+1); break;
|
80
|
+
case '0': zeroPad = true; break;
|
81
|
+
case '#': prefixBaseX = true; break;
|
82
|
+
}
|
83
|
+
|
84
|
+
// parameters may be null, undefined, empty-string or real valued
|
85
|
+
// we want to ignore null, undefined and empty-string values
|
86
|
+
if (!minWidth) {
|
87
|
+
minWidth = 0;
|
88
|
+
} else if (minWidth == '*') {
|
89
|
+
minWidth = +a[i++];
|
90
|
+
} else if (minWidth.charAt(0) == '*') {
|
91
|
+
minWidth = +a[minWidth.slice(1, -1)];
|
92
|
+
} else {
|
93
|
+
minWidth = +minWidth;
|
94
|
+
}
|
95
|
+
|
96
|
+
// Note: undocumented perl feature:
|
97
|
+
if (minWidth < 0) {
|
98
|
+
minWidth = -minWidth;
|
99
|
+
leftJustify = true;
|
100
|
+
}
|
101
|
+
|
102
|
+
if (!isFinite(minWidth)) {
|
103
|
+
throw new Error('sprintf: (minimum-)width must be finite');
|
104
|
+
}
|
105
|
+
|
106
|
+
if (!precision) {
|
107
|
+
precision = 'fFeE'.indexOf(type) > -1 ? 6 : (type == 'd') ? 0 : void(0);
|
108
|
+
} else if (precision == '*') {
|
109
|
+
precision = +a[i++];
|
110
|
+
} else if (precision.charAt(0) == '*') {
|
111
|
+
precision = +a[precision.slice(1, -1)];
|
112
|
+
} else {
|
113
|
+
precision = +precision;
|
114
|
+
}
|
115
|
+
|
116
|
+
// grab value using valueIndex if required?
|
117
|
+
value = valueIndex ? a[valueIndex.slice(0, -1)] : a[i++];
|
118
|
+
|
119
|
+
switch (type) {
|
120
|
+
case 's': return formatString(String(value), leftJustify, minWidth, precision, zeroPad, customPadChar);
|
121
|
+
case 'c': return formatString(String.fromCharCode(+value), leftJustify, minWidth, precision, zeroPad);
|
122
|
+
case 'b': return formatBaseX(value, 2, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
|
123
|
+
case 'o': return formatBaseX(value, 8, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
|
124
|
+
case 'x': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
|
125
|
+
case 'X': return formatBaseX(value, 16, prefixBaseX, leftJustify, minWidth, precision, zeroPad).toUpperCase();
|
126
|
+
case 'u': return formatBaseX(value, 10, prefixBaseX, leftJustify, minWidth, precision, zeroPad);
|
127
|
+
case 'i':
|
128
|
+
case 'd': {
|
129
|
+
number = parseInt(+value);
|
130
|
+
prefix = number < 0 ? '-' : positivePrefix;
|
131
|
+
value = prefix + pad(String(Math.abs(number)), precision, '0', false);
|
132
|
+
return justify(value, prefix, leftJustify, minWidth, zeroPad);
|
133
|
+
}
|
134
|
+
case 'e':
|
135
|
+
case 'E':
|
136
|
+
case 'f':
|
137
|
+
case 'F':
|
138
|
+
case 'g':
|
139
|
+
case 'G': {
|
140
|
+
number = +value;
|
141
|
+
prefix = number < 0 ? '-' : positivePrefix;
|
142
|
+
method = ['toExponential', 'toFixed', 'toPrecision']['efg'.indexOf(type.toLowerCase())];
|
143
|
+
textTransform = ['toString', 'toUpperCase']['eEfFgG'.indexOf(type) % 2];
|
144
|
+
value = prefix + Math.abs(number)[method](precision);
|
145
|
+
return justify(value, prefix, leftJustify, minWidth, zeroPad)[textTransform]();
|
146
|
+
}
|
147
|
+
default: return substring;
|
148
|
+
}
|
149
|
+
};
|
150
|
+
|
151
|
+
return format.replace(regex, doFormat);
|
152
|
+
}
|
@@ -0,0 +1,2090 @@
|
|
1
|
+
/**
|
2
|
+
* @preserve tableExport.jquery.plugin
|
3
|
+
*
|
4
|
+
* Copyright (c) 2015-2017 hhurz, https://github.com/hhurz
|
5
|
+
*
|
6
|
+
* Original Work Copyright (c) 2014 Giri Raj
|
7
|
+
*
|
8
|
+
* Licensed under the MIT License
|
9
|
+
**/
|
10
|
+
|
11
|
+
(function ($) {
|
12
|
+
$.fn.extend({
|
13
|
+
tableExport: function (options) {
|
14
|
+
var defaults = {
|
15
|
+
consoleLog: false,
|
16
|
+
csvEnclosure: '"',
|
17
|
+
csvSeparator: ',',
|
18
|
+
csvUseBOM: true,
|
19
|
+
displayTableName: false,
|
20
|
+
escape: false,
|
21
|
+
excelFileFormat: 'xlshtml', // xmlss = XML Spreadsheet 2003 file format (XMLSS), xlshtml = Excel 2000 html format
|
22
|
+
excelstyles: [], // e.g. ['border-bottom', 'border-top', 'border-left', 'border-right']
|
23
|
+
fileName: 'tableExport',
|
24
|
+
htmlContent: false,
|
25
|
+
ignoreColumn: [],
|
26
|
+
ignoreRow: [],
|
27
|
+
jsonScope: 'all', // head, data, all
|
28
|
+
jspdf: {
|
29
|
+
orientation: 'p',
|
30
|
+
unit: 'pt',
|
31
|
+
format: 'a4', // jspdf page format or 'bestfit' for autmatic paper format selection
|
32
|
+
margins: {left: 20, right: 10, top: 10, bottom: 10},
|
33
|
+
onDocCreated: null,
|
34
|
+
autotable: {
|
35
|
+
styles: {
|
36
|
+
cellPadding: 2,
|
37
|
+
rowHeight: 12,
|
38
|
+
fontSize: 8,
|
39
|
+
fillColor: 255, // color value or 'inherit' to use css background-color from html table
|
40
|
+
textColor: 50, // color value or 'inherit' to use css color from html table
|
41
|
+
fontStyle: 'normal', // normal, bold, italic, bolditalic or 'inherit' to use css font-weight and fonst-style from html table
|
42
|
+
overflow: 'ellipsize', // visible, hidden, ellipsize or linebreak
|
43
|
+
halign: 'left', // left, center, right
|
44
|
+
valign: 'middle' // top, middle, bottom
|
45
|
+
},
|
46
|
+
headerStyles: {
|
47
|
+
fillColor: [52, 73, 94],
|
48
|
+
textColor: 255,
|
49
|
+
fontStyle: 'bold',
|
50
|
+
halign: 'center'
|
51
|
+
},
|
52
|
+
alternateRowStyles: {
|
53
|
+
fillColor: 245
|
54
|
+
},
|
55
|
+
tableExport: {
|
56
|
+
doc: null, // jsPDF doc object. If set, an already created doc will be used to export to
|
57
|
+
onAfterAutotable: null,
|
58
|
+
onBeforeAutotable: null,
|
59
|
+
onAutotableText: null,
|
60
|
+
onTable: null,
|
61
|
+
outputImages: true
|
62
|
+
}
|
63
|
+
}
|
64
|
+
},
|
65
|
+
numbers: {
|
66
|
+
html: {
|
67
|
+
decimalMark: '.',
|
68
|
+
thousandsSeparator: ','
|
69
|
+
},
|
70
|
+
output: // set to false to not format numbers in exported output
|
71
|
+
{
|
72
|
+
decimalMark: '.',
|
73
|
+
thousandsSeparator: ','
|
74
|
+
}
|
75
|
+
},
|
76
|
+
onCellData: null,
|
77
|
+
onCellHtmlData: null,
|
78
|
+
onMsoNumberFormat: null, // Excel 2000 html format only. See readme.md for more information about msonumberformat
|
79
|
+
outputMode: 'file', // 'file', 'string', 'base64' or 'window' (experimental)
|
80
|
+
pdfmake: {
|
81
|
+
enabled: false, // true: use pdfmake instead of jspdf and jspdf-autotable (experimental)
|
82
|
+
docDefinition: {
|
83
|
+
pageOrientation: 'portrait', // 'portrait' or 'landscape'
|
84
|
+
defaultStyle: {
|
85
|
+
font: 'Roboto' // default is 'Roboto', for arabic font set this option to 'Mirza' and include mirza_fonts.js
|
86
|
+
}
|
87
|
+
},
|
88
|
+
fonts: {}
|
89
|
+
},
|
90
|
+
tbodySelector: 'tr',
|
91
|
+
tfootSelector: 'tr', // set empty ('') to prevent export of tfoot rows
|
92
|
+
theadSelector: 'tr',
|
93
|
+
tableName: 'myTableName',
|
94
|
+
type: 'csv', // 'csv', 'tsv', 'txt', 'sql', 'json', 'xml', 'excel', 'doc', 'png' or 'pdf'
|
95
|
+
worksheetName: 'Worksheet'
|
96
|
+
};
|
97
|
+
|
98
|
+
var FONT_ROW_RATIO = 1.15;
|
99
|
+
var el = this;
|
100
|
+
var DownloadEvt = null;
|
101
|
+
var $hrows = [];
|
102
|
+
var $rows = [];
|
103
|
+
var rowIndex = 0;
|
104
|
+
var rowspans = [];
|
105
|
+
var trData = '';
|
106
|
+
var colNames = [];
|
107
|
+
var blob;
|
108
|
+
|
109
|
+
$.extend(true, defaults, options);
|
110
|
+
|
111
|
+
colNames = GetColumnNames(el);
|
112
|
+
|
113
|
+
if ( defaults.type == 'csv' || defaults.type == 'tsv' || defaults.type == 'txt' ) {
|
114
|
+
|
115
|
+
var csvData = "";
|
116
|
+
var rowlength = 0;
|
117
|
+
rowIndex = 0;
|
118
|
+
|
119
|
+
function csvString (cell, rowIndex, colIndex) {
|
120
|
+
var result = '';
|
121
|
+
|
122
|
+
if ( cell !== null ) {
|
123
|
+
var dataString = parseString(cell, rowIndex, colIndex);
|
124
|
+
|
125
|
+
var csvValue = (dataString === null || dataString === '') ? '' : dataString.toString();
|
126
|
+
|
127
|
+
if ( defaults.type == 'tsv' ) {
|
128
|
+
if ( dataString instanceof Date )
|
129
|
+
dataString.toLocaleString();
|
130
|
+
|
131
|
+
// According to http://www.iana.org/assignments/media-types/text/tab-separated-values
|
132
|
+
// are fields that contain tabs not allowable in tsv encoding
|
133
|
+
result = replaceAll(csvValue, '\t', ' ');
|
134
|
+
}
|
135
|
+
else {
|
136
|
+
// Takes a string and encapsulates it (by default in double-quotes) if it
|
137
|
+
// contains the csv field separator, spaces, or linebreaks.
|
138
|
+
if ( dataString instanceof Date )
|
139
|
+
result = defaults.csvEnclosure + dataString.toLocaleString() + defaults.csvEnclosure;
|
140
|
+
else {
|
141
|
+
result = replaceAll(csvValue, defaults.csvEnclosure, defaults.csvEnclosure + defaults.csvEnclosure);
|
142
|
+
|
143
|
+
if ( result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result) )
|
144
|
+
result = defaults.csvEnclosure + result + defaults.csvEnclosure;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
return result;
|
150
|
+
}
|
151
|
+
|
152
|
+
var CollectCsvData = function ($rows, rowselector, length) {
|
153
|
+
|
154
|
+
$rows.each(function () {
|
155
|
+
trData = "";
|
156
|
+
ForEachVisibleCell(this, rowselector, rowIndex, length + $rows.length,
|
157
|
+
function (cell, row, col) {
|
158
|
+
trData += csvString(cell, row, col) + (defaults.type == 'tsv' ? '\t' : defaults.csvSeparator);
|
159
|
+
});
|
160
|
+
trData = $.trim(trData).substring(0, trData.length - 1);
|
161
|
+
if ( trData.length > 0 ) {
|
162
|
+
|
163
|
+
if ( csvData.length > 0 )
|
164
|
+
csvData += "\n";
|
165
|
+
|
166
|
+
csvData += trData;
|
167
|
+
}
|
168
|
+
rowIndex++;
|
169
|
+
});
|
170
|
+
|
171
|
+
return $rows.length;
|
172
|
+
};
|
173
|
+
|
174
|
+
rowlength += CollectCsvData($(el).find('thead').first().find(defaults.theadSelector), 'th,td', rowlength);
|
175
|
+
$(el).find('tbody').each(function () {
|
176
|
+
rowlength += CollectCsvData($(this).find(defaults.tbodySelector), 'td,th', rowlength);
|
177
|
+
});
|
178
|
+
if ( defaults.tfootSelector.length )
|
179
|
+
CollectCsvData($(el).find('tfoot').first().find(defaults.tfootSelector), 'td,th', rowlength);
|
180
|
+
|
181
|
+
csvData += "\n";
|
182
|
+
|
183
|
+
//output
|
184
|
+
if ( defaults.consoleLog === true )
|
185
|
+
console.log(csvData);
|
186
|
+
|
187
|
+
if ( defaults.outputMode === 'string' )
|
188
|
+
return csvData;
|
189
|
+
|
190
|
+
if ( defaults.outputMode === 'base64' )
|
191
|
+
return base64encode(csvData);
|
192
|
+
|
193
|
+
if ( defaults.outputMode === 'window' ) {
|
194
|
+
downloadFile(false, 'data:text/' + (defaults.type == 'csv' ? 'csv' : 'plain') + ';charset=utf-8,', csvData);
|
195
|
+
return;
|
196
|
+
}
|
197
|
+
|
198
|
+
try {
|
199
|
+
blob = new Blob([csvData], {type: "text/" + (defaults.type == 'csv' ? 'csv' : 'plain') + ";charset=utf-8"});
|
200
|
+
saveAs(blob, defaults.fileName + '.' + defaults.type, (defaults.type != 'csv' || defaults.csvUseBOM === false));
|
201
|
+
}
|
202
|
+
catch (e) {
|
203
|
+
downloadFile(defaults.fileName + '.' + defaults.type,
|
204
|
+
'data:text/' + (defaults.type == 'csv' ? 'csv' : 'plain') + ';charset=utf-8,' + ((defaults.type == 'csv' && defaults.csvUseBOM) ? '\ufeff' : ''),
|
205
|
+
csvData);
|
206
|
+
}
|
207
|
+
|
208
|
+
} else if ( defaults.type == 'sql' ) {
|
209
|
+
|
210
|
+
// Header
|
211
|
+
rowIndex = 0;
|
212
|
+
var tdData = "INSERT INTO `" + defaults.tableName + "` (";
|
213
|
+
$hrows = $(el).find('thead').first().find(defaults.theadSelector);
|
214
|
+
$hrows.each(function () {
|
215
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
|
216
|
+
function (cell, row, col) {
|
217
|
+
tdData += "'" + parseString(cell, row, col) + "',";
|
218
|
+
});
|
219
|
+
rowIndex++;
|
220
|
+
tdData = $.trim(tdData);
|
221
|
+
tdData = $.trim(tdData).substring(0, tdData.length - 1);
|
222
|
+
});
|
223
|
+
tdData += ") VALUES ";
|
224
|
+
// Row vs Column
|
225
|
+
$(el).find('tbody').each(function () {
|
226
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
227
|
+
});
|
228
|
+
if ( defaults.tfootSelector.length )
|
229
|
+
$rows.push.apply($rows, $(el).find('tfoot').find(defaults.tfootSelector));
|
230
|
+
$($rows).each(function () {
|
231
|
+
trData = "";
|
232
|
+
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
|
233
|
+
function (cell, row, col) {
|
234
|
+
trData += "'" + parseString(cell, row, col) + "',";
|
235
|
+
});
|
236
|
+
if ( trData.length > 3 ) {
|
237
|
+
tdData += "(" + trData;
|
238
|
+
tdData = $.trim(tdData).substring(0, tdData.length - 1);
|
239
|
+
tdData += "),";
|
240
|
+
}
|
241
|
+
rowIndex++;
|
242
|
+
});
|
243
|
+
|
244
|
+
tdData = $.trim(tdData).substring(0, tdData.length - 1);
|
245
|
+
tdData += ";";
|
246
|
+
|
247
|
+
//output
|
248
|
+
if ( defaults.consoleLog === true )
|
249
|
+
console.log(tdData);
|
250
|
+
|
251
|
+
if ( defaults.outputMode === 'string' )
|
252
|
+
return tdData;
|
253
|
+
|
254
|
+
if ( defaults.outputMode === 'base64' )
|
255
|
+
return base64encode(tdData);
|
256
|
+
|
257
|
+
try {
|
258
|
+
blob = new Blob([tdData], {type: "text/plain;charset=utf-8"});
|
259
|
+
saveAs(blob, defaults.fileName + '.sql');
|
260
|
+
}
|
261
|
+
catch (e) {
|
262
|
+
downloadFile(defaults.fileName + '.sql',
|
263
|
+
'data:application/sql;charset=utf-8,',
|
264
|
+
tdData);
|
265
|
+
}
|
266
|
+
|
267
|
+
} else if ( defaults.type == 'json' ) {
|
268
|
+
var jsonHeaderArray = [];
|
269
|
+
$hrows = $(el).find('thead').first().find(defaults.theadSelector);
|
270
|
+
$hrows.each(function () {
|
271
|
+
var jsonArrayTd = [];
|
272
|
+
|
273
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
|
274
|
+
function (cell, row, col) {
|
275
|
+
jsonArrayTd.push(parseString(cell, row, col));
|
276
|
+
});
|
277
|
+
jsonHeaderArray.push(jsonArrayTd);
|
278
|
+
});
|
279
|
+
|
280
|
+
var jsonArray = [];
|
281
|
+
$(el).find('tbody').each(function () {
|
282
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
283
|
+
});
|
284
|
+
if ( defaults.tfootSelector.length )
|
285
|
+
$rows.push.apply($rows, $(el).find('tfoot').find(defaults.tfootSelector));
|
286
|
+
$($rows).each(function () {
|
287
|
+
var jsonObjectTd = {};
|
288
|
+
var colIndex = 0;
|
289
|
+
|
290
|
+
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
|
291
|
+
function (cell, row, col) {
|
292
|
+
if ( jsonHeaderArray.length ) {
|
293
|
+
jsonObjectTd[jsonHeaderArray[jsonHeaderArray.length - 1][colIndex]] = parseString(cell, row, col);
|
294
|
+
} else {
|
295
|
+
jsonObjectTd[colIndex] = parseString(cell, row, col);
|
296
|
+
}
|
297
|
+
colIndex++;
|
298
|
+
});
|
299
|
+
if ( $.isEmptyObject(jsonObjectTd) === false )
|
300
|
+
jsonArray.push(jsonObjectTd);
|
301
|
+
|
302
|
+
rowIndex++;
|
303
|
+
});
|
304
|
+
|
305
|
+
var sdata = "";
|
306
|
+
|
307
|
+
if ( defaults.jsonScope == 'head' )
|
308
|
+
sdata = JSON.stringify(jsonHeaderArray);
|
309
|
+
else if ( defaults.jsonScope == 'data' )
|
310
|
+
sdata = JSON.stringify(jsonArray);
|
311
|
+
else // all
|
312
|
+
sdata = JSON.stringify({header: jsonHeaderArray, data: jsonArray});
|
313
|
+
|
314
|
+
if ( defaults.consoleLog === true )
|
315
|
+
console.log(sdata);
|
316
|
+
|
317
|
+
if ( defaults.outputMode === 'string' )
|
318
|
+
return sdata;
|
319
|
+
|
320
|
+
if ( defaults.outputMode === 'base64' )
|
321
|
+
return base64encode(sdata);
|
322
|
+
|
323
|
+
try {
|
324
|
+
blob = new Blob([sdata], {type: "application/json;charset=utf-8"});
|
325
|
+
saveAs(blob, defaults.fileName + '.json');
|
326
|
+
}
|
327
|
+
catch (e) {
|
328
|
+
downloadFile(defaults.fileName + '.json',
|
329
|
+
'data:application/json;charset=utf-8;base64,',
|
330
|
+
sdata);
|
331
|
+
}
|
332
|
+
|
333
|
+
} else if ( defaults.type === 'xml' ) {
|
334
|
+
|
335
|
+
rowIndex = 0;
|
336
|
+
var xml = '<?xml version="1.0" encoding="utf-8"?>';
|
337
|
+
xml += '<tabledata><fields>';
|
338
|
+
|
339
|
+
// Header
|
340
|
+
$hrows = $(el).find('thead').first().find(defaults.theadSelector);
|
341
|
+
$hrows.each(function () {
|
342
|
+
|
343
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
|
344
|
+
function (cell, row, col) {
|
345
|
+
xml += "<field>" + parseString(cell, row, col) + "</field>";
|
346
|
+
});
|
347
|
+
rowIndex++;
|
348
|
+
});
|
349
|
+
xml += '</fields><data>';
|
350
|
+
|
351
|
+
// Row Vs Column
|
352
|
+
var rowCount = 1;
|
353
|
+
$(el).find('tbody').each(function () {
|
354
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
355
|
+
});
|
356
|
+
if ( defaults.tfootSelector.length )
|
357
|
+
$rows.push.apply($rows, $(el).find('tfoot').find(defaults.tfootSelector));
|
358
|
+
$($rows).each(function () {
|
359
|
+
var colCount = 1;
|
360
|
+
trData = "";
|
361
|
+
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
|
362
|
+
function (cell, row, col) {
|
363
|
+
trData += "<column-" + colCount + ">" + parseString(cell, row, col) + "</column-" + colCount + ">";
|
364
|
+
colCount++;
|
365
|
+
});
|
366
|
+
if ( trData.length > 0 && trData != "<column-1></column-1>" ) {
|
367
|
+
xml += '<row id="' + rowCount + '">' + trData + '</row>';
|
368
|
+
rowCount++;
|
369
|
+
}
|
370
|
+
|
371
|
+
rowIndex++;
|
372
|
+
});
|
373
|
+
xml += '</data></tabledata>';
|
374
|
+
|
375
|
+
//output
|
376
|
+
if ( defaults.consoleLog === true )
|
377
|
+
console.log(xml);
|
378
|
+
|
379
|
+
if ( defaults.outputMode === 'string' )
|
380
|
+
return xml;
|
381
|
+
|
382
|
+
if ( defaults.outputMode === 'base64' )
|
383
|
+
return base64encode(xml);
|
384
|
+
|
385
|
+
try {
|
386
|
+
blob = new Blob([xml], {type: "application/xml;charset=utf-8"});
|
387
|
+
saveAs(blob, defaults.fileName + '.xml');
|
388
|
+
}
|
389
|
+
catch (e) {
|
390
|
+
downloadFile(defaults.fileName + '.xml',
|
391
|
+
'data:application/xml;charset=utf-8;base64,',
|
392
|
+
xml);
|
393
|
+
}
|
394
|
+
}
|
395
|
+
else if ( defaults.type === 'excel' && defaults.excelFileFormat === 'xmlss' ) {
|
396
|
+
var docDatas = [];
|
397
|
+
|
398
|
+
$(el).filter(function () {
|
399
|
+
return $(this).data("tableexport-display") != 'none' &&
|
400
|
+
($(this).is(':visible') ||
|
401
|
+
$(this).data("tableexport-display") == 'always');
|
402
|
+
}).each(function () {
|
403
|
+
var $table = $(this);
|
404
|
+
var docData = '';
|
405
|
+
rowIndex = 0;
|
406
|
+
colNames = GetColumnNames(this);
|
407
|
+
$hrows = $table.find('thead').first().find(defaults.theadSelector);
|
408
|
+
docData += '<Table>';
|
409
|
+
|
410
|
+
// Header
|
411
|
+
var cols = 0;
|
412
|
+
$hrows.each(function () {
|
413
|
+
trData = "";
|
414
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
|
415
|
+
function (cell, row, col) {
|
416
|
+
if ( cell !== null ) {
|
417
|
+
trData += '<Cell><Data ss:Type="String">' + parseString(cell, row, col) + '</Data></Cell>';
|
418
|
+
cols++;
|
419
|
+
}
|
420
|
+
});
|
421
|
+
if ( trData.length > 0 )
|
422
|
+
docData += '<Row>' + trData + '</Row>';
|
423
|
+
rowIndex++;
|
424
|
+
});
|
425
|
+
|
426
|
+
// Row Vs Column, support multiple tbodys
|
427
|
+
$rows = [];
|
428
|
+
$table.find('tbody').each(function () {
|
429
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
430
|
+
});
|
431
|
+
|
432
|
+
//if (defaults.tfootSelector.length)
|
433
|
+
// $rows.push.apply($rows, $table.find('tfoot').find(defaults.tfootSelector));
|
434
|
+
|
435
|
+
$($rows).each(function () {
|
436
|
+
trData = "";
|
437
|
+
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
|
438
|
+
function (cell, row, col) {
|
439
|
+
if ( cell !== null ) {
|
440
|
+
var type = "String";
|
441
|
+
var style = "";
|
442
|
+
var data = parseString(cell, row, col);
|
443
|
+
|
444
|
+
if ( jQuery.isNumeric(data) !== false ) {
|
445
|
+
type = "Number";
|
446
|
+
}
|
447
|
+
else {
|
448
|
+
var number = parsePercent(data);
|
449
|
+
if ( number !== false ) {
|
450
|
+
data = number;
|
451
|
+
type = "Number";
|
452
|
+
style = ' ss:StyleID="pct1"';
|
453
|
+
}
|
454
|
+
}
|
455
|
+
|
456
|
+
if ( type !== "Number" )
|
457
|
+
data = data.replace(/\n/g, '<br>');
|
458
|
+
|
459
|
+
trData += '<Cell' + style + '><Data ss:Type="' + type + '">' + data + '</Data></Cell>';
|
460
|
+
}
|
461
|
+
});
|
462
|
+
if ( trData.length > 0 )
|
463
|
+
docData += '<Row>' + trData + '</Row>';
|
464
|
+
rowIndex++;
|
465
|
+
});
|
466
|
+
|
467
|
+
docData += '</Table>';
|
468
|
+
docDatas.push(docData);
|
469
|
+
|
470
|
+
if ( defaults.consoleLog === true )
|
471
|
+
console.log(docData);
|
472
|
+
});
|
473
|
+
|
474
|
+
var CreationDate = new Date().toISOString();
|
475
|
+
var xmlssDocFile = '<?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?> ' +
|
476
|
+
'<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" ' +
|
477
|
+
'xmlns:o="urn:schemas-microsoft-com:office:office" ' +
|
478
|
+
'xmlns:x="urn:schemas-microsoft-com:office:excel" ' +
|
479
|
+
'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ' +
|
480
|
+
'xmlns:html="http://www.w3.org/TR/REC-html40"> ' +
|
481
|
+
'<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> ' +
|
482
|
+
'<Created>' + CreationDate + '</Created> ' +
|
483
|
+
'</DocumentProperties> ' +
|
484
|
+
'<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office"> ' +
|
485
|
+
'<AllowPNG/> ' +
|
486
|
+
'</OfficeDocumentSettings> ' +
|
487
|
+
'<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> ' +
|
488
|
+
'<WindowHeight>9000</WindowHeight> ' +
|
489
|
+
'<WindowWidth>13860</WindowWidth> ' +
|
490
|
+
'<WindowTopX>0</WindowTopX> ' +
|
491
|
+
'<WindowTopY>0</WindowTopY> ' +
|
492
|
+
'<ProtectStructure>False</ProtectStructure> ' +
|
493
|
+
'<ProtectWindows>False</ProtectWindows> ' +
|
494
|
+
'</ExcelWorkbook> ' +
|
495
|
+
'<Styles> ' +
|
496
|
+
'<Style ss:ID="Default" ss:Name="Default"> ' +
|
497
|
+
'<Alignment ss:Vertical="Center"/> ' +
|
498
|
+
'<Borders/> ' +
|
499
|
+
'<Font/> ' +
|
500
|
+
'<Interior/> ' +
|
501
|
+
'<NumberFormat/> ' +
|
502
|
+
'<Protection/> ' +
|
503
|
+
'</Style> ' +
|
504
|
+
'<Style ss:ID="Normal" ss:Name="Normal"/> ' +
|
505
|
+
'<Style ss:ID="pct1"> ' +
|
506
|
+
' <NumberFormat ss:Format="Percent"/> ' +
|
507
|
+
'</Style> ' +
|
508
|
+
'</Styles>';
|
509
|
+
|
510
|
+
for ( var j = 0; j < docDatas.length; j++ ) {
|
511
|
+
var ssName = typeof defaults.worksheetName === 'string' ? defaults.worksheetName + ' ' + (j + 1) :
|
512
|
+
typeof defaults.worksheetName[j] !== 'undefined' ? defaults.worksheetName[j] :
|
513
|
+
'Table ' + (j + 1);
|
514
|
+
|
515
|
+
xmlssDocFile += '<Worksheet ss:Name="' + ssName + '">' +
|
516
|
+
docDatas[j] +
|
517
|
+
'<WorksheetOptions/> ' +
|
518
|
+
'</Worksheet>';
|
519
|
+
}
|
520
|
+
|
521
|
+
xmlssDocFile += '</Workbook>';
|
522
|
+
|
523
|
+
if ( defaults.consoleLog === true )
|
524
|
+
console.log(xmlssDocFile);
|
525
|
+
|
526
|
+
if ( defaults.outputMode === 'string' )
|
527
|
+
return xmlssDocFile;
|
528
|
+
|
529
|
+
if ( defaults.outputMode === 'base64' )
|
530
|
+
return base64encode(xmlssDocFile);
|
531
|
+
|
532
|
+
try {
|
533
|
+
blob = new Blob([xmlssDocFile], {type: "application/xml;charset=utf-8"});
|
534
|
+
saveAs(blob, defaults.fileName + '.xml');
|
535
|
+
}
|
536
|
+
catch (e) {
|
537
|
+
downloadFile(defaults.fileName + '.xml',
|
538
|
+
'data:application/xml;charset=utf-8;base64,',
|
539
|
+
xmlssDocFile);
|
540
|
+
}
|
541
|
+
}
|
542
|
+
else if ( defaults.type == 'excel' || defaults.type == 'xls' || defaults.type == 'word' || defaults.type == 'doc' ) {
|
543
|
+
|
544
|
+
var MSDocType = (defaults.type == 'excel' || defaults.type == 'xls') ? 'excel' : 'word';
|
545
|
+
var MSDocExt = (MSDocType == 'excel') ? 'xls' : 'doc';
|
546
|
+
var MSDocSchema = 'xmlns:x="urn:schemas-microsoft-com:office:' + MSDocType + '"';
|
547
|
+
var docData = '';
|
548
|
+
|
549
|
+
$(el).filter(function () {
|
550
|
+
return $(this).data("tableexport-display") != 'none' &&
|
551
|
+
($(this).is(':visible') ||
|
552
|
+
$(this).data("tableexport-display") == 'always');
|
553
|
+
}).each(function () {
|
554
|
+
var $table = $(this);
|
555
|
+
rowIndex = 0;
|
556
|
+
colNames = GetColumnNames(this);
|
557
|
+
|
558
|
+
// Header
|
559
|
+
docData += '<table><thead>';
|
560
|
+
$hrows = $table.find('thead').first().find(defaults.theadSelector);
|
561
|
+
$hrows.each(function () {
|
562
|
+
trData = "";
|
563
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
|
564
|
+
function (cell, row, col) {
|
565
|
+
if ( cell !== null ) {
|
566
|
+
var thstyle = '';
|
567
|
+
trData += '<th';
|
568
|
+
for ( var styles in defaults.excelstyles ) {
|
569
|
+
if ( defaults.excelstyles.hasOwnProperty(styles) ) {
|
570
|
+
var thcss = $(cell).css(defaults.excelstyles[styles]);
|
571
|
+
if ( thcss !== '' && thcss != '0px none rgb(0, 0, 0)' && thcss != 'rgba(0, 0, 0, 0)' ) {
|
572
|
+
thstyle += (thstyle === '') ? 'style="' : ';';
|
573
|
+
thstyle += defaults.excelstyles[styles] + ':' + thcss;
|
574
|
+
}
|
575
|
+
}
|
576
|
+
}
|
577
|
+
if ( thstyle !== '' )
|
578
|
+
trData += ' ' + thstyle + '"';
|
579
|
+
if ( $(cell).is("[colspan]") )
|
580
|
+
trData += ' colspan="' + $(cell).attr('colspan') + '"';
|
581
|
+
if ( $(cell).is("[rowspan]") )
|
582
|
+
trData += ' rowspan="' + $(cell).attr('rowspan') + '"';
|
583
|
+
trData += '>' + parseString(cell, row, col) + '</th>';
|
584
|
+
}
|
585
|
+
});
|
586
|
+
if ( trData.length > 0 )
|
587
|
+
docData += '<tr>' + trData + '</tr>';
|
588
|
+
rowIndex++;
|
589
|
+
});
|
590
|
+
|
591
|
+
docData += '</thead><tbody>';
|
592
|
+
// Row Vs Column, support multiple tbodys
|
593
|
+
$table.find('tbody').each(function () {
|
594
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
595
|
+
});
|
596
|
+
if ( defaults.tfootSelector.length )
|
597
|
+
$rows.push.apply($rows, $table.find('tfoot').find(defaults.tfootSelector));
|
598
|
+
|
599
|
+
$($rows).each(function () {
|
600
|
+
var $row = $(this);
|
601
|
+
trData = "";
|
602
|
+
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
|
603
|
+
function (cell, row, col) {
|
604
|
+
if ( cell !== null ) {
|
605
|
+
var tdstyle = '';
|
606
|
+
var tdcss = $(cell).data("tableexport-msonumberformat");
|
607
|
+
|
608
|
+
if ( typeof tdcss == 'undefined' && typeof defaults.onMsoNumberFormat === 'function' )
|
609
|
+
tdcss = defaults.onMsoNumberFormat(cell, row, col);
|
610
|
+
|
611
|
+
if ( typeof tdcss != 'undefined' && tdcss !== '' )
|
612
|
+
tdstyle = 'style="mso-number-format:\'' + tdcss + '\'';
|
613
|
+
|
614
|
+
for ( var cssStyle in defaults.excelstyles ) {
|
615
|
+
if ( defaults.excelstyles.hasOwnProperty(cssStyle) ) {
|
616
|
+
tdcss = $(cell).css(defaults.excelstyles[cssStyle]);
|
617
|
+
if ( tdcss === '' )
|
618
|
+
tdcss = $row.css(defaults.excelstyles[cssStyle]);
|
619
|
+
|
620
|
+
if ( tdcss !== '' && tdcss != '0px none rgb(0, 0, 0)' && tdcss != 'rgba(0, 0, 0, 0)' ) {
|
621
|
+
tdstyle += (tdstyle === '') ? 'style="' : ';';
|
622
|
+
tdstyle += defaults.excelstyles[cssStyle] + ':' + tdcss;
|
623
|
+
}
|
624
|
+
}
|
625
|
+
}
|
626
|
+
trData += '<td';
|
627
|
+
if ( tdstyle !== '' )
|
628
|
+
trData += ' ' + tdstyle + '"';
|
629
|
+
if ( $(cell).is("[colspan]") )
|
630
|
+
trData += ' colspan="' + $(cell).attr('colspan') + '"';
|
631
|
+
if ( $(cell).is("[rowspan]") )
|
632
|
+
trData += ' rowspan="' + $(cell).attr('rowspan') + '"';
|
633
|
+
trData += '>' + parseString(cell, row, col).replace(/\n/g, '<br>') + '</td>';
|
634
|
+
}
|
635
|
+
});
|
636
|
+
if ( trData.length > 0 )
|
637
|
+
docData += '<tr>' + trData + '</tr>';
|
638
|
+
rowIndex++;
|
639
|
+
});
|
640
|
+
|
641
|
+
if ( defaults.displayTableName )
|
642
|
+
docData += '<tr><td></td></tr><tr><td></td></tr><tr><td>' + parseString($('<p>' + defaults.tableName + '</p>')) + '</td></tr>';
|
643
|
+
|
644
|
+
docData += '</tbody></table>';
|
645
|
+
|
646
|
+
if ( defaults.consoleLog === true )
|
647
|
+
console.log(docData);
|
648
|
+
});
|
649
|
+
|
650
|
+
//noinspection XmlUnusedNamespaceDeclaration
|
651
|
+
var docFile = '<html xmlns:o="urn:schemas-microsoft-com:office:office" ' + MSDocSchema + ' xmlns="http://www.w3.org/TR/REC-html40">';
|
652
|
+
docFile += '<meta http-equiv="content-type" content="application/vnd.ms-' + MSDocType + '; charset=UTF-8">';
|
653
|
+
docFile += "<head>";
|
654
|
+
if ( MSDocType === 'excel' ) {
|
655
|
+
docFile += "<!--[if gte mso 9]>";
|
656
|
+
docFile += "<xml>";
|
657
|
+
docFile += "<x:ExcelWorkbook>";
|
658
|
+
docFile += "<x:ExcelWorksheets>";
|
659
|
+
docFile += "<x:ExcelWorksheet>";
|
660
|
+
docFile += "<x:Name>";
|
661
|
+
docFile += defaults.worksheetName;
|
662
|
+
docFile += "</x:Name>";
|
663
|
+
docFile += "<x:WorksheetOptions>";
|
664
|
+
docFile += "<x:DisplayGridlines/>";
|
665
|
+
docFile += "</x:WorksheetOptions>";
|
666
|
+
docFile += "</x:ExcelWorksheet>";
|
667
|
+
docFile += "</x:ExcelWorksheets>";
|
668
|
+
docFile += "</x:ExcelWorkbook>";
|
669
|
+
docFile += "</xml>";
|
670
|
+
docFile += "<![endif]-->";
|
671
|
+
}
|
672
|
+
docFile += "<style>br {mso-data-placement:same-cell;}</style>";
|
673
|
+
docFile += "</head>";
|
674
|
+
docFile += "<body>";
|
675
|
+
docFile += docData;
|
676
|
+
docFile += "</body>";
|
677
|
+
docFile += "</html>";
|
678
|
+
|
679
|
+
if ( defaults.consoleLog === true )
|
680
|
+
console.log(docFile);
|
681
|
+
|
682
|
+
if ( defaults.outputMode === 'string' )
|
683
|
+
return docFile;
|
684
|
+
|
685
|
+
if ( defaults.outputMode === 'base64' )
|
686
|
+
return base64encode(docFile);
|
687
|
+
|
688
|
+
try {
|
689
|
+
blob = new Blob([docFile], {type: 'application/vnd.ms-' + defaults.type});
|
690
|
+
saveAs(blob, defaults.fileName + '.' + MSDocExt);
|
691
|
+
}
|
692
|
+
catch (e) {
|
693
|
+
downloadFile(defaults.fileName + '.' + MSDocExt,
|
694
|
+
'data:application/vnd.ms-' + MSDocType + ';base64,',
|
695
|
+
docFile);
|
696
|
+
}
|
697
|
+
|
698
|
+
} else if ( defaults.type == 'xlsx' ) {
|
699
|
+
|
700
|
+
var data = [];
|
701
|
+
var ranges = [];
|
702
|
+
rowIndex = 0;
|
703
|
+
|
704
|
+
$rows = $(el).find('thead').first().find(defaults.theadSelector);
|
705
|
+
$(el).find('tbody').each(function () {
|
706
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
707
|
+
});
|
708
|
+
if ( defaults.tfootSelector.length )
|
709
|
+
$rows.push.apply($rows, $(el).find('tfoot').find(defaults.tfootSelector));
|
710
|
+
|
711
|
+
$($rows).each(function () {
|
712
|
+
var cols = [];
|
713
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $rows.length,
|
714
|
+
function (cell, row, col) {
|
715
|
+
if ( typeof cell !== 'undefined' && cell !== null ) {
|
716
|
+
|
717
|
+
var colspan = parseInt(cell.getAttribute('colspan'));
|
718
|
+
var rowspan = parseInt(cell.getAttribute('rowspan'));
|
719
|
+
|
720
|
+
var cellValue = parseString(cell, row, col);
|
721
|
+
|
722
|
+
if ( cellValue !== "" && cellValue == +cellValue ) cellValue = +cellValue;
|
723
|
+
|
724
|
+
//Skip ranges
|
725
|
+
ranges.forEach(function (range) {
|
726
|
+
if ( rowIndex >= range.s.r && rowIndex <= range.e.r && cols.length >= range.s.c && cols.length <= range.e.c ) {
|
727
|
+
for ( var i = 0; i <= range.e.c - range.s.c; ++i ) cols.push(null);
|
728
|
+
}
|
729
|
+
});
|
730
|
+
|
731
|
+
//Handle Row Span
|
732
|
+
if ( rowspan || colspan ) {
|
733
|
+
rowspan = rowspan || 1;
|
734
|
+
colspan = colspan || 1;
|
735
|
+
ranges.push({
|
736
|
+
s: {r: rowIndex, c: cols.length},
|
737
|
+
e: {r: rowIndex + rowspan - 1, c: cols.length + colspan - 1}
|
738
|
+
});
|
739
|
+
}
|
740
|
+
|
741
|
+
//Handle Value
|
742
|
+
cols.push(cellValue !== "" ? cellValue : null);
|
743
|
+
|
744
|
+
//Handle Colspan
|
745
|
+
if ( colspan ) for ( var k = 0; k < colspan - 1; ++k ) cols.push(null);
|
746
|
+
}
|
747
|
+
});
|
748
|
+
data.push(cols);
|
749
|
+
rowIndex++;
|
750
|
+
});
|
751
|
+
|
752
|
+
//noinspection JSPotentiallyInvalidConstructorUsage
|
753
|
+
var wb = new jx_Workbook(),
|
754
|
+
ws = jx_createSheet(data);
|
755
|
+
|
756
|
+
// add ranges to worksheet
|
757
|
+
ws['!merges'] = ranges;
|
758
|
+
|
759
|
+
// add worksheet to workbook
|
760
|
+
wb.SheetNames.push(defaults.worksheetName);
|
761
|
+
wb.Sheets[defaults.worksheetName] = ws;
|
762
|
+
|
763
|
+
var wbout = XLSX.write(wb, {bookType: defaults.type, bookSST: false, type: 'binary'});
|
764
|
+
|
765
|
+
try {
|
766
|
+
blob = new Blob([jx_s2ab(wbout)], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8'});
|
767
|
+
saveAs(blob, defaults.fileName + '.' + defaults.type);
|
768
|
+
}
|
769
|
+
catch (e) {
|
770
|
+
downloadFile(defaults.fileName + '.' + defaults.type,
|
771
|
+
'data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8,',
|
772
|
+
jx_s2ab(wbout));
|
773
|
+
}
|
774
|
+
|
775
|
+
} else if ( defaults.type == 'png' ) {
|
776
|
+
//html2canvas($(el)[0], {
|
777
|
+
// onrendered: function (canvas) {
|
778
|
+
html2canvas($(el)[0]).then(
|
779
|
+
function (canvas) {
|
780
|
+
|
781
|
+
var image = canvas.toDataURL();
|
782
|
+
var byteString = atob(image.substring(22)); // remove data stuff
|
783
|
+
var buffer = new ArrayBuffer(byteString.length);
|
784
|
+
var intArray = new Uint8Array(buffer);
|
785
|
+
|
786
|
+
for ( var i = 0; i < byteString.length; i++ )
|
787
|
+
intArray[i] = byteString.charCodeAt(i);
|
788
|
+
|
789
|
+
if ( defaults.consoleLog === true )
|
790
|
+
console.log(byteString);
|
791
|
+
|
792
|
+
if ( defaults.outputMode === 'string' )
|
793
|
+
return byteString;
|
794
|
+
|
795
|
+
if ( defaults.outputMode === 'base64' )
|
796
|
+
return base64encode(image);
|
797
|
+
|
798
|
+
if ( defaults.outputMode === 'window' ) {
|
799
|
+
window.open(image);
|
800
|
+
return;
|
801
|
+
}
|
802
|
+
|
803
|
+
try {
|
804
|
+
blob = new Blob([buffer], {type: "image/png"});
|
805
|
+
saveAs(blob, defaults.fileName + '.png');
|
806
|
+
}
|
807
|
+
catch (e) {
|
808
|
+
downloadFile(defaults.fileName + '.png', 'data:image/png,', blob);
|
809
|
+
}
|
810
|
+
//}
|
811
|
+
});
|
812
|
+
|
813
|
+
} else if ( defaults.type == 'pdf' ) {
|
814
|
+
|
815
|
+
if ( defaults.pdfmake.enabled === true ) {
|
816
|
+
// pdf output using pdfmake
|
817
|
+
// https://github.com/bpampuch/pdfmake
|
818
|
+
|
819
|
+
var widths = [];
|
820
|
+
var body = [];
|
821
|
+
rowIndex = 0;
|
822
|
+
|
823
|
+
var CollectPdfmakeData = function ($rows, colselector, length) {
|
824
|
+
var rlength = 0;
|
825
|
+
|
826
|
+
$($rows).each(function () {
|
827
|
+
var r = [];
|
828
|
+
|
829
|
+
ForEachVisibleCell(this, colselector, rowIndex, length,
|
830
|
+
function (cell, row, col) {
|
831
|
+
if ( typeof cell !== 'undefined' && cell !== null ) {
|
832
|
+
|
833
|
+
var colspan = parseInt(cell.getAttribute('colspan'));
|
834
|
+
var rowspan = parseInt(cell.getAttribute('rowspan'));
|
835
|
+
|
836
|
+
var cellValue = parseString(cell, row, col) || " ";
|
837
|
+
|
838
|
+
if ( colspan > 1 || rowspan > 1 ) {
|
839
|
+
colspan = colspan || 1;
|
840
|
+
rowspan = rowspan || 1;
|
841
|
+
r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue});
|
842
|
+
}
|
843
|
+
else
|
844
|
+
r.push(cellValue);
|
845
|
+
}
|
846
|
+
else
|
847
|
+
r.push(" ");
|
848
|
+
});
|
849
|
+
|
850
|
+
if ( r.length )
|
851
|
+
body.push(r);
|
852
|
+
|
853
|
+
if ( rlength < r.length )
|
854
|
+
rlength = r.length;
|
855
|
+
|
856
|
+
rowIndex++;
|
857
|
+
});
|
858
|
+
|
859
|
+
return rlength;
|
860
|
+
};
|
861
|
+
|
862
|
+
$hrows = $(this).find('thead').first().find(defaults.theadSelector);
|
863
|
+
|
864
|
+
var colcount = CollectPdfmakeData($hrows, 'th,td', $hrows.length);
|
865
|
+
|
866
|
+
for ( var i = widths.length; i < colcount; i++ )
|
867
|
+
widths.push("*");
|
868
|
+
|
869
|
+
$(this).find('tbody').each(function () {
|
870
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
871
|
+
});
|
872
|
+
if ( defaults.tfootSelector.length )
|
873
|
+
$rows.push.apply($rows, $(this).find('tfoot').find(defaults.tfootSelector));
|
874
|
+
|
875
|
+
CollectPdfmakeData($rows, 'th,td', $hrows.length + $rows.length);
|
876
|
+
|
877
|
+
var docDefinition = {
|
878
|
+
content: [{
|
879
|
+
table: {
|
880
|
+
headerRows: $hrows.length,
|
881
|
+
widths: widths,
|
882
|
+
body: body
|
883
|
+
}
|
884
|
+
}]
|
885
|
+
};
|
886
|
+
|
887
|
+
$.extend(true, docDefinition, defaults.pdfmake.docDefinition);
|
888
|
+
|
889
|
+
pdfMake.fonts = {
|
890
|
+
Roboto: {
|
891
|
+
normal: 'Roboto-Regular.ttf',
|
892
|
+
bold: 'Roboto-Medium.ttf',
|
893
|
+
italics: 'Roboto-Italic.ttf',
|
894
|
+
bolditalics: 'Roboto-MediumItalic.ttf'
|
895
|
+
}
|
896
|
+
};
|
897
|
+
|
898
|
+
$.extend(true, pdfMake.fonts, defaults.pdfmake.fonts);
|
899
|
+
|
900
|
+
pdfMake.createPdf(docDefinition).getBuffer(function (buffer) {
|
901
|
+
|
902
|
+
try {
|
903
|
+
var blob = new Blob([buffer], {type: "application/pdf"});
|
904
|
+
saveAs(blob, defaults.fileName + '.pdf');
|
905
|
+
}
|
906
|
+
catch (e) {
|
907
|
+
downloadFile(defaults.fileName + '.pdf',
|
908
|
+
'data:application/pdf;base64,',
|
909
|
+
buffer);
|
910
|
+
}
|
911
|
+
});
|
912
|
+
|
913
|
+
}
|
914
|
+
else if ( defaults.jspdf.autotable === false ) {
|
915
|
+
// pdf output using jsPDF's core html support
|
916
|
+
|
917
|
+
var addHtmlOptions = {
|
918
|
+
dim: {
|
919
|
+
w: getPropertyUnitValue($(el).first().get(0), 'width', 'mm'),
|
920
|
+
h: getPropertyUnitValue($(el).first().get(0), 'height', 'mm')
|
921
|
+
},
|
922
|
+
pagesplit: false
|
923
|
+
};
|
924
|
+
|
925
|
+
var doc = new jsPDF(defaults.jspdf.orientation, defaults.jspdf.unit, defaults.jspdf.format);
|
926
|
+
doc.addHTML($(el).first(),
|
927
|
+
defaults.jspdf.margins.left,
|
928
|
+
defaults.jspdf.margins.top,
|
929
|
+
addHtmlOptions,
|
930
|
+
function () {
|
931
|
+
jsPdfOutput(doc, false);
|
932
|
+
});
|
933
|
+
//delete doc;
|
934
|
+
}
|
935
|
+
else {
|
936
|
+
// pdf output using jsPDF AutoTable plugin
|
937
|
+
// https://github.com/simonbengtsson/jsPDF-AutoTable
|
938
|
+
|
939
|
+
var teOptions = defaults.jspdf.autotable.tableExport;
|
940
|
+
|
941
|
+
// When setting jspdf.format to 'bestfit' tableExport tries to choose
|
942
|
+
// the minimum required paper format and orientation in which the table
|
943
|
+
// (or tables in multitable mode) completely fits without column adjustment
|
944
|
+
if ( typeof defaults.jspdf.format === 'string' && defaults.jspdf.format.toLowerCase() === 'bestfit' ) {
|
945
|
+
var pageFormats = {
|
946
|
+
'a0': [2383.94, 3370.39], 'a1': [1683.78, 2383.94],
|
947
|
+
'a2': [1190.55, 1683.78], 'a3': [841.89, 1190.55],
|
948
|
+
'a4': [595.28, 841.89]
|
949
|
+
};
|
950
|
+
var rk = '', ro = '';
|
951
|
+
var mw = 0;
|
952
|
+
|
953
|
+
$(el).filter(':visible').each(function () {
|
954
|
+
if ( $(this).css('display') != 'none' ) {
|
955
|
+
var w = getPropertyUnitValue($(this).get(0), 'width', 'pt');
|
956
|
+
|
957
|
+
if ( w > mw ) {
|
958
|
+
if ( w > pageFormats.a0[0] ) {
|
959
|
+
rk = 'a0';
|
960
|
+
ro = 'l';
|
961
|
+
}
|
962
|
+
for ( var key in pageFormats ) {
|
963
|
+
if ( pageFormats.hasOwnProperty(key) ) {
|
964
|
+
if ( pageFormats[key][1] > w ) {
|
965
|
+
rk = key;
|
966
|
+
ro = 'l';
|
967
|
+
if ( pageFormats[key][0] > w )
|
968
|
+
ro = 'p';
|
969
|
+
}
|
970
|
+
}
|
971
|
+
}
|
972
|
+
mw = w;
|
973
|
+
}
|
974
|
+
}
|
975
|
+
});
|
976
|
+
defaults.jspdf.format = (rk === '' ? 'a4' : rk);
|
977
|
+
defaults.jspdf.orientation = (ro === '' ? 'w' : ro);
|
978
|
+
}
|
979
|
+
|
980
|
+
// The jsPDF doc object is stored in defaults.jspdf.autotable.tableExport,
|
981
|
+
// thus it can be accessed from any callback function
|
982
|
+
if ( teOptions.doc == null ) {
|
983
|
+
teOptions.doc = new jsPDF(defaults.jspdf.orientation,
|
984
|
+
defaults.jspdf.unit,
|
985
|
+
defaults.jspdf.format);
|
986
|
+
|
987
|
+
if ( typeof defaults.jspdf.onDocCreated === 'function' )
|
988
|
+
defaults.jspdf.onDocCreated(teOptions.doc);
|
989
|
+
}
|
990
|
+
|
991
|
+
if ( teOptions.outputImages === true )
|
992
|
+
teOptions.images = {};
|
993
|
+
|
994
|
+
if ( typeof teOptions.images != 'undefined' ) {
|
995
|
+
$(el).filter(function () {
|
996
|
+
return $(this).data("tableexport-display") != 'none' &&
|
997
|
+
($(this).is(':visible') ||
|
998
|
+
$(this).data("tableexport-display") == 'always');
|
999
|
+
}).each(function () {
|
1000
|
+
var rowCount = 0;
|
1001
|
+
|
1002
|
+
$hrows = $(this).find('thead').find(defaults.theadSelector);
|
1003
|
+
$(this).find('tbody').each(function () {
|
1004
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
1005
|
+
});
|
1006
|
+
if ( defaults.tfootSelector.length )
|
1007
|
+
$rows.push.apply($rows, $(this).find('tfoot').find(defaults.tfootSelector));
|
1008
|
+
|
1009
|
+
$($rows).each(function () {
|
1010
|
+
ForEachVisibleCell(this, 'td,th', $hrows.length + rowCount, $hrows.length + $rows.length,
|
1011
|
+
function (cell) {
|
1012
|
+
if ( typeof cell !== 'undefined' && cell !== null ) {
|
1013
|
+
var kids = $(cell).children();
|
1014
|
+
if ( typeof kids != 'undefined' && kids.length > 0 )
|
1015
|
+
collectImages(cell, kids, teOptions);
|
1016
|
+
}
|
1017
|
+
});
|
1018
|
+
rowCount++;
|
1019
|
+
});
|
1020
|
+
});
|
1021
|
+
|
1022
|
+
$hrows = [];
|
1023
|
+
$rows = [];
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
loadImages(teOptions, function () {
|
1027
|
+
$(el).filter(function () {
|
1028
|
+
return $(this).data("tableexport-display") != 'none' &&
|
1029
|
+
($(this).is(':visible') ||
|
1030
|
+
$(this).data("tableexport-display") == 'always');
|
1031
|
+
}).each(function () {
|
1032
|
+
var colKey;
|
1033
|
+
var rowIndex = 0;
|
1034
|
+
|
1035
|
+
colNames = GetColumnNames(this);
|
1036
|
+
|
1037
|
+
teOptions.columns = [];
|
1038
|
+
teOptions.rows = [];
|
1039
|
+
teOptions.rowoptions = {};
|
1040
|
+
|
1041
|
+
// onTable: optional callback function for every matching table that can be used
|
1042
|
+
// to modify the tableExport options or to skip the output of a particular table
|
1043
|
+
// if the table selector targets multiple tables
|
1044
|
+
if ( typeof teOptions.onTable === 'function' )
|
1045
|
+
if ( teOptions.onTable($(this), defaults) === false )
|
1046
|
+
return true; // continue to next iteration step (table)
|
1047
|
+
|
1048
|
+
// each table works with an own copy of AutoTable options
|
1049
|
+
defaults.jspdf.autotable.tableExport = null; // avoid deep recursion error
|
1050
|
+
var atOptions = $.extend(true, {}, defaults.jspdf.autotable);
|
1051
|
+
defaults.jspdf.autotable.tableExport = teOptions;
|
1052
|
+
|
1053
|
+
atOptions.margin = {};
|
1054
|
+
$.extend(true, atOptions.margin, defaults.jspdf.margins);
|
1055
|
+
atOptions.tableExport = teOptions;
|
1056
|
+
|
1057
|
+
// Fix jsPDF Autotable's row height calculation
|
1058
|
+
if ( typeof atOptions.beforePageContent !== 'function' ) {
|
1059
|
+
atOptions.beforePageContent = function (data) {
|
1060
|
+
if ( data.pageCount == 1 ) {
|
1061
|
+
var all = data.table.rows.concat(data.table.headerRow);
|
1062
|
+
all.forEach(function (row) {
|
1063
|
+
if ( row.height > 0 ) {
|
1064
|
+
row.height += (2 - FONT_ROW_RATIO) / 2 * row.styles.fontSize;
|
1065
|
+
data.table.height += (2 - FONT_ROW_RATIO) / 2 * row.styles.fontSize;
|
1066
|
+
}
|
1067
|
+
});
|
1068
|
+
}
|
1069
|
+
};
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
if ( typeof atOptions.createdHeaderCell !== 'function' ) {
|
1073
|
+
// apply some original css styles to pdf header cells
|
1074
|
+
atOptions.createdHeaderCell = function (cell, data) {
|
1075
|
+
|
1076
|
+
// jsPDF AutoTable plugin v2.0.14 fix: each cell needs its own styles object
|
1077
|
+
cell.styles = $.extend({}, data.row.styles);
|
1078
|
+
|
1079
|
+
if ( typeof teOptions.columns [data.column.dataKey] != 'undefined' ) {
|
1080
|
+
var col = teOptions.columns [data.column.dataKey];
|
1081
|
+
|
1082
|
+
if ( typeof col.rect != 'undefined' ) {
|
1083
|
+
var rh;
|
1084
|
+
|
1085
|
+
cell.contentWidth = col.rect.width;
|
1086
|
+
|
1087
|
+
if ( typeof teOptions.heightRatio == 'undefined' || teOptions.heightRatio === 0 ) {
|
1088
|
+
if ( data.row.raw [data.column.dataKey].rowspan )
|
1089
|
+
rh = data.row.raw [data.column.dataKey].rect.height / data.row.raw [data.column.dataKey].rowspan;
|
1090
|
+
else
|
1091
|
+
rh = data.row.raw [data.column.dataKey].rect.height;
|
1092
|
+
|
1093
|
+
teOptions.heightRatio = cell.styles.rowHeight / rh;
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
rh = data.row.raw [data.column.dataKey].rect.height * teOptions.heightRatio;
|
1097
|
+
if ( rh > cell.styles.rowHeight )
|
1098
|
+
cell.styles.rowHeight = rh;
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
if ( typeof col.style != 'undefined' && col.style.hidden !== true ) {
|
1102
|
+
cell.styles.halign = col.style.align;
|
1103
|
+
if ( atOptions.styles.fillColor === 'inherit' )
|
1104
|
+
cell.styles.fillColor = col.style.bcolor;
|
1105
|
+
if ( atOptions.styles.textColor === 'inherit' )
|
1106
|
+
cell.styles.textColor = col.style.color;
|
1107
|
+
if ( atOptions.styles.fontStyle === 'inherit' )
|
1108
|
+
cell.styles.fontStyle = col.style.fstyle;
|
1109
|
+
}
|
1110
|
+
}
|
1111
|
+
};
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
if ( typeof atOptions.createdCell !== 'function' ) {
|
1115
|
+
// apply some original css styles to pdf table cells
|
1116
|
+
atOptions.createdCell = function (cell, data) {
|
1117
|
+
var rowopt = teOptions.rowoptions [data.row.index + ":" + data.column.dataKey];
|
1118
|
+
|
1119
|
+
if ( typeof rowopt != 'undefined' &&
|
1120
|
+
typeof rowopt.style != 'undefined' &&
|
1121
|
+
rowopt.style.hidden !== true ) {
|
1122
|
+
cell.styles.halign = rowopt.style.align;
|
1123
|
+
if ( atOptions.styles.fillColor === 'inherit' )
|
1124
|
+
cell.styles.fillColor = rowopt.style.bcolor;
|
1125
|
+
if ( atOptions.styles.textColor === 'inherit' )
|
1126
|
+
cell.styles.textColor = rowopt.style.color;
|
1127
|
+
if ( atOptions.styles.fontStyle === 'inherit' )
|
1128
|
+
cell.styles.fontStyle = rowopt.style.fstyle;
|
1129
|
+
}
|
1130
|
+
};
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
if ( typeof atOptions.drawHeaderCell !== 'function' ) {
|
1134
|
+
atOptions.drawHeaderCell = function (cell, data) {
|
1135
|
+
var colopt = teOptions.columns [data.column.dataKey];
|
1136
|
+
|
1137
|
+
if ( (colopt.style.hasOwnProperty("hidden") !== true || colopt.style.hidden !== true) &&
|
1138
|
+
colopt.rowIndex >= 0 )
|
1139
|
+
return prepareAutoTableText(cell, data, colopt);
|
1140
|
+
else
|
1141
|
+
return false; // cell is hidden
|
1142
|
+
};
|
1143
|
+
}
|
1144
|
+
|
1145
|
+
if ( typeof atOptions.drawCell !== 'function' ) {
|
1146
|
+
atOptions.drawCell = function (cell, data) {
|
1147
|
+
var rowopt = teOptions.rowoptions [data.row.index + ":" + data.column.dataKey];
|
1148
|
+
if ( prepareAutoTableText(cell, data, rowopt) ) {
|
1149
|
+
|
1150
|
+
teOptions.doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle);
|
1151
|
+
|
1152
|
+
if ( typeof rowopt != 'undefined' && typeof rowopt.kids != 'undefined' && rowopt.kids.length > 0 ) {
|
1153
|
+
|
1154
|
+
var dh = cell.height / rowopt.rect.height;
|
1155
|
+
if ( dh > teOptions.dh || typeof teOptions.dh == 'undefined' )
|
1156
|
+
teOptions.dh = dh;
|
1157
|
+
teOptions.dw = cell.width / rowopt.rect.width;
|
1158
|
+
|
1159
|
+
var y = cell.textPos.y;
|
1160
|
+
drawAutotableElements(cell, rowopt.kids, teOptions);
|
1161
|
+
cell.textPos.y = y;
|
1162
|
+
drawAutotableText(cell, rowopt.kids, teOptions);
|
1163
|
+
}
|
1164
|
+
else
|
1165
|
+
drawAutotableText(cell, {}, teOptions);
|
1166
|
+
}
|
1167
|
+
return false;
|
1168
|
+
};
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
// collect header and data rows
|
1172
|
+
teOptions.headerrows = [];
|
1173
|
+
$hrows = $(this).find('thead').find(defaults.theadSelector);
|
1174
|
+
$hrows.each(function () {
|
1175
|
+
colKey = 0;
|
1176
|
+
|
1177
|
+
teOptions.headerrows[rowIndex] = [];
|
1178
|
+
|
1179
|
+
ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length,
|
1180
|
+
function (cell, row, col) {
|
1181
|
+
var obj = getCellStyles(cell);
|
1182
|
+
obj.title = parseString(cell, row, col);
|
1183
|
+
obj.key = colKey++;
|
1184
|
+
obj.rowIndex = rowIndex;
|
1185
|
+
teOptions.headerrows[rowIndex].push(obj);
|
1186
|
+
});
|
1187
|
+
rowIndex++;
|
1188
|
+
});
|
1189
|
+
|
1190
|
+
if ( rowIndex > 0 ) {
|
1191
|
+
// iterate through last row
|
1192
|
+
var lastrow = rowIndex - 1;
|
1193
|
+
while ( lastrow >= 0 ) {
|
1194
|
+
$.each(teOptions.headerrows[lastrow], function () {
|
1195
|
+
var obj = this;
|
1196
|
+
|
1197
|
+
if ( lastrow > 0 && this.rect === null )
|
1198
|
+
obj = teOptions.headerrows[lastrow - 1][this.key];
|
1199
|
+
|
1200
|
+
if ( obj !== null && obj.rowIndex >= 0 &&
|
1201
|
+
(obj.style.hasOwnProperty("hidden") !== true || obj.style.hidden !== true) )
|
1202
|
+
teOptions.columns.push(obj);
|
1203
|
+
});
|
1204
|
+
|
1205
|
+
lastrow = (teOptions.columns.length > 0) ? -1 : lastrow - 1;
|
1206
|
+
}
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
var rowCount = 0;
|
1210
|
+
$rows = [];
|
1211
|
+
$(this).find('tbody').each(function () {
|
1212
|
+
$rows.push.apply($rows, $(this).find(defaults.tbodySelector));
|
1213
|
+
});
|
1214
|
+
if ( defaults.tfootSelector.length )
|
1215
|
+
$rows.push.apply($rows, $(this).find('tfoot').find(defaults.tfootSelector));
|
1216
|
+
$($rows).each(function () {
|
1217
|
+
var rowData = [];
|
1218
|
+
colKey = 0;
|
1219
|
+
|
1220
|
+
ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length,
|
1221
|
+
function (cell, row, col) {
|
1222
|
+
var obj;
|
1223
|
+
|
1224
|
+
if ( typeof teOptions.columns[colKey] === 'undefined' ) {
|
1225
|
+
// jsPDF-Autotable needs columns. Thus define hidden ones for tables without thead
|
1226
|
+
obj = {
|
1227
|
+
title: '',
|
1228
|
+
key: colKey,
|
1229
|
+
style: {
|
1230
|
+
hidden: true
|
1231
|
+
}
|
1232
|
+
};
|
1233
|
+
teOptions.columns.push(obj);
|
1234
|
+
}
|
1235
|
+
if ( typeof cell !== 'undefined' && cell !== null ) {
|
1236
|
+
obj = getCellStyles(cell);
|
1237
|
+
obj.kids = $(cell).children();
|
1238
|
+
teOptions.rowoptions [rowCount + ":" + colKey++] = obj;
|
1239
|
+
}
|
1240
|
+
else {
|
1241
|
+
obj = $.extend(true, {}, teOptions.rowoptions [rowCount + ":" + (colKey - 1)]);
|
1242
|
+
obj.colspan = -1;
|
1243
|
+
teOptions.rowoptions [rowCount + ":" + colKey++] = obj;
|
1244
|
+
}
|
1245
|
+
|
1246
|
+
rowData.push(parseString(cell, row, col));
|
1247
|
+
});
|
1248
|
+
if ( rowData.length ) {
|
1249
|
+
teOptions.rows.push(rowData);
|
1250
|
+
rowCount++;
|
1251
|
+
}
|
1252
|
+
rowIndex++;
|
1253
|
+
});
|
1254
|
+
|
1255
|
+
// onBeforeAutotable: optional callback function before calling
|
1256
|
+
// jsPDF AutoTable that can be used to modify the AutoTable options
|
1257
|
+
if ( typeof teOptions.onBeforeAutotable === 'function' )
|
1258
|
+
teOptions.onBeforeAutotable($(this), teOptions.columns, teOptions.rows, atOptions);
|
1259
|
+
|
1260
|
+
teOptions.doc.autoTable(teOptions.columns, teOptions.rows, atOptions);
|
1261
|
+
|
1262
|
+
// onAfterAutotable: optional callback function after returning
|
1263
|
+
// from jsPDF AutoTable that can be used to modify the AutoTable options
|
1264
|
+
if ( typeof teOptions.onAfterAutotable === 'function' )
|
1265
|
+
teOptions.onAfterAutotable($(this), atOptions);
|
1266
|
+
|
1267
|
+
// set the start position for the next table (in case there is one)
|
1268
|
+
defaults.jspdf.autotable.startY = teOptions.doc.autoTableEndPosY() + atOptions.margin.top;
|
1269
|
+
|
1270
|
+
});
|
1271
|
+
|
1272
|
+
jsPdfOutput(teOptions.doc, (typeof teOptions.images != 'undefined' && jQuery.isEmptyObject(teOptions.images) === false));
|
1273
|
+
|
1274
|
+
if ( typeof teOptions.headerrows != 'undefined' )
|
1275
|
+
teOptions.headerrows.length = 0;
|
1276
|
+
if ( typeof teOptions.columns != 'undefined' )
|
1277
|
+
teOptions.columns.length = 0;
|
1278
|
+
if ( typeof teOptions.rows != 'undefined' )
|
1279
|
+
teOptions.rows.length = 0;
|
1280
|
+
delete teOptions.doc;
|
1281
|
+
teOptions.doc = null;
|
1282
|
+
});
|
1283
|
+
}
|
1284
|
+
}
|
1285
|
+
|
1286
|
+
/*
|
1287
|
+
function FindColObject (objects, colIndex, rowIndex) {
|
1288
|
+
var result = null;
|
1289
|
+
$.each(objects, function () {
|
1290
|
+
if ( this.rowIndex == rowIndex && this.key == colIndex ) {
|
1291
|
+
result = this;
|
1292
|
+
return false;
|
1293
|
+
}
|
1294
|
+
});
|
1295
|
+
return result;
|
1296
|
+
}
|
1297
|
+
*/
|
1298
|
+
|
1299
|
+
function GetColumnNames (table) {
|
1300
|
+
var result = [];
|
1301
|
+
$(table).find('thead').first().find('th').each(function (index, el) {
|
1302
|
+
if ( $(el).attr("data-field") !== undefined )
|
1303
|
+
result[index] = $(el).attr("data-field");
|
1304
|
+
else
|
1305
|
+
result[index] = index.toString();
|
1306
|
+
});
|
1307
|
+
return result;
|
1308
|
+
}
|
1309
|
+
|
1310
|
+
function isColumnIgnored (rowLength, colIndex) {
|
1311
|
+
var result = false;
|
1312
|
+
if ( defaults.ignoreColumn.length > 0 ) {
|
1313
|
+
if ( $.inArray(colIndex, defaults.ignoreColumn) != -1 ||
|
1314
|
+
$.inArray(colIndex - rowLength, defaults.ignoreColumn) != -1 ||
|
1315
|
+
(colNames.length > colIndex && typeof colNames[colIndex] != 'undefined' &&
|
1316
|
+
$.inArray(colNames[colIndex], defaults.ignoreColumn) != -1) )
|
1317
|
+
result = true;
|
1318
|
+
}
|
1319
|
+
return result;
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
function ForEachVisibleCell (tableRow, selector, rowIndex, rowCount, cellcallback) {
|
1323
|
+
if ( $.inArray(rowIndex, defaults.ignoreRow) == -1 &&
|
1324
|
+
$.inArray(rowIndex - rowCount, defaults.ignoreRow) == -1 ) {
|
1325
|
+
|
1326
|
+
var $row = $(tableRow).filter(function () {
|
1327
|
+
return $(this).data("tableexport-display") != 'none' &&
|
1328
|
+
($(this).is(':visible') ||
|
1329
|
+
$(this).data("tableexport-display") == 'always' ||
|
1330
|
+
$(this).closest('table').data("tableexport-display") == 'always');
|
1331
|
+
}).find(selector);
|
1332
|
+
|
1333
|
+
var rowColspan = 0;
|
1334
|
+
|
1335
|
+
$row.each(function (colIndex) {
|
1336
|
+
if ( $(this).data("tableexport-display") == 'always' ||
|
1337
|
+
($(this).css('display') != 'none' &&
|
1338
|
+
$(this).css('visibility') != 'hidden' &&
|
1339
|
+
$(this).data("tableexport-display") != 'none') ) {
|
1340
|
+
if ( typeof (cellcallback) === "function" ) {
|
1341
|
+
var c, Colspan = 1;
|
1342
|
+
var r, Rowspan = 1;
|
1343
|
+
var rowLength = $row.length;
|
1344
|
+
|
1345
|
+
// handle rowspans from previous rows
|
1346
|
+
if ( typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0 ) {
|
1347
|
+
var colCount = colIndex;
|
1348
|
+
for ( c = 0; c <= colCount; c++ ) {
|
1349
|
+
if ( typeof rowspans[rowIndex][c] != 'undefined' ) {
|
1350
|
+
cellcallback(null, rowIndex, c);
|
1351
|
+
delete rowspans[rowIndex][c];
|
1352
|
+
colCount++;
|
1353
|
+
}
|
1354
|
+
}
|
1355
|
+
colIndex += rowspans[rowIndex].length;
|
1356
|
+
rowLength += rowspans[rowIndex].length;
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
if ( $(this).is("[colspan]") ) {
|
1360
|
+
Colspan = parseInt($(this).attr('colspan')) || 1;
|
1361
|
+
|
1362
|
+
rowColspan += Colspan > 0 ? Colspan - 1 : 0;
|
1363
|
+
}
|
1364
|
+
|
1365
|
+
if ( $(this).is("[rowspan]") )
|
1366
|
+
Rowspan = parseInt($(this).attr('rowspan')) || 1;
|
1367
|
+
|
1368
|
+
if ( isColumnIgnored(rowLength, colIndex + rowColspan) === false ) {
|
1369
|
+
// output content of current cell
|
1370
|
+
cellcallback(this, rowIndex, colIndex);
|
1371
|
+
|
1372
|
+
// handle colspan of current cell
|
1373
|
+
for ( c = 1; c < Colspan; c++ )
|
1374
|
+
cellcallback(null, rowIndex, colIndex + c);
|
1375
|
+
}
|
1376
|
+
|
1377
|
+
// store rowspan for following rows
|
1378
|
+
if ( Rowspan > 1 ) {
|
1379
|
+
for ( r = 1; r < Rowspan; r++ ) {
|
1380
|
+
if ( typeof rowspans[rowIndex + r] == 'undefined' )
|
1381
|
+
rowspans[rowIndex + r] = [];
|
1382
|
+
|
1383
|
+
rowspans[rowIndex + r][colIndex + rowColspan] = "";
|
1384
|
+
|
1385
|
+
for ( c = 1; c < Colspan; c++ )
|
1386
|
+
rowspans[rowIndex + r][colIndex + rowColspan - c] = "";
|
1387
|
+
}
|
1388
|
+
}
|
1389
|
+
}
|
1390
|
+
}
|
1391
|
+
});
|
1392
|
+
// handle rowspans from previous rows
|
1393
|
+
if ( typeof rowspans[rowIndex] != 'undefined' && rowspans[rowIndex].length > 0 ) {
|
1394
|
+
for ( var c = 0; c <= rowspans[rowIndex].length; c++ ) {
|
1395
|
+
if ( typeof rowspans[rowIndex][c] != 'undefined' ) {
|
1396
|
+
cellcallback(null, rowIndex, c);
|
1397
|
+
delete rowspans[rowIndex][c];
|
1398
|
+
}
|
1399
|
+
}
|
1400
|
+
}
|
1401
|
+
}
|
1402
|
+
}
|
1403
|
+
|
1404
|
+
function jsPdfOutput (doc, hasimages) {
|
1405
|
+
if ( defaults.consoleLog === true )
|
1406
|
+
console.log(doc.output());
|
1407
|
+
|
1408
|
+
if ( defaults.outputMode === 'string' )
|
1409
|
+
return doc.output();
|
1410
|
+
|
1411
|
+
if ( defaults.outputMode === 'base64' )
|
1412
|
+
return base64encode(doc.output());
|
1413
|
+
|
1414
|
+
if ( defaults.outputMode === 'window' ) {
|
1415
|
+
window.open(URL.createObjectURL(doc.output("blob")));
|
1416
|
+
return;
|
1417
|
+
}
|
1418
|
+
|
1419
|
+
try {
|
1420
|
+
var blob = doc.output('blob');
|
1421
|
+
saveAs(blob, defaults.fileName + '.pdf');
|
1422
|
+
}
|
1423
|
+
catch (e) {
|
1424
|
+
downloadFile(defaults.fileName + '.pdf',
|
1425
|
+
'data:application/pdf' + (hasimages ? '' : ';base64') + ',',
|
1426
|
+
hasimages ? doc.output('blob') : doc.output());
|
1427
|
+
}
|
1428
|
+
}
|
1429
|
+
|
1430
|
+
function prepareAutoTableText (cell, data, cellopt) {
|
1431
|
+
var cs = 0;
|
1432
|
+
if ( typeof cellopt != 'undefined' )
|
1433
|
+
cs = cellopt.colspan;
|
1434
|
+
|
1435
|
+
if ( cs >= 0 ) {
|
1436
|
+
// colspan handling
|
1437
|
+
var cellWidth = cell.width;
|
1438
|
+
var textPosX = cell.textPos.x;
|
1439
|
+
var i = data.table.columns.indexOf(data.column);
|
1440
|
+
|
1441
|
+
for ( var c = 1; c < cs; c++ ) {
|
1442
|
+
var column = data.table.columns[i + c];
|
1443
|
+
cellWidth += column.width;
|
1444
|
+
}
|
1445
|
+
|
1446
|
+
if ( cs > 1 ) {
|
1447
|
+
if ( cell.styles.halign === 'right' )
|
1448
|
+
textPosX = cell.textPos.x + cellWidth - cell.width;
|
1449
|
+
else if ( cell.styles.halign === 'center' )
|
1450
|
+
textPosX = cell.textPos.x + (cellWidth - cell.width) / 2;
|
1451
|
+
}
|
1452
|
+
|
1453
|
+
cell.width = cellWidth;
|
1454
|
+
cell.textPos.x = textPosX;
|
1455
|
+
|
1456
|
+
if ( typeof cellopt != 'undefined' && cellopt.rowspan > 1 )
|
1457
|
+
cell.height = cell.height * cellopt.rowspan;
|
1458
|
+
|
1459
|
+
// fix jsPDF's calculation of text position
|
1460
|
+
if ( cell.styles.valign === 'middle' || cell.styles.valign === 'bottom' ) {
|
1461
|
+
var splittedText = typeof cell.text === 'string' ? cell.text.split(/\r\n|\r|\n/g) : cell.text;
|
1462
|
+
var lineCount = splittedText.length || 1;
|
1463
|
+
if ( lineCount > 2 )
|
1464
|
+
cell.textPos.y -= ((2 - FONT_ROW_RATIO) / 2 * data.row.styles.fontSize) * (lineCount - 2) / 3;
|
1465
|
+
}
|
1466
|
+
return true;
|
1467
|
+
}
|
1468
|
+
else
|
1469
|
+
return false; // cell is hidden (colspan = -1), don't draw it
|
1470
|
+
}
|
1471
|
+
|
1472
|
+
function collectImages (cell, elements, teOptions) {
|
1473
|
+
if ( typeof teOptions.images != 'undefined' ) {
|
1474
|
+
elements.each(function () {
|
1475
|
+
var kids = $(this).children();
|
1476
|
+
|
1477
|
+
if ( $(this).is("img") ) {
|
1478
|
+
var hash = strHashCode(this.src);
|
1479
|
+
|
1480
|
+
teOptions.images[hash] = {
|
1481
|
+
url: this.src,
|
1482
|
+
src: this.src
|
1483
|
+
};
|
1484
|
+
}
|
1485
|
+
|
1486
|
+
if ( typeof kids != 'undefined' && kids.length > 0 )
|
1487
|
+
collectImages(cell, kids, teOptions);
|
1488
|
+
});
|
1489
|
+
}
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
function loadImages (teOptions, callback) {
|
1493
|
+
var i;
|
1494
|
+
var imageCount = 0;
|
1495
|
+
var x = 0;
|
1496
|
+
|
1497
|
+
function done () {
|
1498
|
+
callback(imageCount);
|
1499
|
+
}
|
1500
|
+
|
1501
|
+
function loadImage (image) {
|
1502
|
+
if ( !image.url )
|
1503
|
+
return;
|
1504
|
+
var img = new Image();
|
1505
|
+
imageCount = ++x;
|
1506
|
+
img.crossOrigin = 'Anonymous';
|
1507
|
+
img.onerror = img.onload = function () {
|
1508
|
+
if ( img.complete ) {
|
1509
|
+
|
1510
|
+
if ( img.src.indexOf('data:image/') === 0 ) {
|
1511
|
+
img.width = image.width || img.width || 0;
|
1512
|
+
img.height = image.height || img.height || 0;
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
if ( img.width + img.height ) {
|
1516
|
+
var canvas = document.createElement("canvas");
|
1517
|
+
var ctx = canvas.getContext("2d");
|
1518
|
+
|
1519
|
+
canvas.width = img.width;
|
1520
|
+
canvas.height = img.height;
|
1521
|
+
ctx.drawImage(img, 0, 0);
|
1522
|
+
|
1523
|
+
image.src = canvas.toDataURL("image/jpeg");
|
1524
|
+
}
|
1525
|
+
}
|
1526
|
+
if ( !--x )
|
1527
|
+
done();
|
1528
|
+
};
|
1529
|
+
img.src = image.url;
|
1530
|
+
}
|
1531
|
+
|
1532
|
+
if ( typeof teOptions.images != 'undefined' ) {
|
1533
|
+
for ( i in teOptions.images )
|
1534
|
+
if ( teOptions.images.hasOwnProperty(i) )
|
1535
|
+
loadImage(teOptions.images[i]);
|
1536
|
+
}
|
1537
|
+
|
1538
|
+
return x || done();
|
1539
|
+
}
|
1540
|
+
|
1541
|
+
function drawAutotableElements (cell, elements, teOptions) {
|
1542
|
+
elements.each(function () {
|
1543
|
+
var kids = $(this).children();
|
1544
|
+
var uy = 0;
|
1545
|
+
|
1546
|
+
if ( $(this).is("div") ) {
|
1547
|
+
var bcolor = rgb2array(getStyle(this, 'background-color'), [255, 255, 255]);
|
1548
|
+
var lcolor = rgb2array(getStyle(this, 'border-top-color'), [0, 0, 0]);
|
1549
|
+
var lwidth = getPropertyUnitValue(this, 'border-top-width', defaults.jspdf.unit);
|
1550
|
+
|
1551
|
+
var r = this.getBoundingClientRect();
|
1552
|
+
var ux = this.offsetLeft * teOptions.dw;
|
1553
|
+
uy = this.offsetTop * teOptions.dh;
|
1554
|
+
var uw = r.width * teOptions.dw;
|
1555
|
+
var uh = r.height * teOptions.dh;
|
1556
|
+
|
1557
|
+
teOptions.doc.setDrawColor.apply(undefined, lcolor);
|
1558
|
+
teOptions.doc.setFillColor.apply(undefined, bcolor);
|
1559
|
+
teOptions.doc.setLineWidth(lwidth);
|
1560
|
+
teOptions.doc.rect(cell.x + ux, cell.y + uy, uw, uh, lwidth ? "FD" : "F");
|
1561
|
+
}
|
1562
|
+
else if ( $(this).is("img") ) {
|
1563
|
+
if ( typeof teOptions.images != 'undefined' ) {
|
1564
|
+
var hash = strHashCode(this.src);
|
1565
|
+
var image = teOptions.images[hash];
|
1566
|
+
|
1567
|
+
if ( typeof image != 'undefined' ) {
|
1568
|
+
|
1569
|
+
var arCell = cell.width / cell.height;
|
1570
|
+
var arImg = this.width / this.height;
|
1571
|
+
var imgWidth = cell.width;
|
1572
|
+
var imgHeight = cell.height;
|
1573
|
+
var px2pt = 0.264583 * 72 / 25.4;
|
1574
|
+
|
1575
|
+
if ( arImg <= arCell ) {
|
1576
|
+
imgHeight = Math.min(cell.height, this.height);
|
1577
|
+
imgWidth = this.width * imgHeight / this.height;
|
1578
|
+
}
|
1579
|
+
else if ( arImg > arCell ) {
|
1580
|
+
imgWidth = Math.min(cell.width, this.width);
|
1581
|
+
imgHeight = this.height * imgWidth / this.width;
|
1582
|
+
}
|
1583
|
+
|
1584
|
+
imgWidth *= px2pt;
|
1585
|
+
imgHeight *= px2pt;
|
1586
|
+
|
1587
|
+
if ( imgHeight < cell.height )
|
1588
|
+
uy = (cell.height - imgHeight) / 2;
|
1589
|
+
|
1590
|
+
try {
|
1591
|
+
teOptions.doc.addImage(image.src, cell.textPos.x, cell.y + uy, imgWidth, imgHeight);
|
1592
|
+
}
|
1593
|
+
catch (e) {
|
1594
|
+
// TODO: IE -> convert png to jpeg
|
1595
|
+
}
|
1596
|
+
cell.textPos.x += imgWidth;
|
1597
|
+
}
|
1598
|
+
}
|
1599
|
+
}
|
1600
|
+
|
1601
|
+
if ( typeof kids != 'undefined' && kids.length > 0 )
|
1602
|
+
drawAutotableElements(cell, kids, teOptions);
|
1603
|
+
});
|
1604
|
+
}
|
1605
|
+
|
1606
|
+
function drawAutotableText (cell, texttags, teOptions) {
|
1607
|
+
if ( typeof teOptions.onAutotableText === 'function' ) {
|
1608
|
+
teOptions.onAutotableText(teOptions.doc, cell, texttags);
|
1609
|
+
}
|
1610
|
+
else {
|
1611
|
+
var x = cell.textPos.x;
|
1612
|
+
var y = cell.textPos.y;
|
1613
|
+
var style = {halign: cell.styles.halign, valign: cell.styles.valign};
|
1614
|
+
|
1615
|
+
if ( texttags.length ) {
|
1616
|
+
var tag = texttags[0];
|
1617
|
+
while ( tag.previousSibling )
|
1618
|
+
tag = tag.previousSibling;
|
1619
|
+
|
1620
|
+
var b = false, i = false;
|
1621
|
+
|
1622
|
+
while ( tag ) {
|
1623
|
+
var txt = tag.innerText || tag.textContent || "";
|
1624
|
+
|
1625
|
+
txt = ((txt.length && txt[0] == " ") ? " " : "") +
|
1626
|
+
$.trim(txt) +
|
1627
|
+
((txt.length > 1 && txt[txt.length - 1] == " ") ? " " : "");
|
1628
|
+
|
1629
|
+
if ( $(tag).is("br") ) {
|
1630
|
+
x = cell.textPos.x;
|
1631
|
+
y += teOptions.doc.internal.getFontSize();
|
1632
|
+
}
|
1633
|
+
|
1634
|
+
if ( $(tag).is("b") )
|
1635
|
+
b = true;
|
1636
|
+
else if ( $(tag).is("i") )
|
1637
|
+
i = true;
|
1638
|
+
|
1639
|
+
if ( b || i )
|
1640
|
+
teOptions.doc.setFontType((b && i) ? "bolditalic" : b ? "bold" : "italic");
|
1641
|
+
|
1642
|
+
var w = teOptions.doc.getStringUnitWidth(txt) * teOptions.doc.internal.getFontSize();
|
1643
|
+
|
1644
|
+
if ( w ) {
|
1645
|
+
if ( cell.styles.overflow === 'linebreak' &&
|
1646
|
+
x > cell.textPos.x && (x + w) > (cell.textPos.x + cell.width) ) {
|
1647
|
+
var chars = ".,!%*;:=-";
|
1648
|
+
if ( chars.indexOf(txt.charAt(0)) >= 0 ) {
|
1649
|
+
var s = txt.charAt(0);
|
1650
|
+
w = teOptions.doc.getStringUnitWidth(s) * teOptions.doc.internal.getFontSize();
|
1651
|
+
if ( (x + w) <= (cell.textPos.x + cell.width) ) {
|
1652
|
+
teOptions.doc.autoTableText(s, x, y, style);
|
1653
|
+
txt = txt.substring(1, txt.length);
|
1654
|
+
}
|
1655
|
+
w = teOptions.doc.getStringUnitWidth(txt) * teOptions.doc.internal.getFontSize();
|
1656
|
+
}
|
1657
|
+
x = cell.textPos.x;
|
1658
|
+
y += teOptions.doc.internal.getFontSize();
|
1659
|
+
}
|
1660
|
+
|
1661
|
+
while ( txt.length && (x + w) > (cell.textPos.x + cell.width) ) {
|
1662
|
+
txt = txt.substring(0, txt.length - 1);
|
1663
|
+
w = teOptions.doc.getStringUnitWidth(txt) * teOptions.doc.internal.getFontSize();
|
1664
|
+
}
|
1665
|
+
|
1666
|
+
teOptions.doc.autoTableText(txt, x, y, style);
|
1667
|
+
x += w;
|
1668
|
+
}
|
1669
|
+
|
1670
|
+
if ( b || i ) {
|
1671
|
+
if ( $(tag).is("b") )
|
1672
|
+
b = false;
|
1673
|
+
else if ( $(tag).is("i") )
|
1674
|
+
i = false;
|
1675
|
+
|
1676
|
+
teOptions.doc.setFontType((!b && !i) ? "normal" : b ? "bold" : "italic");
|
1677
|
+
}
|
1678
|
+
|
1679
|
+
tag = tag.nextSibling;
|
1680
|
+
}
|
1681
|
+
cell.textPos.x = x;
|
1682
|
+
cell.textPos.y = y;
|
1683
|
+
}
|
1684
|
+
else {
|
1685
|
+
teOptions.doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, style);
|
1686
|
+
}
|
1687
|
+
}
|
1688
|
+
}
|
1689
|
+
|
1690
|
+
function escapeRegExp (string) {
|
1691
|
+
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
function replaceAll (string, find, replace) {
|
1695
|
+
return string.replace(new RegExp(escapeRegExp(find), 'g'), replace);
|
1696
|
+
}
|
1697
|
+
|
1698
|
+
function parseNumber (value) {
|
1699
|
+
value = value || "0";
|
1700
|
+
value = replaceAll(value, defaults.numbers.html.thousandsSeparator, '');
|
1701
|
+
value = replaceAll(value, defaults.numbers.html.decimalMark, '.');
|
1702
|
+
|
1703
|
+
return typeof value === "number" || jQuery.isNumeric(value) !== false ? value : false;
|
1704
|
+
}
|
1705
|
+
|
1706
|
+
function parsePercent (value) {
|
1707
|
+
if ( value.indexOf("%") > -1 ) {
|
1708
|
+
value = parseNumber(value.replace(/%/g, ""));
|
1709
|
+
if ( value !== false )
|
1710
|
+
value = value / 100;
|
1711
|
+
}
|
1712
|
+
else
|
1713
|
+
value = false;
|
1714
|
+
return value;
|
1715
|
+
}
|
1716
|
+
|
1717
|
+
function parseString (cell, rowIndex, colIndex) {
|
1718
|
+
var result = '';
|
1719
|
+
|
1720
|
+
if ( cell !== null ) {
|
1721
|
+
var $cell = $(cell);
|
1722
|
+
var htmlData;
|
1723
|
+
|
1724
|
+
if ( $cell[0].hasAttribute("data-tableexport-value") ) {
|
1725
|
+
htmlData = $cell.data("tableexport-value");
|
1726
|
+
htmlData = htmlData ? htmlData + '' : ''
|
1727
|
+
}
|
1728
|
+
else {
|
1729
|
+
htmlData = $cell.html();
|
1730
|
+
|
1731
|
+
if ( typeof defaults.onCellHtmlData === 'function' )
|
1732
|
+
htmlData = defaults.onCellHtmlData($cell, rowIndex, colIndex, htmlData);
|
1733
|
+
else if ( htmlData != '' ) {
|
1734
|
+
var html = $.parseHTML(htmlData);
|
1735
|
+
var inputidx = 0;
|
1736
|
+
var selectidx = 0;
|
1737
|
+
|
1738
|
+
htmlData = '';
|
1739
|
+
$.each(html, function () {
|
1740
|
+
if ( $(this).is("input") )
|
1741
|
+
htmlData += $cell.find('input').eq(inputidx++).val();
|
1742
|
+
else if ( $(this).is("select") )
|
1743
|
+
htmlData += $cell.find('select option:selected').eq(selectidx++).text();
|
1744
|
+
else {
|
1745
|
+
if ( typeof $(this).html() === 'undefined' )
|
1746
|
+
htmlData += $(this).text();
|
1747
|
+
else if ( jQuery().bootstrapTable === undefined || $(this).hasClass('filterControl') !== true )
|
1748
|
+
htmlData += $(this).html();
|
1749
|
+
}
|
1750
|
+
});
|
1751
|
+
}
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
if ( defaults.htmlContent === true ) {
|
1755
|
+
result = $.trim(htmlData);
|
1756
|
+
}
|
1757
|
+
else if ( htmlData && htmlData != '' ) {
|
1758
|
+
var text = htmlData.replace(/\n/g, '\u2028').replace(/<br\s*[\/]?>/gi, '\u2060');
|
1759
|
+
var obj = $('<div/>').html(text).contents();
|
1760
|
+
var number = false;
|
1761
|
+
text = '';
|
1762
|
+
$.each(obj.text().split("\u2028"), function (i, v) {
|
1763
|
+
if ( i > 0 )
|
1764
|
+
text += " ";
|
1765
|
+
text += $.trim(v);
|
1766
|
+
});
|
1767
|
+
|
1768
|
+
$.each(text.split("\u2060"), function (i, v) {
|
1769
|
+
if ( i > 0 )
|
1770
|
+
result += "\n";
|
1771
|
+
result += $.trim(v).replace(/\u00AD/g, ""); // remove soft hyphens
|
1772
|
+
});
|
1773
|
+
|
1774
|
+
if ( defaults.type == 'json' ||
|
1775
|
+
(defaults.type === 'excel' && defaults.excelFileFormat === 'xmlss') ||
|
1776
|
+
defaults.numbers.output === false ) {
|
1777
|
+
number = parseNumber(result);
|
1778
|
+
|
1779
|
+
if ( number !== false )
|
1780
|
+
result = Number(number);
|
1781
|
+
}
|
1782
|
+
else if ( defaults.numbers.html.decimalMark != defaults.numbers.output.decimalMark ||
|
1783
|
+
defaults.numbers.html.thousandsSeparator != defaults.numbers.output.thousandsSeparator ) {
|
1784
|
+
number = parseNumber(result);
|
1785
|
+
|
1786
|
+
if ( number !== false ) {
|
1787
|
+
var frac = ("" + number.substr(number < 0 ? 1 : 0)).split('.');
|
1788
|
+
if ( frac.length == 1 )
|
1789
|
+
frac[1] = "";
|
1790
|
+
var mod = frac[0].length > 3 ? frac[0].length % 3 : 0;
|
1791
|
+
|
1792
|
+
result = (number < 0 ? "-" : "") +
|
1793
|
+
(defaults.numbers.output.thousandsSeparator ? ((mod ? frac[0].substr(0, mod) + defaults.numbers.output.thousandsSeparator : "") + frac[0].substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + defaults.numbers.output.thousandsSeparator)) : frac[0]) +
|
1794
|
+
(frac[1].length ? defaults.numbers.output.decimalMark + frac[1] : "");
|
1795
|
+
}
|
1796
|
+
}
|
1797
|
+
}
|
1798
|
+
|
1799
|
+
if ( defaults.escape === true ) {
|
1800
|
+
//noinspection JSDeprecatedSymbols
|
1801
|
+
result = escape(result);
|
1802
|
+
}
|
1803
|
+
|
1804
|
+
if ( typeof defaults.onCellData === 'function' ) {
|
1805
|
+
result = defaults.onCellData($cell, rowIndex, colIndex, result);
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
|
1809
|
+
return result;
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
//noinspection JSUnusedLocalSymbols
|
1813
|
+
function hyphenate (a, b, c) {
|
1814
|
+
return b + "-" + c.toLowerCase();
|
1815
|
+
}
|
1816
|
+
|
1817
|
+
function rgb2array (rgb_string, default_result) {
|
1818
|
+
var re = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/;
|
1819
|
+
var bits = re.exec(rgb_string);
|
1820
|
+
var result = default_result;
|
1821
|
+
if ( bits )
|
1822
|
+
result = [parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3])];
|
1823
|
+
return result;
|
1824
|
+
}
|
1825
|
+
|
1826
|
+
function getCellStyles (cell) {
|
1827
|
+
var a = getStyle(cell, 'text-align');
|
1828
|
+
var fw = getStyle(cell, 'font-weight');
|
1829
|
+
var fs = getStyle(cell, 'font-style');
|
1830
|
+
var f = '';
|
1831
|
+
if ( a == 'start' )
|
1832
|
+
a = getStyle(cell, 'direction') == 'rtl' ? 'right' : 'left';
|
1833
|
+
if ( fw >= 700 )
|
1834
|
+
f = 'bold';
|
1835
|
+
if ( fs == 'italic' )
|
1836
|
+
f += fs;
|
1837
|
+
if ( f === '' )
|
1838
|
+
f = 'normal';
|
1839
|
+
|
1840
|
+
var result = {
|
1841
|
+
style: {
|
1842
|
+
align: a,
|
1843
|
+
bcolor: rgb2array(getStyle(cell, 'background-color'), [255, 255, 255]),
|
1844
|
+
color: rgb2array(getStyle(cell, 'color'), [0, 0, 0]),
|
1845
|
+
fstyle: f
|
1846
|
+
},
|
1847
|
+
colspan: (parseInt($(cell).attr('colspan')) || 0),
|
1848
|
+
rowspan: (parseInt($(cell).attr('rowspan')) || 0)
|
1849
|
+
};
|
1850
|
+
|
1851
|
+
if ( cell !== null ) {
|
1852
|
+
var r = cell.getBoundingClientRect();
|
1853
|
+
result.rect = {
|
1854
|
+
width: r.width,
|
1855
|
+
height: r.height
|
1856
|
+
};
|
1857
|
+
}
|
1858
|
+
|
1859
|
+
return result;
|
1860
|
+
}
|
1861
|
+
|
1862
|
+
// get computed style property
|
1863
|
+
function getStyle (target, prop) {
|
1864
|
+
try {
|
1865
|
+
if ( window.getComputedStyle ) { // gecko and webkit
|
1866
|
+
prop = prop.replace(/([a-z])([A-Z])/, hyphenate); // requires hyphenated, not camel
|
1867
|
+
return window.getComputedStyle(target, null).getPropertyValue(prop);
|
1868
|
+
}
|
1869
|
+
if ( target.currentStyle ) { // ie
|
1870
|
+
return target.currentStyle[prop];
|
1871
|
+
}
|
1872
|
+
return target.style[prop];
|
1873
|
+
}
|
1874
|
+
catch (e) {
|
1875
|
+
}
|
1876
|
+
return "";
|
1877
|
+
}
|
1878
|
+
|
1879
|
+
function getUnitValue (parent, value, unit) {
|
1880
|
+
var baseline = 100; // any number serves
|
1881
|
+
|
1882
|
+
var temp = document.createElement("div"); // create temporary element
|
1883
|
+
temp.style.overflow = "hidden"; // in case baseline is set too low
|
1884
|
+
temp.style.visibility = "hidden"; // no need to show it
|
1885
|
+
|
1886
|
+
parent.appendChild(temp); // insert it into the parent for em, ex and %
|
1887
|
+
|
1888
|
+
temp.style.width = baseline + unit;
|
1889
|
+
var factor = baseline / temp.offsetWidth;
|
1890
|
+
|
1891
|
+
parent.removeChild(temp); // clean up
|
1892
|
+
|
1893
|
+
return (value * factor);
|
1894
|
+
}
|
1895
|
+
|
1896
|
+
function getPropertyUnitValue (target, prop, unit) {
|
1897
|
+
var value = getStyle(target, prop); // get the computed style value
|
1898
|
+
|
1899
|
+
var numeric = value.match(/\d+/); // get the numeric component
|
1900
|
+
if ( numeric !== null ) {
|
1901
|
+
numeric = numeric[0]; // get the string
|
1902
|
+
|
1903
|
+
return getUnitValue(target.parentElement, numeric, unit);
|
1904
|
+
}
|
1905
|
+
return 0;
|
1906
|
+
}
|
1907
|
+
|
1908
|
+
function jx_Workbook () {
|
1909
|
+
if ( !(this instanceof jx_Workbook) ) {
|
1910
|
+
//noinspection JSPotentiallyInvalidConstructorUsage
|
1911
|
+
return new jx_Workbook();
|
1912
|
+
}
|
1913
|
+
this.SheetNames = [];
|
1914
|
+
this.Sheets = {};
|
1915
|
+
}
|
1916
|
+
|
1917
|
+
function jx_s2ab (s) {
|
1918
|
+
var buf = new ArrayBuffer(s.length);
|
1919
|
+
var view = new Uint8Array(buf);
|
1920
|
+
for ( var i = 0; i != s.length; ++i ) view[i] = s.charCodeAt(i) & 0xFF;
|
1921
|
+
return buf;
|
1922
|
+
}
|
1923
|
+
|
1924
|
+
function jx_datenum (v, date1904) {
|
1925
|
+
if ( date1904 ) v += 1462;
|
1926
|
+
var epoch = Date.parse(v);
|
1927
|
+
return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
function jx_createSheet (data) {
|
1931
|
+
var ws = {};
|
1932
|
+
var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
|
1933
|
+
for ( var R = 0; R != data.length; ++R ) {
|
1934
|
+
for ( var C = 0; C != data[R].length; ++C ) {
|
1935
|
+
if ( range.s.r > R ) range.s.r = R;
|
1936
|
+
if ( range.s.c > C ) range.s.c = C;
|
1937
|
+
if ( range.e.r < R ) range.e.r = R;
|
1938
|
+
if ( range.e.c < C ) range.e.c = C;
|
1939
|
+
var cell = {v: data[R][C]};
|
1940
|
+
if ( cell.v === null ) continue;
|
1941
|
+
var cell_ref = XLSX.utils.encode_cell({c: C, r: R});
|
1942
|
+
|
1943
|
+
if ( typeof cell.v === 'number' ) cell.t = 'n';
|
1944
|
+
else if ( typeof cell.v === 'boolean' ) cell.t = 'b';
|
1945
|
+
else if ( cell.v instanceof Date ) {
|
1946
|
+
cell.t = 'n';
|
1947
|
+
cell.z = XLSX.SSF._table[14];
|
1948
|
+
cell.v = jx_datenum(cell.v);
|
1949
|
+
}
|
1950
|
+
else cell.t = 's';
|
1951
|
+
ws[cell_ref] = cell;
|
1952
|
+
}
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
if ( range.s.c < 10000000 ) ws['!ref'] = XLSX.utils.encode_range(range);
|
1956
|
+
return ws;
|
1957
|
+
}
|
1958
|
+
|
1959
|
+
function strHashCode (str) {
|
1960
|
+
var hash = 0, i, chr, len;
|
1961
|
+
if ( str.length === 0 ) return hash;
|
1962
|
+
for ( i = 0, len = str.length; i < len; i++ ) {
|
1963
|
+
chr = str.charCodeAt(i);
|
1964
|
+
hash = ((hash << 5) - hash) + chr;
|
1965
|
+
hash |= 0; // Convert to 32bit integer
|
1966
|
+
}
|
1967
|
+
return hash;
|
1968
|
+
}
|
1969
|
+
|
1970
|
+
function downloadFile (filename, header, data) {
|
1971
|
+
|
1972
|
+
var ua = window.navigator.userAgent;
|
1973
|
+
if ( filename !== false && (ua.indexOf("MSIE ") > 0 || !!ua.match(/Trident.*rv\:11\./)) ) {
|
1974
|
+
if ( window.navigator.msSaveOrOpenBlob ) {
|
1975
|
+
//noinspection JSUnresolvedFunction
|
1976
|
+
window.navigator.msSaveOrOpenBlob(new Blob([data]), filename);
|
1977
|
+
}
|
1978
|
+
else {
|
1979
|
+
// Internet Explorer (<= 9) workaround by Darryl (https://github.com/dawiong/tableExport.jquery.plugin)
|
1980
|
+
// based on sampopes answer on http://stackoverflow.com/questions/22317951
|
1981
|
+
// ! Not working for json and pdf format !
|
1982
|
+
var frame = document.createElement("iframe");
|
1983
|
+
|
1984
|
+
if ( frame ) {
|
1985
|
+
document.body.appendChild(frame);
|
1986
|
+
frame.setAttribute("style", "display:none");
|
1987
|
+
frame.contentDocument.open("txt/html", "replace");
|
1988
|
+
frame.contentDocument.write(data);
|
1989
|
+
frame.contentDocument.close();
|
1990
|
+
frame.focus();
|
1991
|
+
|
1992
|
+
frame.contentDocument.execCommand("SaveAs", true, filename);
|
1993
|
+
document.body.removeChild(frame);
|
1994
|
+
}
|
1995
|
+
}
|
1996
|
+
}
|
1997
|
+
else {
|
1998
|
+
var DownloadLink = document.createElement('a');
|
1999
|
+
|
2000
|
+
if ( DownloadLink ) {
|
2001
|
+
var blobUrl = null;
|
2002
|
+
|
2003
|
+
DownloadLink.style.display = 'none';
|
2004
|
+
if ( filename !== false )
|
2005
|
+
DownloadLink.download = filename;
|
2006
|
+
else
|
2007
|
+
DownloadLink.target = '_blank';
|
2008
|
+
|
2009
|
+
if ( typeof data == 'object' ) {
|
2010
|
+
blobUrl = window.URL.createObjectURL(data);
|
2011
|
+
DownloadLink.href = blobUrl;
|
2012
|
+
}
|
2013
|
+
else if ( header.toLowerCase().indexOf("base64,") >= 0 )
|
2014
|
+
DownloadLink.href = header + base64encode(data);
|
2015
|
+
else
|
2016
|
+
DownloadLink.href = header + encodeURIComponent(data);
|
2017
|
+
|
2018
|
+
document.body.appendChild(DownloadLink);
|
2019
|
+
|
2020
|
+
if ( document.createEvent ) {
|
2021
|
+
if ( DownloadEvt === null )
|
2022
|
+
DownloadEvt = document.createEvent('MouseEvents');
|
2023
|
+
|
2024
|
+
DownloadEvt.initEvent('click', true, false);
|
2025
|
+
DownloadLink.dispatchEvent(DownloadEvt);
|
2026
|
+
}
|
2027
|
+
else if ( document.createEventObject )
|
2028
|
+
DownloadLink.fireEvent('onclick');
|
2029
|
+
else if ( typeof DownloadLink.onclick == 'function' )
|
2030
|
+
DownloadLink.onclick();
|
2031
|
+
|
2032
|
+
if ( blobUrl )
|
2033
|
+
window.URL.revokeObjectURL(blobUrl);
|
2034
|
+
|
2035
|
+
document.body.removeChild(DownloadLink);
|
2036
|
+
}
|
2037
|
+
}
|
2038
|
+
}
|
2039
|
+
|
2040
|
+
function utf8Encode (string) {
|
2041
|
+
string = string.replace(/\x0d\x0a/g, "\x0a");
|
2042
|
+
var utftext = "";
|
2043
|
+
for ( var n = 0; n < string.length; n++ ) {
|
2044
|
+
var c = string.charCodeAt(n);
|
2045
|
+
if ( c < 128 ) {
|
2046
|
+
utftext += String.fromCharCode(c);
|
2047
|
+
}
|
2048
|
+
else if ( (c > 127) && (c < 2048) ) {
|
2049
|
+
utftext += String.fromCharCode((c >> 6) | 192);
|
2050
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
2051
|
+
}
|
2052
|
+
else {
|
2053
|
+
utftext += String.fromCharCode((c >> 12) | 224);
|
2054
|
+
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
2055
|
+
utftext += String.fromCharCode((c & 63) | 128);
|
2056
|
+
}
|
2057
|
+
}
|
2058
|
+
return utftext;
|
2059
|
+
}
|
2060
|
+
|
2061
|
+
function base64encode (input) {
|
2062
|
+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
2063
|
+
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
2064
|
+
var output = "";
|
2065
|
+
var i = 0;
|
2066
|
+
input = utf8Encode(input);
|
2067
|
+
while ( i < input.length ) {
|
2068
|
+
chr1 = input.charCodeAt(i++);
|
2069
|
+
chr2 = input.charCodeAt(i++);
|
2070
|
+
chr3 = input.charCodeAt(i++);
|
2071
|
+
enc1 = chr1 >> 2;
|
2072
|
+
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
2073
|
+
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
2074
|
+
enc4 = chr3 & 63;
|
2075
|
+
if ( isNaN(chr2) ) {
|
2076
|
+
enc3 = enc4 = 64;
|
2077
|
+
} else if ( isNaN(chr3) ) {
|
2078
|
+
enc4 = 64;
|
2079
|
+
}
|
2080
|
+
output = output +
|
2081
|
+
keyStr.charAt(enc1) + keyStr.charAt(enc2) +
|
2082
|
+
keyStr.charAt(enc3) + keyStr.charAt(enc4);
|
2083
|
+
}
|
2084
|
+
return output;
|
2085
|
+
}
|
2086
|
+
|
2087
|
+
return this;
|
2088
|
+
}
|
2089
|
+
});
|
2090
|
+
})(jQuery);
|