Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
updates for v3.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed May 4, 2016
1 parent 2543ad7 commit ee1b6d7
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 34 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tableexport.js",
"version": "3.1.2",
"version": "3.1.3",
"authors": [
"clarketm <[email protected]>"
],
Expand Down
37 changes: 23 additions & 14 deletions dist/js/tableexport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v3.1.2 (http://www.clarketravis.com)
* TableExport.js v3.1.3 (http://www.clarketravis.com)
* Copyright 2015 Travis Clarke
* Licensed under the MIT license
*/
Expand Down Expand Up @@ -31,27 +31,28 @@
exporters = {
xlsx: function (rDel, name) {
var dataURL = $rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).text()
});
}).get(),
dataObject = JSON.stringify({
var $cols = $(val).find('th, td');
return [$cols.map(function (i, val) {
return $(val).text();
}).get()];
}).get(),
dataObject = escapeHtml(
JSON.stringify({
data: dataURL,
name: name
}).replace(/'/g, "&#39;"),
})),
myFile = name + ".xlsx",
myContent = $.fn.tableExport.xlsx.buttonContent,
myClass = $.fn.tableExport.xlsx.defaultClass;
createObjButton(dataObject, myFile, myContent, myClass);
},
xls: function (rdel, name) {
var colD = $.fn.tableExport.xls.separator,
dataURL = 'data:application/vnd.ms-excel;charset=utf-16,' +
dataURL = 'data:application/vnd.ms-excel;charset=utf-8,' +
encodeURIComponent($rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).html()
return $(val).text();
}).get().join(colD);
}).get().join(rdel)),
myFile = name + ".xls",
Expand All @@ -62,11 +63,11 @@
csv: function (rdel, name) {
rdel = '"' + rdel + '"';
var colD = '"' + $.fn.tableExport.csv.separator + '"',
dataURL = 'data:text/csv;charset=utf-16,' +
dataURL = 'data:text/csv;charset=utf-8,' +
encodeURIComponent('"' + $rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).text().replace(/"/g, '""')
return $(val).text().replace(/"/g, '""');
}).get().join(colD);
}).get().join(rdel) + '"'),
myFile = name + ".csv",
Expand All @@ -76,11 +77,11 @@
},
txt: function (rdel, name) {
var colD = $.fn.tableExport.txt.separator,
dataURL = 'data:text/plain;charset=utf-16,' +
dataURL = 'data:text/plain;charset=utf-8,' +
encodeURIComponent($rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).text()
return $(val).text();
}).get().join(colD);
}).get().join(rdel)),
myFile = name + ".txt",
Expand Down Expand Up @@ -168,6 +169,14 @@

$.fn.tableExport.rowDel = "\r\n";

$.fn.tableExport.entityMap = {"&": "&#38;", "<": "&#60;", ">": "&#62;", "'": '&#39;', "/": '&#47'};

function escapeHtml(string) {
return String(string).replace(/[&<>'\/]/g, function (s) {
return $.fn.tableExport.entityMap[s];
});
}

function dateNum(v, date1904) {
if (date1904) v += 1462;
var epoch = Date.parse(v);
Expand Down
4 changes: 2 additions & 2 deletions dist/js/tableexport.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tableexport",
"version": "3.1.2",
"version": "3.1.3",
"authors": [
"clarketm <[email protected]>"
],
Expand Down
37 changes: 23 additions & 14 deletions src/stable/js/tableexport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v3.1.2 (http://www.clarketravis.com)
* TableExport.js v3.1.3 (http://www.clarketravis.com)
* Copyright 2015 Travis Clarke
* Licensed under the MIT license
*/
Expand Down Expand Up @@ -31,27 +31,28 @@
exporters = {
xlsx: function (rDel, name) {
var dataURL = $rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).text()
});
}).get(),
dataObject = JSON.stringify({
var $cols = $(val).find('th, td');
return [$cols.map(function (i, val) {
return $(val).text();
}).get()];
}).get(),
dataObject = escapeHtml(
JSON.stringify({
data: dataURL,
name: name
}).replace(/'/g, "&#39;"),
})),
myFile = name + ".xlsx",
myContent = $.fn.tableExport.xlsx.buttonContent,
myClass = $.fn.tableExport.xlsx.defaultClass;
createObjButton(dataObject, myFile, myContent, myClass);
},
xls: function (rdel, name) {
var colD = $.fn.tableExport.xls.separator,
dataURL = 'data:application/vnd.ms-excel;charset=utf-16,' +
dataURL = 'data:application/vnd.ms-excel;charset=utf-8,' +
encodeURIComponent($rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).html()
return $(val).text();
}).get().join(colD);
}).get().join(rdel)),
myFile = name + ".xls",
Expand All @@ -62,11 +63,11 @@
csv: function (rdel, name) {
rdel = '"' + rdel + '"';
var colD = '"' + $.fn.tableExport.csv.separator + '"',
dataURL = 'data:text/csv;charset=utf-16,' +
dataURL = 'data:text/csv;charset=utf-8,' +
encodeURIComponent('"' + $rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).text().replace(/"/g, '""')
return $(val).text().replace(/"/g, '""');
}).get().join(colD);
}).get().join(rdel) + '"'),
myFile = name + ".csv",
Expand All @@ -76,11 +77,11 @@
},
txt: function (rdel, name) {
var colD = $.fn.tableExport.txt.separator,
dataURL = 'data:text/plain;charset=utf-16,' +
dataURL = 'data:text/plain;charset=utf-8,' +
encodeURIComponent($rows.map(function (i, val) {
var $cols = $(val).find('th, td');
return $cols.map(function (i, val) {
return $(val).text()
return $(val).text();
}).get().join(colD);
}).get().join(rdel)),
myFile = name + ".txt",
Expand Down Expand Up @@ -168,6 +169,14 @@

$.fn.tableExport.rowDel = "\r\n";

$.fn.tableExport.entityMap = {"&": "&#38;", "<": "&#60;", ">": "&#62;", "'": '&#39;', "/": '&#47'};

function escapeHtml(string) {
return String(string).replace(/[&<>'\/]/g, function (s) {
return $.fn.tableExport.entityMap[s];
});
}

function dateNum(v, date1904) {
if (date1904) v += 1462;
var epoch = Date.parse(v);
Expand Down
Loading

0 comments on commit ee1b6d7

Please sign in to comment.