From 691609f3957903398b3fdc87c59da1850f867cf7 Mon Sep 17 00:00:00 2001 From: Travis Clarke Date: Fri, 20 Jan 2017 17:28:01 -0800 Subject: [PATCH] v3.3.8 - add 'trimWhitespace' property, closes #42 --- README.md | 2 +- bower.json | 2 +- dist/css/tableexport.css | 2 +- dist/css/tableexport.min.css | 2 +- dist/js/tableexport.js | 33 +++++++++++++++---------- dist/js/tableexport.min.js | 4 +-- dist/typings/tableexport.d.ts | 1 + package.json | 2 +- src/stable/css/tableexport.css | 2 +- src/stable/css/tableexport.min.css | 2 +- src/stable/js/tableexport.js | 38 ++++++++++++++++++++++------- src/stable/js/tableexport.min.js | 4 +-- src/stable/typings/tableexport.d.ts | 1 + 13 files changed, 62 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 4050482..e6e2779 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ $("table").tableExport({ ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file - trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text + trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces (including non-breaking spaces), and tabs from cell text }); ``` > **Note:** to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section. diff --git a/bower.json b/bower.json index 024daf9..841ed3a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "tableexport.js", - "version": "3.3.7", + "version": "3.3.8", "authors": [ "clarketm " ], diff --git a/dist/css/tableexport.css b/dist/css/tableexport.css index e628809..634564c 100644 --- a/dist/css/tableexport.css +++ b/dist/css/tableexport.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ diff --git a/dist/css/tableexport.min.css b/dist/css/tableexport.min.css index 55048f6..cad42d2 100644 --- a/dist/css/tableexport.min.css +++ b/dist/css/tableexport.min.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */.top{caption-side:top}.bottom{caption-side:bottom}.button-default,.button-default:active,.button-default:focus,.button-default:hover{text-decoration:none}.button-default{font:700 12px sans-serif;color:#222;cursor:pointer;padding:5px;margin:5px}.button-default.csv:before,.button-default.txt:before,.button-default.xls:before,.button-default.xlsx:before{content:none}.csv:before,.txt:before,.xls:before,.xlsx:before{content:""}.csv,.txt,.xls,.xlsx{margin:4px 0}.csv:before,.txt:before,.xls:before,.xlsx:before{margin-right:10px;padding:11px 15px 12px;box-shadow:1px 1px 2px rgba(0,0,0,.2)}.xlsx:before{background:url(../img/xlsx.svg) center no-repeat #006400}.xls:before{background:url(../img/xls.svg) center no-repeat green}.csv:before{background:url(../img/csv.svg) center no-repeat #00f}.txt:before{background:url(../img/txt.svg) center no-repeat purple} \ No newline at end of file diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index b064725..9356c00 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ @@ -15,7 +15,7 @@ // Browser globals factory(root, root.jQuery, root.Blob, root.saveAs, root.XLSX); } -}(this, function (exports, $, Blob, saveAs, XLSX) { +}(this || window, function (exports, $, Blob, saveAs, XLSX) { 'use strict'; /** * TableExport main plugin constructor @@ -259,23 +259,30 @@ } ); - function trimWhitespace(string) { - if (self.settings.trimWhitespace) { - return $.trim(string); - } - return string; - } - + /** + * Removes leading/trailing whitespace from cell string + * @param string {String} + * @returns {String} trimmed string + */ function formatValue(string) { - string = trimWhitespace(string); - return string; + return self.settings.trimWhitespace ? string.trim() : string; } + /** + * Initializes table caption with export buttons + * @param exportButton {HTMLButtonElement} + */ function checkCaption(exportButton) { var $caption = $el.find('caption:not(.head)'); $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); } + /** + * Creates file export buttons + * @param dataObject {JSON} + * @param myContent {String} + * @param myClass {String} + */ function createObjButton(dataObject, myContent, myClass) { var exportButton = ""; checkCaption(exportButton); @@ -302,7 +309,7 @@ * Version. * @memberof TableExport.prototype */ - version: "3.3.7", + version: "3.3.8", /** * Default plugin options. * @memberof TableExport.prototype @@ -318,7 +325,7 @@ ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null) ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore") emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") - trimWhitespace: false // (Boolean), remove all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of cell text + trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces (including non-breaking spaces), and tabs from cell text (default: false) }, /** * Character set (character encoding) of the HTML. diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index 810b971..61c09b8 100644 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -1,6 +1,6 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ -!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(t,e,n,o,r){"use strict";var i=function(t,n,o){var s=this;s.settings=o?n:e.extend({},i.prototype.defaults,n),s.selectors=t;var a,p,f,l=i.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS,y=s.settings.emptyCSS instanceof Array?s.settings.emptyCSS.join(", "):s.settings.emptyCSS;return s.settings.bootstrap?(a=i.prototype.bootstrap[0]+" ",p=i.prototype.bootstrap[1]+" ",f=i.prototype.bootstrap[2]+" "):(a=i.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){var e=d.find("caption:not(.head)");e.length?e.append(t):d.prepend(''+t+"")}function n(e,n,o){var r="";t(r)}var d=e(this);o&&d.find("caption:not(.head)").remove();var m=d.find("tbody").find("tr"),m=s.settings.headings?m.add(d.find("thead>tr")):m,m=s.settings.footers?m.add(d.find("tfoot>tr")):m,g=s.settings.headings?d.find("thead>tr").length:0,b="id"===s.settings.fileName?d.attr("id")?d.attr("id"):i.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(t,o){var r={},s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(e(o).is(y))return" ";if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i=n?a+r[t][i]:a:p++,p!==s);i++);return new Array(a).concat(e(o).text())}return e(o).text()}}).get()]}}).get(),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.xlsx.mimeType,fileExtension:i.prototype.xlsx.fileExtension})),p=i.prototype.xlsx.buttonContent,f=i.prototype.xlsx.defaultClass;n(a,p,f)},xlsm:function(t,o){var r={},s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(e(o).is(y))return" ";if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i=n?a+r[t][i]:a:p++,p!==s);i++);return new Array(a).concat(e(o).text())}return e(o).text()}}).get()]}}).get(),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.xls.mimeType,fileExtension:i.prototype.xls.fileExtension})),p=i.prototype.xls.buttonContent,f=i.prototype.xls.defaultClass;n(a,p,f)},xls:function(t,o){var r=i.prototype.xls.separator,s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return o.map(function(t,n){if(!~c.indexOf(t)&&!e(n).is(x))return e(n).is(y)?" ":e(n).text()}).get().join(r)}}).get().join(t),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.xls.mimeType,fileExtension:i.prototype.xls.fileExtension})),p=i.prototype.xls.buttonContent,f=i.prototype.xls.defaultClass;n(a,p,f)},csv:function(t,o){var r=i.prototype.csv.separator,s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return o.map(function(t,n){if(!~c.indexOf(t)&&!e(n).is(x))return e(n).is(y)?" ":'"'+e(n).text().replace(/"/g,'""')+'"'}).get().join(r)}}).get().join(t),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.csv.mimeType,fileExtension:i.prototype.csv.fileExtension})),p=i.prototype.csv.buttonContent,f=i.prototype.csv.defaultClass;n(a,p,f)},txt:function(t,o){var r=i.prototype.txt.separator,s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return o.map(function(t,n){if(!~c.indexOf(t)&&!e(n).is(x))return e(n).is(y)?" ":e(n).text()}).get().join(r)}}).get().join(t),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.txt.mimeType,fileExtension:i.prototype.txt.fileExtension})),p=i.prototype.txt.buttonContent,f=i.prototype.txt.defaultClass;n(a,p,f)}};s.settings.formats.forEach(function(t){!(!r||"xls"!==t)&&(t="xlsm"),!r&&"xlsx"===t&&(t=null),t&&h[t](l,b)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,r=t.mimeType,s=t.fileExtension;i.prototype.export2file(n,r,o,s)}),s};i.prototype={version:"3.3.7",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty"},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return i.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var i=0;i!=t[o].length;++i){n.s.r>o&&(n.s.r=o),n.s.c>i&&(n.s.c=i),n.e.r'+t+"")}function d(t,e,o){var i="";n(i)}var m=e(this);o&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=s.settings.headings?g.add(m.find("thead>tr")):g,g=s.settings.footers?g.add(m.find("tfoot>tr")):g,b=s.settings.headings?m.find("thead>tr").length:0,h="id"===s.settings.fileName?m.attr("id")?m.attr("id"):r.prototype.defaultFileName:s.settings.fileName,v={xlsx:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(y))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xlsx.mimeType,fileExtension:r.prototype.xlsx.fileExtension})),p=r.prototype.xlsx.buttonContent,f=r.prototype.xlsx.defaultClass;d(a,p,f)},xlsm:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(y))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;d(a,p,f)},xls:function(n,o){var i=r.prototype.xls.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;d(a,p,f)},csv:function(n,o){var i=r.prototype.csv.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":'"'+t(e(o).text().replace(/"/g,'""'))+'"'}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.csv.mimeType,fileExtension:r.prototype.csv.fileExtension})),p=r.prototype.csv.buttonContent,f=r.prototype.csv.defaultClass;d(a,p,f)},txt:function(n,o){var i=r.prototype.txt.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.txt.mimeType,fileExtension:r.prototype.txt.fileExtension})),p=r.prototype.txt.buttonContent,f=r.prototype.txt.defaultClass;d(a,p,f)}};s.settings.formats.forEach(function(t){!(!i||"xls"!==t)&&(t="xlsm"),!i&&"xlsx"===t&&(t=null),t&&v[t](l,h)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,i=t.mimeType,s=t.fileExtension;r.prototype.export2file(n,i,o,s)}),s};r.prototype={version:"3.3.8",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return r.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var r=0;r!=t[o].length;++r){n.s.r>o&&(n.s.r=o),n.s.c>r&&(n.s.c=r),n.e.r" ], diff --git a/src/stable/css/tableexport.css b/src/stable/css/tableexport.css index e628809..634564c 100644 --- a/src/stable/css/tableexport.css +++ b/src/stable/css/tableexport.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ diff --git a/src/stable/css/tableexport.min.css b/src/stable/css/tableexport.min.css index 55048f6..cad42d2 100644 --- a/src/stable/css/tableexport.min.css +++ b/src/stable/css/tableexport.min.css @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */.top{caption-side:top}.bottom{caption-side:bottom}.button-default,.button-default:active,.button-default:focus,.button-default:hover{text-decoration:none}.button-default{font:700 12px sans-serif;color:#222;cursor:pointer;padding:5px;margin:5px}.button-default.csv:before,.button-default.txt:before,.button-default.xls:before,.button-default.xlsx:before{content:none}.csv:before,.txt:before,.xls:before,.xlsx:before{content:""}.csv,.txt,.xls,.xlsx{margin:4px 0}.csv:before,.txt:before,.xls:before,.xlsx:before{margin-right:10px;padding:11px 15px 12px;box-shadow:1px 1px 2px rgba(0,0,0,.2)}.xlsx:before{background:url(../img/xlsx.svg) center no-repeat #006400}.xls:before{background:url(../img/xls.svg) center no-repeat green}.csv:before{background:url(../img/csv.svg) center no-repeat #00f}.txt:before{background:url(../img/txt.svg) center no-repeat purple} \ No newline at end of file diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index 87f1eac..9356c00 100644 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ @@ -15,7 +15,7 @@ // Browser globals factory(root, root.jQuery, root.Blob, root.saveAs, root.XLSX); } -}(this, function (exports, $, Blob, saveAs, XLSX) { +}(this || window, function (exports, $, Blob, saveAs, XLSX) { 'use strict'; /** * TableExport main plugin constructor @@ -100,7 +100,7 @@ } return new Array(total).concat($(val).text()); } - return $(val).text(); + return formatValue($(val).text()); }).get()]; }).get(), dataObject = TableExport.prototype.escapeHtml( @@ -151,7 +151,7 @@ } return new Array(total).concat($(val).text()); } - return $(val).text(); + return formatValue($(val).text()); }).get()]; }).get(), dataObject = TableExport.prototype.escapeHtml( @@ -179,7 +179,7 @@ if ($(val).is(emptyCSS)) { return " " } - return $(val).text(); + return formatValue($(val).text()); }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -207,7 +207,7 @@ if ($(val).is(emptyCSS)) { return " " } - return '"' + $(val).text().replace(/"/g, '""') + '"'; + return '"' + formatValue($(val).text().replace(/"/g, '""')) + '"'; }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -235,7 +235,7 @@ if ($(val).is(emptyCSS)) { return " " } - return $(val).text(); + return formatValue($(val).text()); }).get().join(colD); }).get().join(rdel), dataObject = TableExport.prototype.escapeHtml( @@ -259,11 +259,30 @@ } ); + /** + * Removes leading/trailing whitespace from cell string + * @param string {String} + * @returns {String} trimmed string + */ + function formatValue(string) { + return self.settings.trimWhitespace ? string.trim() : string; + } + + /** + * Initializes table caption with export buttons + * @param exportButton {HTMLButtonElement} + */ function checkCaption(exportButton) { var $caption = $el.find('caption:not(.head)'); $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); } + /** + * Creates file export buttons + * @param dataObject {JSON} + * @param myContent {String} + * @param myClass {String} + */ function createObjButton(dataObject, myContent, myClass) { var exportButton = ""; checkCaption(exportButton); @@ -290,7 +309,7 @@ * Version. * @memberof TableExport.prototype */ - version: "3.3.7", + version: "3.3.8", /** * Default plugin options. * @memberof TableExport.prototype @@ -305,7 +324,8 @@ ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file (default: null) ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file (default: null) ignoreCSS: ".tableexport-ignore", // (selector, selector[]), selector(s) to exclude cells from the exported file (default: ".tableexport-ignore") - emptyCSS: ".tableexport-empty" // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") + emptyCSS: ".tableexport-empty", // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file (default: ".tableexport-empty") + trimWhitespace: false // (Boolean), remove all leading/trailing newlines, spaces (including non-breaking spaces), and tabs from cell text (default: false) }, /** * Character set (character encoding) of the HTML. diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 810b971..61c09b8 100644 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -1,6 +1,6 @@ /*! - * TableExport.js v3.3.7 (https://www.travismclarke.com) + * TableExport.js v3.3.8 (https://www.travismclarke.com) * Copyright 2016 Travis Clarke * Licensed under the MIT license */ -!function(t,e){"function"==typeof define&&define.amd?define(["exports","jquery","blobjs","file-saverjs","xlsx-js"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?e(exports,require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx-js")):e(t,t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(t,e,n,o,r){"use strict";var i=function(t,n,o){var s=this;s.settings=o?n:e.extend({},i.prototype.defaults,n),s.selectors=t;var a,p,f,l=i.prototype.rowDel,u=s.settings.ignoreRows instanceof Array?s.settings.ignoreRows:[s.settings.ignoreRows],c=s.settings.ignoreCols instanceof Array?s.settings.ignoreCols:[s.settings.ignoreCols],x=s.settings.ignoreCSS instanceof Array?s.settings.ignoreCSS.join(", "):s.settings.ignoreCSS,y=s.settings.emptyCSS instanceof Array?s.settings.emptyCSS.join(", "):s.settings.emptyCSS;return s.settings.bootstrap?(a=i.prototype.bootstrap[0]+" ",p=i.prototype.bootstrap[1]+" ",f=i.prototype.bootstrap[2]+" "):(a=i.prototype.defaultButton+" ",p=f=""),s.selectors.each(function(){function t(t){var e=d.find("caption:not(.head)");e.length?e.append(t):d.prepend(''+t+"")}function n(e,n,o){var r="";t(r)}var d=e(this);o&&d.find("caption:not(.head)").remove();var m=d.find("tbody").find("tr"),m=s.settings.headings?m.add(d.find("thead>tr")):m,m=s.settings.footers?m.add(d.find("tfoot>tr")):m,g=s.settings.headings?d.find("thead>tr").length:0,b="id"===s.settings.fileName?d.attr("id")?d.attr("id"):i.prototype.defaultFileName:s.settings.fileName,h={xlsx:function(t,o){var r={},s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(e(o).is(y))return" ";if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i=n?a+r[t][i]:a:p++,p!==s);i++);return new Array(a).concat(e(o).text())}return e(o).text()}}).get()]}}).get(),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.xlsx.mimeType,fileExtension:i.prototype.xlsx.fileExtension})),p=i.prototype.xlsx.buttonContent,f=i.prototype.xlsx.defaultClass;n(a,p,f)},xlsm:function(t,o){var r={},s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return[o.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x)){if(e(o).is(y))return" ";if(o.hasAttribute("colspan")&&(r[t]=r[t]||{},r[t][n+1]=o.getAttribute("colspan")-1),o.hasAttribute("rowspan"))for(var i=1;i=n?a+r[t][i]:a:p++,p!==s);i++);return new Array(a).concat(e(o).text())}return e(o).text()}}).get()]}}).get(),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.xls.mimeType,fileExtension:i.prototype.xls.fileExtension})),p=i.prototype.xls.buttonContent,f=i.prototype.xls.defaultClass;n(a,p,f)},xls:function(t,o){var r=i.prototype.xls.separator,s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return o.map(function(t,n){if(!~c.indexOf(t)&&!e(n).is(x))return e(n).is(y)?" ":e(n).text()}).get().join(r)}}).get().join(t),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.xls.mimeType,fileExtension:i.prototype.xls.fileExtension})),p=i.prototype.xls.buttonContent,f=i.prototype.xls.defaultClass;n(a,p,f)},csv:function(t,o){var r=i.prototype.csv.separator,s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return o.map(function(t,n){if(!~c.indexOf(t)&&!e(n).is(x))return e(n).is(y)?" ":'"'+e(n).text().replace(/"/g,'""')+'"'}).get().join(r)}}).get().join(t),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.csv.mimeType,fileExtension:i.prototype.csv.fileExtension})),p=i.prototype.csv.buttonContent,f=i.prototype.csv.defaultClass;n(a,p,f)},txt:function(t,o){var r=i.prototype.txt.separator,s=m.map(function(t,n){if(!~u.indexOf(t-g)&&!e(n).is(x)){var o=e(n).find("th, td");return o.map(function(t,n){if(!~c.indexOf(t)&&!e(n).is(x))return e(n).is(y)?" ":e(n).text()}).get().join(r)}}).get().join(t),a=i.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:i.prototype.txt.mimeType,fileExtension:i.prototype.txt.fileExtension})),p=i.prototype.txt.buttonContent,f=i.prototype.txt.defaultClass;n(a,p,f)}};s.settings.formats.forEach(function(t){!(!r||"xls"!==t)&&(t="xlsm"),!r&&"xlsx"===t&&(t=null),t&&h[t](l,b)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,r=t.mimeType,s=t.fileExtension;i.prototype.export2file(n,r,o,s)}),s};i.prototype={version:"3.3.7",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty"},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return i.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var i=0;i!=t[o].length;++i){n.s.r>o&&(n.s.r=o),n.s.c>i&&(n.s.c=i),n.e.r'+t+"")}function d(t,e,o){var i="";n(i)}var m=e(this);o&&m.find("caption:not(.head)").remove();var g=m.find("tbody").find("tr"),g=s.settings.headings?g.add(m.find("thead>tr")):g,g=s.settings.footers?g.add(m.find("tfoot>tr")):g,b=s.settings.headings?m.find("thead>tr").length:0,h="id"===s.settings.fileName?m.attr("id")?m.attr("id"):r.prototype.defaultFileName:s.settings.fileName,v={xlsx:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(y))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xlsx.mimeType,fileExtension:r.prototype.xlsx.fileExtension})),p=r.prototype.xlsx.buttonContent,f=r.prototype.xlsx.defaultClass;d(a,p,f)},xlsm:function(n,o){var i={},s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return[r.map(function(o,r){if(!~c.indexOf(o)&&!e(r).is(x)){if(e(r).is(y))return" ";if(r.hasAttribute("colspan")&&(i[n]=i[n]||{},i[n][o+1]=r.getAttribute("colspan")-1),r.hasAttribute("rowspan"))for(var s=1;s=o?p+i[n][s]:p:f++,f!==a);s++);return new Array(p).concat(e(r).text())}return t(e(r).text())}}).get()]}}).get(),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;d(a,p,f)},xls:function(n,o){var i=r.prototype.xls.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.xls.mimeType,fileExtension:r.prototype.xls.fileExtension})),p=r.prototype.xls.buttonContent,f=r.prototype.xls.defaultClass;d(a,p,f)},csv:function(n,o){var i=r.prototype.csv.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":'"'+t(e(o).text().replace(/"/g,'""'))+'"'}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.csv.mimeType,fileExtension:r.prototype.csv.fileExtension})),p=r.prototype.csv.buttonContent,f=r.prototype.csv.defaultClass;d(a,p,f)},txt:function(n,o){var i=r.prototype.txt.separator,s=g.map(function(n,o){if(!~u.indexOf(n-b)&&!e(o).is(x)){var r=e(o).find("th, td");return r.map(function(n,o){if(!~c.indexOf(n)&&!e(o).is(x))return e(o).is(y)?" ":t(e(o).text())}).get().join(i)}}).get().join(n),a=r.prototype.escapeHtml(JSON.stringify({data:s,fileName:o,mimeType:r.prototype.txt.mimeType,fileExtension:r.prototype.txt.fileExtension})),p=r.prototype.txt.buttonContent,f=r.prototype.txt.defaultClass;d(a,p,f)}};s.settings.formats.forEach(function(t){!(!i||"xls"!==t)&&(t="xlsm"),!i&&"xlsx"===t&&(t=null),t&&v[t](l,h)})}),e("button[data-fileblob]").off("click").on("click",function(){var t=e(this).data("fileblob"),n=t.data,o=t.fileName,i=t.mimeType,s=t.fileExtension;r.prototype.export2file(n,i,o,s)}),s};r.prototype={version:"3.3.8",defaults:{headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore",emptyCSS:".tableexport-empty",trimWhitespace:!1},charset:"charset=utf-8",defaultFileName:"myDownload",defaultButton:"button-default",bootstrap:["btn","btn-default","btn-toolbar"],rowDel:"\r\n",entityMap:{"&":"&","<":"<",">":">","'":"'","/":"/"},xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv"},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return r.prototype.entityMap[t]})},dateNum:function(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},n={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=0;o!=t.length;++o)for(var r=0;r!=t[o].length;++r){n.s.r>o&&(n.s.r=o),n.s.c>r&&(n.s.c=r),n.e.r