diff --git a/bower.json b/bower.json index 5423236..da126fe 100755 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "tableexport.js", - "version": "3.2.1", + "version": "3.2.2", "authors": [ "clarketm " ], diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index bff593a..fb14066 100755 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.1 (http://www.clarketravis.com) + * TableExport.js v3.2.2 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index cf0bfb0..71dbca6 100755 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.1 (http://www.clarketravis.com) + * TableExport.js v3.2.2 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ diff --git a/package.json b/package.json index 2d525fb..5ebe8ed 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,13 @@ "scripts": { "test": "gulp" }, + "repository": { + "type": "git", + "url": "https://github.com/clarketm/TableExport" + }, + "bugs": { + "url": "https://github.com/clarketm/TableExport/issues" + }, "dependencies": { "Blob": "*", "bootstrap": "~3.3.5", diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index bff593a..fb14066 100755 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.1 (http://www.clarketravis.com) + * TableExport.js v3.2.2 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index cf0bfb0..71dbca6 100755 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.2.1 (http://www.clarketravis.com) + * TableExport.js v3.2.2 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ diff --git a/src/v3/tableexport-3.0.js b/src/v3/tableexport-3.0.js deleted file mode 100755 index 707e68d..0000000 --- a/src/v3/tableexport-3.0.js +++ /dev/null @@ -1,239 +0,0 @@ -/*! - * TableExport.js v3.0.0 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ - -;(function (window, undefined) { - - /*--- GLOBALS ---*/ - var $ = window.jQuery; - - $.fn.tableExport = function (options) { - - var settings = $.extend({}, $.fn.tableExport.defaults, options), - rowD = $.fn.tableExport.rowDel, bootstrapClass, bootstrapTheme, bootstrapSpacing; - - if (settings.bootstrap) { - bootstrapClass = $.fn.tableExport.bootstrap[0] + " "; - bootstrapTheme = $.fn.tableExport.bootstrap[1] + " "; - bootstrapSpacing = $.fn.tableExport.bootstrap[2] + " "; - } else { - bootstrapClass = $.fn.tableExport.defaultButton + " "; - bootstrapTheme = bootstrapSpacing = ""; - } - - - return this.each(function () { - var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, - 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({ - data: dataURL, - name: name - }), - myContent = $.fn.tableExport.xlsx.buttonContent, - myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - xls: function (rdel, name) { - var colD = $.fn.tableExport.xls.separator, - 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() - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".xls", - myContent = $.fn.tableExport.xls.buttonContent, - myClass = $.fn.tableExport.xls.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - csv: function (rdel, name) { - rdel = '"' + rdel + '"'; - var colD = '"' + $.fn.tableExport.csv.separator + '"', - 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, '""') - }).get().join(colD); - }).get().join(rdel) + '"'), - myFile = name + ".csv", - myContent = $.fn.tableExport.csv.buttonContent, - myClass = $.fn.tableExport.csv.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - txt: function (rdel, name) { - var colD = $.fn.tableExport.txt.separator, - 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() - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".txt", - myContent = $.fn.tableExport.txt.buttonContent, - myClass = $.fn.tableExport.txt.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - } - }; - - settings.formats.forEach( - function (key) { - exporters[key](rowD, fileName); - } - ); - - function checkCaption(exportButton) { - var $caption = $el.find('caption:not(.head)'); - $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); - } - - function createButton(dataURL, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - } - - function createObjButton(dataObject, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - addListener(myClass) - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.name; - export2xlsx(data, fileName); - } - }); - } - - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) - formats: ["xls", "csv", "txt"], // (String[]), filetype for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom" // (top, bottom), position of the caption element relative to table, (default: "bottom") - }; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: "," - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " " - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - -}(window)); - -function dateNum(v, date1904) { - if (date1904) v += 1462; - var epoch = Date.parse(v); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); -} - -function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; -} - -function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; -} - -function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; -} - -function export2xlsx(data, name) { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}; - var wbout = XLSX.write(wb, wopts); - - saveAs(new Blob([string2ArrayBuffer(wbout)], - {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), - name + ".xlsx"); -} - - - - - diff --git a/src/v3/tableexport-3.0.min.js b/src/v3/tableexport-3.0.min.js deleted file mode 100755 index 7361a51..0000000 --- a/src/v3/tableexport-3.0.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.0.0 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -;(function(a,c){var b=a.jQuery;b.fn.tableExport=function(f){var g=b.extend({},b.fn.tableExport.defaults,f),i=b.fn.tableExport.rowDel,h,d,e;if(g.bootstrap){h=b.fn.tableExport.bootstrap[0]+" ";d=b.fn.tableExport.bootstrap[1]+" ";e=b.fn.tableExport.bootstrap[2]+" "}else{h=b.fn.tableExport.defaultButton+" ";d=e=""}return this.each(function(){var n=b(this),l=g.headings?n.find("tr"):n.find("tr:has(td)"),q=g.fileName==="id"?(n.attr("id")?n.attr("id"):b.fn.tableExport.defaultFileName):g.fileName,o={xlsx:function(v,r){var w=l.map(function(y,z){var x=b(z).find("th, td");return x.map(function(A,B){return b(B).text()})}).get(),u=JSON.stringify({data:w,name:r}),t=b.fn.tableExport.xlsx.buttonContent,s=b.fn.tableExport.xlsx.defaultClass;p(u,t,s)},xls:function(s,t){var r=b.fn.tableExport.xls.separator,x="data:application/vnd.ms-excel;charset=utf-8,"+encodeURIComponent(l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).html()}).get().join(r)}).get().join(s)),w=t+".xls",v=b.fn.tableExport.xls.buttonContent,u=b.fn.tableExport.xls.defaultClass;j(x,w,v,u)},csv:function(s,t){s='"'+s+'"';var r='"'+b.fn.tableExport.csv.separator+'"',x="data:text/csv;charset=utf-8,"+encodeURIComponent('"'+l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).text().replace(/"/g,'""')}).get().join(r)}).get().join(s)+'"'),w=t+".csv",v=b.fn.tableExport.csv.buttonContent,u=b.fn.tableExport.csv.defaultClass;j(x,w,v,u)},txt:function(s,t){var r=b.fn.tableExport.txt.separator,x="data:text/plain;charset=utf-8,"+encodeURIComponent(l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).text()}).get().join(r)}).get().join(s)),w=t+".txt",v=b.fn.tableExport.txt.buttonContent,u=b.fn.tableExport.txt.defaultClass;j(x,w,v,u)}};g.formats.forEach(function(r){o[r](i,q)});function k(r){var s=n.find("caption:not(.head)");s.length?s.append(r):n.prepend(''+r+"")}function j(v,t,s,r){var u=""+s+"";k(u)}function p(t,s,r){var u=""+s+"";k(u);m(r)}function m(s){var r="."+s;return b(r).on("click",function(v){if(b(this).data("obj")){v.preventDefault();var t=b(this).data("obj"),u=t.data,w=t.name;export2xlsx(u,w)}})}})};b.fn.tableExport.defaults={headings:true,formats:["xls","csv","txt"],fileName:"id",bootstrap:true,position:"bottom"};b.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx"};b.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:"\t"};b.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:","};b.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" "};b.fn.tableExport.defaultFileName="myDownload";b.fn.tableExport.defaultButton="button-default";b.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"];b.fn.tableExport.rowDel="\r\n"}(window));function dateNum(b,a){if(a){b+=1462}var c=Date.parse(b);return(c-new Date(Date.UTC(1899,11,30)))/(24*60*60*1000)}function createSheet(g,f){var b={};var c={s:{c:10000000,r:10000000},e:{c:0,r:0}};for(var e=0;e!=g.length;++e){for(var h=0;h!=g[e].length;++h){if(c.s.r>e){c.s.r=e}if(c.s.c>h){c.s.c=h}if(c.e.r' + exportButton + ''); - } - - function createButton(dataURL, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - } - - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - addListener(myClass) - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.name; - export2xlsx(data, fileName); - } - }); - } - - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) - formats: ["xls", "csv", "txt"], // (String[]), filetype for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom" // (top, bottom), position of the caption element relative to table, (default: "bottom") - }; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: "," - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " " - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - function dateNum(v, date1904) { - if (date1904) v += 1462; - var epoch = Date.parse(v); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); - } - - function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; - } - - function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; - } - - function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; - } - - function export2xlsx(data, name) { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}; - var wbout = XLSX.write(wb, wopts); - - saveAs(new Blob([string2ArrayBuffer(wbout)], - {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), - name + ".xlsx"); - } -}(window)); \ No newline at end of file diff --git a/src/v3/tableexport-3.1.1.min.js b/src/v3/tableexport-3.1.1.min.js deleted file mode 100755 index 0285478..0000000 --- a/src/v3/tableexport-3.1.1.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.1.1 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -!function(t,n){function e(t,n){n&&(t+=1462);var e=Date.parse(t);return(e-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,n){for(var a={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var l=0;l!=t[r].length;++l){o.s.r>r&&(o.s.r=r),o.s.c>l&&(o.s.c=l),o.e.r'+t+"")}function f(a,o,r,l){var s=""+r+"";t(s)}function i(a,o,r,l){var s=""+r+"";t(s),p(l)}function p(t){var n="."+t;return s(n).on("click",function(t){if(s(this).data("obj")){t.preventDefault();var n=s(this).data("obj"),e=n.data,a=n.name;l(e,a)}})}var u=s(this),x=o.headings?u.find("tr"):u.find("tr:has(td)"),c="id"===o.fileName?u.attr("id")?u.attr("id"):s.fn.tableExport.defaultFileName:o.fileName,d={xlsx:function(t,n){var e=x.map(function(t,n){var e=s(n).find("th, td");return e.map(function(t,n){return s(n).text()})}).get(),a=JSON.stringify({data:e,name:n}).replace(/'/g,"'"),o=n+".xlsx",r=s.fn.tableExport.xlsx.buttonContent,l=s.fn.tableExport.xlsx.defaultClass;i(a,o,r,l)},xls:function(t,n){var e=s.fn.tableExport.xls.separator,a="data:application/vnd.ms-excel;charset=utf-16,"+encodeURIComponent(x.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).html()}).get().join(e)}).get().join(t)),o=n+".xls",r=s.fn.tableExport.xls.buttonContent,l=s.fn.tableExport.xls.defaultClass;f(a,o,r,l)},csv:function(t,n){t='"'+t+'"';var e='"'+s.fn.tableExport.csv.separator+'"',a="data:text/csv;charset=utf-16,"+encodeURIComponent('"'+x.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text().replace(/"/g,'""')}).get().join(e)}).get().join(t)+'"'),o=n+".csv",r=s.fn.tableExport.csv.buttonContent,l=s.fn.tableExport.csv.defaultClass;f(a,o,r,l)},txt:function(t,n){var e=s.fn.tableExport.txt.separator,a="data:text/plain;charset=utf-16,"+encodeURIComponent(x.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text()}).get().join(e)}).get().join(t)),o=n+".txt",r=s.fn.tableExport.txt.buttonContent,l=s.fn.tableExport.txt.defaultClass;f(a,o,r,l)}};o.formats.forEach(function(t){d[t](r,c)})})},s.fn.tableExport.defaults={headings:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom"},s.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx"},s.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" "},s.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:","},s.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" "},s.fn.tableExport.defaultFileName="myDownload",s.fn.tableExport.defaultButton="button-default",s.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],s.fn.tableExport.rowDel="\r\n"}(window); \ No newline at end of file diff --git a/src/v3/tableexport-3.1.2.js b/src/v3/tableexport-3.1.2.js deleted file mode 100644 index 5e4a5e6..0000000 --- a/src/v3/tableexport-3.1.2.js +++ /dev/null @@ -1,233 +0,0 @@ -/*! - * TableExport.js v3.1.2 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ - -;(function (window, undefined) { - - /*--- GLOBALS ---*/ - var $ = window.jQuery; - - $.fn.tableExport = function (options) { - - var settings = $.extend({}, $.fn.tableExport.defaults, options), - rowD = $.fn.tableExport.rowDel, bootstrapClass, bootstrapTheme, bootstrapSpacing; - - if (settings.bootstrap) { - bootstrapClass = $.fn.tableExport.bootstrap[0] + " "; - bootstrapTheme = $.fn.tableExport.bootstrap[1] + " "; - bootstrapSpacing = $.fn.tableExport.bootstrap[2] + " "; - } else { - bootstrapClass = $.fn.tableExport.defaultButton + " "; - bootstrapTheme = bootstrapSpacing = ""; - } - - - return this.each(function () { - var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, - 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({ - data: dataURL, - name: name - }).replace(/'/g, "'"), - 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,' + - encodeURIComponent($rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).html() - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".xls", - myContent = $.fn.tableExport.xls.buttonContent, - myClass = $.fn.tableExport.xls.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - csv: function (rdel, name) { - rdel = '"' + rdel + '"'; - var colD = '"' + $.fn.tableExport.csv.separator + '"', - dataURL = 'data:text/csv;charset=utf-16,' + - encodeURIComponent('"' + $rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).text().replace(/"/g, '""') - }).get().join(colD); - }).get().join(rdel) + '"'), - myFile = name + ".csv", - myContent = $.fn.tableExport.csv.buttonContent, - myClass = $.fn.tableExport.csv.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - txt: function (rdel, name) { - var colD = $.fn.tableExport.txt.separator, - dataURL = 'data:text/plain;charset=utf-16,' + - encodeURIComponent($rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).text() - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".txt", - myContent = $.fn.tableExport.txt.buttonContent, - myClass = $.fn.tableExport.txt.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - } - }; - - settings.formats.forEach( - function (key) { - exporters[key](rowD, fileName); - } - ); - - function checkCaption(exportButton) { - var $caption = $el.find('caption:not(.head)'); - $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); - } - - function createButton(dataURL, myFile, myContent, myClass) { - var exportButton = '' + myContent + ''; - checkCaption(exportButton); - } - - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - addListener(myClass) - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.name; - export2xlsx(data, fileName); - } - }); - } - - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) - formats: ["xls", "csv", "txt"], // (String[]), filetype for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom" // (top, bottom), position of the caption element relative to table, (default: "bottom") - }; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: "," - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " " - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - function dateNum(v, date1904) { - if (date1904) v += 1462; - var epoch = Date.parse(v); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); - } - - function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; - } - - function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; - } - - function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; - } - - function export2xlsx(data, name) { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}; - var wbout = XLSX.write(wb, wopts); - - saveAs(new Blob([string2ArrayBuffer(wbout)], - {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), - name + ".xlsx"); - } -}(window)); \ No newline at end of file diff --git a/src/v3/tableexport-3.1.2.min.js b/src/v3/tableexport-3.1.2.min.js deleted file mode 100644 index 6436bf4..0000000 --- a/src/v3/tableexport-3.1.2.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.1.2 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -!function(t,n){function e(t,n){n&&(t+=1462);var e=Date.parse(t);return(e-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,n){for(var a={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var l=0;l!=t[r].length;++l){o.s.r>r&&(o.s.r=r),o.s.c>l&&(o.s.c=l),o.e.r'+t+"")}function f(a,o,r,l){var s=''+r+"";t(s)}function i(a,o,r,l){var s=""+r+"";t(s),p(l)}function p(t){var n="."+t;return s(n).on("click",function(t){if(s(this).data("obj")){t.preventDefault();var n=s(this).data("obj"),e=n.data,a=n.name;l(e,a)}})}var u=s(this),x=o.headings?u.find("tr"):u.find("tr:has(td)"),c="id"===o.fileName?u.attr("id")?u.attr("id"):s.fn.tableExport.defaultFileName:o.fileName,d={xlsx:function(t,n){var e=x.map(function(t,n){var e=s(n).find("th, td");return e.map(function(t,n){return s(n).text()})}).get(),a=JSON.stringify({data:e,name:n}).replace(/'/g,"'"),o=n+".xlsx",r=s.fn.tableExport.xlsx.buttonContent,l=s.fn.tableExport.xlsx.defaultClass;i(a,o,r,l)},xls:function(t,n){var e=s.fn.tableExport.xls.separator,a="data:application/vnd.ms-excel;charset=utf-16,"+encodeURIComponent(x.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).html()}).get().join(e)}).get().join(t)),o=n+".xls",r=s.fn.tableExport.xls.buttonContent,l=s.fn.tableExport.xls.defaultClass;f(a,o,r,l)},csv:function(t,n){t='"'+t+'"';var e='"'+s.fn.tableExport.csv.separator+'"',a="data:text/csv;charset=utf-16,"+encodeURIComponent('"'+x.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text().replace(/"/g,'""')}).get().join(e)}).get().join(t)+'"'),o=n+".csv",r=s.fn.tableExport.csv.buttonContent,l=s.fn.tableExport.csv.defaultClass;f(a,o,r,l)},txt:function(t,n){var e=s.fn.tableExport.txt.separator,a="data:text/plain;charset=utf-16,"+encodeURIComponent(x.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text()}).get().join(e)}).get().join(t)),o=n+".txt",r=s.fn.tableExport.txt.buttonContent,l=s.fn.tableExport.txt.defaultClass;f(a,o,r,l)}};o.formats.forEach(function(t){d[t](r,c)})})},s.fn.tableExport.defaults={headings:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom"},s.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx"},s.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" "},s.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:","},s.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" "},s.fn.tableExport.defaultFileName="myDownload",s.fn.tableExport.defaultButton="button-default",s.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],s.fn.tableExport.rowDel="\r\n"}(window); \ No newline at end of file diff --git a/src/v3/tableexport-3.1.3.js b/src/v3/tableexport-3.1.3.js deleted file mode 100644 index 9f593d7..0000000 --- a/src/v3/tableexport-3.1.3.js +++ /dev/null @@ -1,242 +0,0 @@ -/*! - * TableExport.js v3.1.3 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ - -;(function (window, undefined) { - - /*--- GLOBALS ---*/ - var $ = window.jQuery; - - $.fn.tableExport = function (options) { - - var settings = $.extend({}, $.fn.tableExport.defaults, options), - rowD = $.fn.tableExport.rowDel, bootstrapClass, bootstrapTheme, bootstrapSpacing; - - if (settings.bootstrap) { - bootstrapClass = $.fn.tableExport.bootstrap[0] + " "; - bootstrapTheme = $.fn.tableExport.bootstrap[1] + " "; - bootstrapSpacing = $.fn.tableExport.bootstrap[2] + " "; - } else { - bootstrapClass = $.fn.tableExport.defaultButton + " "; - bootstrapTheme = bootstrapSpacing = ""; - } - - - return this.each(function () { - var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, - 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()]; - }).get(), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - name: name - })), - 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-8,' + - encodeURIComponent($rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).text(); - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".xls", - myContent = $.fn.tableExport.xls.buttonContent, - myClass = $.fn.tableExport.xls.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - csv: function (rdel, name) { - rdel = '"' + rdel + '"'; - var colD = '"' + $.fn.tableExport.csv.separator + '"', - 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, '""'); - }).get().join(colD); - }).get().join(rdel) + '"'), - myFile = name + ".csv", - myContent = $.fn.tableExport.csv.buttonContent, - myClass = $.fn.tableExport.csv.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - txt: function (rdel, name) { - var colD = $.fn.tableExport.txt.separator, - 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(); - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".txt", - myContent = $.fn.tableExport.txt.buttonContent, - myClass = $.fn.tableExport.txt.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - } - }; - - settings.formats.forEach( - function (key) { - exporters[key](rowD, fileName); - } - ); - - function checkCaption(exportButton) { - var $caption = $el.find('caption:not(.head)'); - $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); - } - - function createButton(dataURL, myFile, myContent, myClass) { - var exportButton = '' + myContent + ''; - checkCaption(exportButton); - } - - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - addListener(myClass) - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.name; - export2xlsx(data, fileName); - } - }); - } - - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) - formats: ["xls", "csv", "txt"], // (String[]), filetype for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom" // (top, bottom), position of the caption element relative to table, (default: "bottom") - }; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: "," - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " " - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - $.fn.tableExport.entityMap = {"&": "&", "<": "<", ">": ">", "'": ''', "/": '/'}; - - 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); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); - } - - function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; - } - - function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; - } - - function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; - } - - function export2xlsx(data, name) { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}; - var wbout = XLSX.write(wb, wopts); - - saveAs(new Blob([string2ArrayBuffer(wbout)], - {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), - name + ".xlsx"); - } -}(window)); \ No newline at end of file diff --git a/src/v3/tableexport-3.1.3.min.js b/src/v3/tableexport-3.1.3.min.js deleted file mode 100644 index 28d63d8..0000000 --- a/src/v3/tableexport-3.1.3.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.1.3 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -!function(t,n){function e(t){return String(t).replace(/[&<>'\/]/g,function(t){return s.fn.tableExport.entityMap[t]})}function a(t,n){n&&(t+=1462);var e=Date.parse(t);return(e-new Date(Date.UTC(1899,11,30)))/864e5}function o(t,n){for(var e={},o={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var l=0;l!=t[r].length;++l){o.s.r>r&&(o.s.r=r),o.s.c>l&&(o.s.c=l),o.e.r'+t+"")}function i(e,o,r,l){var f=''+r+"";t(f)}function p(e,o,r,l){var f=""+r+"";t(f),u(l)}function u(t){var n="."+t;return s(n).on("click",function(t){if(s(this).data("obj")){t.preventDefault();var n=s(this).data("obj"),e=n.data,a=n.name;f(e,a)}})}var x=s(this),c=r.headings?x.find("tr"):x.find("tr:has(td)"),b="id"===r.fileName?x.attr("id")?x.attr("id"):s.fn.tableExport.defaultFileName:r.fileName,d={xlsx:function(t,n){var a=c.map(function(t,n){var e=s(n).find("th, td");return[e.map(function(t,n){return s(n).text()}).get()]}).get(),o=e(JSON.stringify({data:a,name:n})),r=n+".xlsx",l=s.fn.tableExport.xlsx.buttonContent,f=s.fn.tableExport.xlsx.defaultClass;p(o,r,l,f)},xls:function(t,n){var e=s.fn.tableExport.xls.separator,a="data:application/vnd.ms-excel;charset=utf-8,"+encodeURIComponent(c.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text()}).get().join(e)}).get().join(t)),o=n+".xls",r=s.fn.tableExport.xls.buttonContent,l=s.fn.tableExport.xls.defaultClass;i(a,o,r,l)},csv:function(t,n){t='"'+t+'"';var e='"'+s.fn.tableExport.csv.separator+'"',a="data:text/csv;charset=utf-8,"+encodeURIComponent('"'+c.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text().replace(/"/g,'""')}).get().join(e)}).get().join(t)+'"'),o=n+".csv",r=s.fn.tableExport.csv.buttonContent,l=s.fn.tableExport.csv.defaultClass;i(a,o,r,l)},txt:function(t,n){var e=s.fn.tableExport.txt.separator,a="data:text/plain;charset=utf-8,"+encodeURIComponent(c.map(function(t,n){var a=s(n).find("th, td");return a.map(function(t,n){return s(n).text()}).get().join(e)}).get().join(t)),o=n+".txt",r=s.fn.tableExport.txt.buttonContent,l=s.fn.tableExport.txt.defaultClass;i(a,o,r,l)}};r.formats.forEach(function(t){d[t](l,b)})})},s.fn.tableExport.defaults={headings:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom"},s.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx"},s.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" "},s.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:","},s.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" "},s.fn.tableExport.defaultFileName="myDownload",s.fn.tableExport.defaultButton="button-default",s.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],s.fn.tableExport.rowDel="\r\n",s.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file diff --git a/src/v3/tableexport-3.1.js b/src/v3/tableexport-3.1.js deleted file mode 100755 index 177da35..0000000 --- a/src/v3/tableexport-3.1.js +++ /dev/null @@ -1,240 +0,0 @@ -/*! - * TableExport.js v3.1.0 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ - -;(function (window, undefined) { - - /*--- GLOBALS ---*/ - var $ = window.jQuery; - - $.fn.tableExport = function (options) { - - var settings = $.extend({}, $.fn.tableExport.defaults, options), - rowD = $.fn.tableExport.rowDel, bootstrapClass, bootstrapTheme, bootstrapSpacing; - - if (settings.bootstrap) { - bootstrapClass = $.fn.tableExport.bootstrap[0] + " "; - bootstrapTheme = $.fn.tableExport.bootstrap[1] + " "; - bootstrapSpacing = $.fn.tableExport.bootstrap[2] + " "; - } else { - bootstrapClass = $.fn.tableExport.defaultButton + " "; - bootstrapTheme = bootstrapSpacing = ""; - } - - - return this.each(function () { - var $el = $(this), - $rows = settings.headings ? $el.find('tr') : $el.find('tr:has(td)'), - fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, - 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({ - data: dataURL, - name: name - }), - 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,' + - encodeURIComponent($rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).html() - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".xls", - myContent = $.fn.tableExport.xls.buttonContent, - myClass = $.fn.tableExport.xls.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - csv: function (rdel, name) { - rdel = '"' + rdel + '"'; - var colD = '"' + $.fn.tableExport.csv.separator + '"', - dataURL = 'data:text/csv;charset=utf-16,' + - encodeURIComponent('"' + $rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).text().replace(/"/g, '""') - }).get().join(colD); - }).get().join(rdel) + '"'), - myFile = name + ".csv", - myContent = $.fn.tableExport.csv.buttonContent, - myClass = $.fn.tableExport.csv.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - }, - txt: function (rdel, name) { - var colD = $.fn.tableExport.txt.separator, - dataURL = 'data:text/plain;charset=utf-16,' + - encodeURIComponent($rows.map(function (i, val) { - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - return $(val).text() - }).get().join(colD); - }).get().join(rdel)), - myFile = name + ".txt", - myContent = $.fn.tableExport.txt.buttonContent, - myClass = $.fn.tableExport.txt.defaultClass; - createButton(dataURL, myFile, myContent, myClass); - } - }; - - settings.formats.forEach( - function (key) { - exporters[key](rowD, fileName); - } - ); - - function checkCaption(exportButton) { - var $caption = $el.find('caption:not(.head)'); - $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); - } - - function createButton(dataURL, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - } - - function createObjButton(dataObject, myFile, myContent, myClass) { - var exportButton = "" + myContent + ""; - checkCaption(exportButton); - addListener(myClass) - } - - function addListener(el) { - var $el = "." + el; - return $($el).on("click", function (e) { - if ($(this).data("obj")) { - e.preventDefault(); - var object = $(this).data("obj"), - data = object.data, - fileName = object.name; - export2xlsx(data, fileName); - } - }); - } - - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th elements) in the first row, (default: true) - formats: ["xls", "csv", "txt"], // (String[]), filetype for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom" // (top, bottom), position of the caption element relative to table, (default: "bottom") - }; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: "," - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " " - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - -}(window)); - -function dateNum(v, date1904) { - if (date1904) v += 1462; - var epoch = Date.parse(v); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); -} - -function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; -} - -function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; -} - -function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; -} - -function export2xlsx(data, name) { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}; - var wbout = XLSX.write(wb, wopts); - - saveAs(new Blob([string2ArrayBuffer(wbout)], - {type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}), - name + ".xlsx"); -} - - - - - diff --git a/src/v3/tableexport-3.1.min.js b/src/v3/tableexport-3.1.min.js deleted file mode 100755 index a3cda0f..0000000 --- a/src/v3/tableexport-3.1.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.1.0 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -;(function(a,c){var b=a.jQuery;b.fn.tableExport=function(f){var g=b.extend({},b.fn.tableExport.defaults,f),i=b.fn.tableExport.rowDel,h,d,e;if(g.bootstrap){h=b.fn.tableExport.bootstrap[0]+" ";d=b.fn.tableExport.bootstrap[1]+" ";e=b.fn.tableExport.bootstrap[2]+" "}else{h=b.fn.tableExport.defaultButton+" ";d=e=""}return this.each(function(){var n=b(this),l=g.headings?n.find("tr"):n.find("tr:has(td)"),q=g.fileName==="id"?(n.attr("id")?n.attr("id"):b.fn.tableExport.defaultFileName):g.fileName,o={xlsx:function(w,r){var x=l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).text()})}).get(),v=JSON.stringify({data:x,name:r}),u=r+".xlsx",t=b.fn.tableExport.xlsx.buttonContent,s=b.fn.tableExport.xlsx.defaultClass;p(v,u,t,s)},xls:function(s,t){var r=b.fn.tableExport.xls.separator,x="data:application/vnd.ms-excel;charset=utf-16,"+encodeURIComponent(l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).html()}).get().join(r)}).get().join(s)),w=t+".xls",v=b.fn.tableExport.xls.buttonContent,u=b.fn.tableExport.xls.defaultClass;j(x,w,v,u)},csv:function(s,t){s='"'+s+'"';var r='"'+b.fn.tableExport.csv.separator+'"',x="data:text/csv;charset=utf-16,"+encodeURIComponent('"'+l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).text().replace(/"/g,'""')}).get().join(r)}).get().join(s)+'"'),w=t+".csv",v=b.fn.tableExport.csv.buttonContent,u=b.fn.tableExport.csv.defaultClass;j(x,w,v,u)},txt:function(s,t){var r=b.fn.tableExport.txt.separator,x="data:text/plain;charset=utf-16,"+encodeURIComponent(l.map(function(z,A){var y=b(A).find("th, td");return y.map(function(B,C){return b(C).text()}).get().join(r)}).get().join(s)),w=t+".txt",v=b.fn.tableExport.txt.buttonContent,u=b.fn.tableExport.txt.defaultClass;j(x,w,v,u)}};g.formats.forEach(function(r){o[r](i,q)});function k(r){var s=n.find("caption:not(.head)");s.length?s.append(r):n.prepend(''+r+"")}function j(v,t,s,r){var u=""+s+"";k(u)}function p(u,t,s,r){var v=""+s+"";k(v);m(r)}function m(s){var r="."+s;return b(r).on("click",function(v){if(b(this).data("obj")){v.preventDefault();var t=b(this).data("obj"),u=t.data,w=t.name;export2xlsx(u,w)}})}})};b.fn.tableExport.defaults={headings:true,formats:["xls","csv","txt"],fileName:"id",bootstrap:true,position:"bottom"};b.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx"};b.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:"\t"};b.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:","};b.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" "};b.fn.tableExport.defaultFileName="myDownload";b.fn.tableExport.defaultButton="button-default";b.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"];b.fn.tableExport.rowDel="\r\n"}(window));function dateNum(b,a){if(a){b+=1462}var c=Date.parse(b);return(c-new Date(Date.UTC(1899,11,30)))/(24*60*60*1000)}function createSheet(g,f){var b={};var c={s:{c:10000000,r:10000000},e:{c:0,r:0}};for(var e=0;e!=g.length;++e){for(var h=0;h!=g[e].length;++h){if(c.s.r>e){c.s.r=e}if(c.s.c>h){c.s.c=h}if(c.e.rtr')) : $rows, - $rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows, - thAdj = settings.headings ? $el.find('thead>tr').length : 0, - fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, - exporters = { - xlsx: function (rDel, name) { - var dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj) || $(val).is(ignoreCSS)) { return;} - var $cols = $(val).find('th, td'); - return [$cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return;} - console.log($(val).is(ignoreCSS)); - return $(val).text(); - }).get()]; - }).get(), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.xlsx.mimeType, - fileExtension: $.fn.tableExport.xlsx.fileExtension - })), - myContent = $.fn.tableExport.xlsx.buttonContent, - myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - xls: function (rdel, name) { - var colD = $.fn.tableExport.xls.separator, - dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj) || $(val).is(ignoreCSS)) { return;} - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return;} - return $(val).text(); - }).get().join(colD); - }).get().join(rdel), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.xls.mimeType, - fileExtension: $.fn.tableExport.xls.fileExtension - })), - myContent = $.fn.tableExport.xls.buttonContent, - myClass = $.fn.tableExport.xls.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - csv: function (rdel, name) { - var colD = $.fn.tableExport.csv.separator, - dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj) || $(val).is(ignoreCSS)) { return;} - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return;} - return $(val).text(); - }).get().join(colD); - }).get().join(rdel), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.csv.mimeType, - fileExtension: $.fn.tableExport.csv.fileExtension - })), - myContent = $.fn.tableExport.csv.buttonContent, - myClass = $.fn.tableExport.csv.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - txt: function (rdel, name) { - var colD = $.fn.tableExport.txt.separator, - dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj) || $(val).is(ignoreCSS)) { return;} - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i) || $(val).is(ignoreCSS)) { return;} - return $(val).text(); - }).get().join(colD); - }).get().join(rdel), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.txt.mimeType, - fileExtension: $.fn.tableExport.txt.fileExtension - })), - myContent = $.fn.tableExport.txt.buttonContent, - myClass = $.fn.tableExport.txt.defaultClass; - createObjButton(dataObject, myContent, myClass); - } - }; - - settings.formats.forEach( - function (key) { - exporters[key](rowD, fileName); - } - ); - - function checkCaption(exportButton) { - var $caption = $el.find('caption:not(.head)'); - $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); - } - - function createObjButton(dataObject, myContent, myClass) { - var exportButton = ""; - checkCaption(exportButton); - } - }); - - $("button[data-fileblob]") - .off("click") - .on("click", function () { - var object = $(this).data("fileblob"), - data = object.data, - fileName = object.fileName, - mimeType = object.mimeType, - fileExtension = object.fileExtension; - export2file(data, mimeType, fileName, fileExtension); - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th or td elements) in the , (default: true) - footers: true, // (Boolean), display table footers (th or td elements) in the , (default: false) - formats: ["xls", "csv", "txt"], // (String[]), filetype(s) for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") - 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 from the exported file (default: ".tableexport-ignore") - }; - - $.fn.tableExport.charset = "charset=utf-8"; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx", - mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - fileExtension: ".xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t", - mimeType: "application/vnd.ms-excel", - fileExtension: ".xls" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: ",", - mimeType: "application/csv", - fileExtension: ".csv" - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " ", - mimeType: "text/plain", - fileExtension: ".txt" - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - $.fn.tableExport.entityMap = {"&": "&", "<": "<", ">": ">", "'": ''', "/": '/'}; - - 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); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); - } - - function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; - } - - function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; - } - - function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; - } - - function export2file(data, mime, name, extension) { - if (extension === ".xlsx") { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}, - wbout = XLSX.write(wb, wopts); - - data = string2ArrayBuffer(wbout); - } - saveAs(new Blob([data], - {type: mime + ";" + $.fn.tableExport.charset}), - name + extension); - } - -}(window)); \ No newline at end of file diff --git a/src/v3/tableexport-3.2.1.min.js b/src/v3/tableexport-3.2.1.min.js deleted file mode 100644 index cf0bfb0..0000000 --- a/src/v3/tableexport-3.2.1.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.2.1 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},i=0;i!=t.length;++i)for(var r=0;r!=t[i].length;++r){a.s.r>i&&(a.s.r=i),a.s.c>r&&(a.s.c=r),a.e.r'+t+"")}function f(n,a,i){var r="";t(r)}var u=l(this),b=u.find("tbody").find("tr"),b=i.headings?b.add(u.find("thead>tr")):b,b=i.footers?b.add(u.find("tfoor>tr")):b,d=i.headings?u.find("thead>tr").length:0,c="id"===i.fileName?u.attr("id")?u.attr("id"):l.fn.tableExport.defaultFileName:i.fileName,E={xlsx:function(t,e){var o=b.map(function(t,e){if(!~s.indexOf(t-d)&&!l(e).is(p)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)||l(e).is(p)?void 0:(console.log(l(e).is(p)),l(e).text())}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),i=l.fn.tableExport.xlsx.buttonContent,r=l.fn.tableExport.xlsx.defaultClass;f(a,i,r)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)&&!l(e).is(p)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)||l(e).is(p)?void 0:l(e).text()}).get().join(o)}}).get().join(t),i=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),r=l.fn.tableExport.xls.buttonContent,u=l.fn.tableExport.xls.defaultClass;f(i,r,u)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)&&!l(e).is(p)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)||l(e).is(p)?void 0:l(e).text()}).get().join(o)}}).get().join(t),i=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),r=l.fn.tableExport.csv.buttonContent,u=l.fn.tableExport.csv.defaultClass;f(i,r,u)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=b.map(function(t,e){if(!~s.indexOf(t-d)&&!l(e).is(p)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)||l(e).is(p)?void 0:l(e).text()}).get().join(o)}}).get().join(t),i=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),r=l.fn.tableExport.txt.buttonContent,u=l.fn.tableExport.txt.defaultClass;f(i,r,u)}};i.formats.forEach(function(t){E[t](r,c)})}),l("button[data-fileblob]").off("click").on("click",function(){var t=l(this).data("fileblob"),e=t.data,n=t.fileName,o=t.mimeType,a=t.fileExtension;f(e,o,n,a)})},l.fn.tableExport.defaults={headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null,ignoreCSS:".tableexport-ignore"},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file diff --git a/src/v3/tableexport-3.2.js b/src/v3/tableexport-3.2.js deleted file mode 100755 index b2ed266..0000000 --- a/src/v3/tableexport-3.2.js +++ /dev/null @@ -1,276 +0,0 @@ -/*! - * TableExport.js v3.2.0 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ - -;(function (window, undefined) { - - /*--- GLOBALS ---*/ - var $ = window.jQuery; - - $.fn.tableExport = function (options) { - - var settings = $.extend({}, $.fn.tableExport.defaults, options), - rowD = $.fn.tableExport.rowDel, - ignoreRows = settings.ignoreRows instanceof Array ? settings.ignoreRows : [settings.ignoreRows], - ignoreCols = settings.ignoreCols instanceof Array ? settings.ignoreCols : [settings.ignoreCols], - bootstrapClass, bootstrapTheme, bootstrapSpacing; - - if (settings.bootstrap) { - bootstrapClass = $.fn.tableExport.bootstrap[0] + " "; - bootstrapTheme = $.fn.tableExport.bootstrap[1] + " "; - bootstrapSpacing = $.fn.tableExport.bootstrap[2] + " "; - } else { - bootstrapClass = $.fn.tableExport.defaultButton + " "; - bootstrapTheme = bootstrapSpacing = ""; - } - - this.each(function () { - var $el = $(this), - $rows = $el.find('tbody').find('tr'), - $rows = settings.headings ? $rows.add($el.find('thead>tr')) : $rows, - $rows = settings.footers ? $rows.add($el.find('tfoor>tr')) : $rows, - thAdj = settings.headings ? $el.find('thead>tr').length : 0, - fileName = settings.fileName === "id" ? ($el.attr('id') ? $el.attr('id') : $.fn.tableExport.defaultFileName) : settings.fileName, - exporters = { - xlsx: function (rDel, name) { - var dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} - var $cols = $(val).find('th, td'); - return [$cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i)) { return;} - return $(val).text(); - }).get()]; - }).get(), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.xlsx.mimeType, - fileExtension: $.fn.tableExport.xlsx.fileExtension - })), - myContent = $.fn.tableExport.xlsx.buttonContent, - myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - xls: function (rdel, name) { - var colD = $.fn.tableExport.xls.separator, - dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i)) { return;} - return $(val).text(); - }).get().join(colD); - }).get().join(rdel), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.xls.mimeType, - fileExtension: $.fn.tableExport.xls.fileExtension - })), - myContent = $.fn.tableExport.xls.buttonContent, - myClass = $.fn.tableExport.xls.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - csv: function (rdel, name) { - var colD = $.fn.tableExport.csv.separator, - dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i)) { return;} - return $(val).text(); - }).get().join(colD); - }).get().join(rdel), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.csv.mimeType, - fileExtension: $.fn.tableExport.csv.fileExtension - })), - myContent = $.fn.tableExport.csv.buttonContent, - myClass = $.fn.tableExport.csv.defaultClass; - createObjButton(dataObject, myContent, myClass); - }, - txt: function (rdel, name) { - var colD = $.fn.tableExport.txt.separator, - dataURL = $rows.map(function (i, val) { - if (!!~ignoreRows.indexOf(i-thAdj)) { return;} - var $cols = $(val).find('th, td'); - return $cols.map(function (i, val) { - if (!!~ignoreCols.indexOf(i)) { return;} - return $(val).text(); - }).get().join(colD); - }).get().join(rdel), - dataObject = escapeHtml( - JSON.stringify({ - data: dataURL, - fileName: name, - mimeType: $.fn.tableExport.txt.mimeType, - fileExtension: $.fn.tableExport.txt.fileExtension - })), - myContent = $.fn.tableExport.txt.buttonContent, - myClass = $.fn.tableExport.txt.defaultClass; - createObjButton(dataObject, myContent, myClass); - } - }; - - settings.formats.forEach( - function (key) { - exporters[key](rowD, fileName); - } - ); - - function checkCaption(exportButton) { - var $caption = $el.find('caption:not(.head)'); - $caption.length ? $caption.append(exportButton) : $el.prepend('' + exportButton + ''); - } - - function createObjButton(dataObject, myContent, myClass) { - var exportButton = ""; - checkCaption(exportButton); - } - }); - - $("button[data-fileblob]").on("click", function () { - var object = $(this).data("fileblob"), - data = object.data, - fileName = object.fileName, - mimeType = object.mimeType, - fileExtension = object.fileExtension; - export2file(data, mimeType, fileName, fileExtension); - }); - }; - - // Define the plugin default properties. - $.fn.tableExport.defaults = { - headings: true, // (Boolean), display table headings (th or td elements) in the , (default: true) - footers: true, // (Boolean), display table footers (th or td elements) in the , (default: false) - formats: ["xls", "csv", "txt"], // (String[]), filetype(s) for the export, (default: ["xls", "csv", "txt"]) - fileName: "id", // (id, String), filename for the downloaded file, (default: "id") - bootstrap: true, // (Boolean), style buttons using bootstrap, (default: true) - position: "bottom", // (top, bottom), position of the caption element relative to table, (default: "bottom") - 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) - }; - - $.fn.tableExport.charset = "charset=utf-8"; - - $.fn.tableExport.xlsx = { - defaultClass: "xlsx", - buttonContent: "Export to xlsx", - mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - fileExtension: ".xlsx" - }; - - $.fn.tableExport.xls = { - defaultClass: "xls", - buttonContent: "Export to xls", - separator: "\t", - mimeType: "application/vnd.ms-excel", - fileExtension: ".xls" - }; - - $.fn.tableExport.csv = { - defaultClass: "csv", - buttonContent: "Export to csv", - separator: ",", - mimeType: "application/csv", - fileExtension: ".csv" - }; - - $.fn.tableExport.txt = { - defaultClass: "txt", - buttonContent: "Export to txt", - separator: " ", - mimeType: "text/plain", - fileExtension: ".txt" - }; - - $.fn.tableExport.defaultFileName = "myDownload"; - - $.fn.tableExport.defaultButton = "button-default"; - - $.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"]; - - $.fn.tableExport.rowDel = "\r\n"; - - $.fn.tableExport.entityMap = {"&": "&", "<": "<", ">": ">", "'": ''', "/": '/'}; - - 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); - return (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000); - } - - function createSheet(data, opts) { - var ws = {}; - var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}}; - for (var R = 0; R != data.length; ++R) { - for (var C = 0; C != data[R].length; ++C) { - if (range.s.r > R) range.s.r = R; - if (range.s.c > C) range.s.c = C; - if (range.e.r < R) range.e.r = R; - if (range.e.c < C) range.e.c = C; - var cell = {v: data[R][C]}; - if (cell.v == null) continue; - var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); - - if (typeof cell.v === 'number') cell.t = 'n'; - else if (typeof cell.v === 'boolean') cell.t = 'b'; - else if (cell.v instanceof Date) { - cell.t = 'n'; - cell.z = XLSX.SSF._table[14]; - cell.v = dateNum(cell.v); - } - else cell.t = 's'; - - ws[cell_ref] = cell; - } - } - if (range.s.c < 10000000) ws['!ref'] = XLSX.utils.encode_range(range); - return ws; - } - - function Workbook() { - if (!(this instanceof Workbook)) return new Workbook(); - this.SheetNames = []; - this.Sheets = {}; - } - - function string2ArrayBuffer(s) { - var buf = new ArrayBuffer(s.length); - var view = new Uint8Array(buf); - for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; - return buf; - } - - function export2file(data, mime, name, extension) { - if (extension === ".xlsx") { - var wb = new Workbook(), - ws = createSheet(data); - - wb.SheetNames.push(name); - wb.Sheets[name] = ws; - - var wopts = {bookType: 'xlsx', bookSST: false, type: 'binary'}, - wbout = XLSX.write(wb, wopts); - - data = string2ArrayBuffer(wbout); - } - saveAs(new Blob([data], - {type: mime + ";" + $.fn.tableExport.charset}), - name + extension); - } - -}(window)); \ No newline at end of file diff --git a/src/v3/tableexport-3.2.min.js b/src/v3/tableexport-3.2.min.js deleted file mode 100755 index 756aa8a..0000000 --- a/src/v3/tableexport-3.2.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! - * TableExport.js v3.2.0 (http://www.clarketravis.com) - * Copyright 2015 Travis Clarke - * Licensed under the MIT license - */ -!function(t,e){function n(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.fn.tableExport.entityMap[t]})}function o(t,e){e&&(t+=1462);var n=Date.parse(t);return(n-new Date(Date.UTC(1899,11,30)))/864e5}function a(t,e){for(var n={},a={s:{c:1e7,r:1e7},e:{c:0,r:0}},r=0;r!=t.length;++r)for(var i=0;i!=t[r].length;++i){a.s.r>r&&(a.s.r=r),a.s.c>i&&(a.s.c=i),a.e.r'+t+"")}function f(n,a,r){var i="";t(i)}var p=l(this),u=p.find("tbody").find("tr"),u=r.headings?u.add(p.find("thead>tr")):u,u=r.footers?u.add(p.find("tfoor>tr")):u,b=r.headings?p.find("thead>tr").length:0,d="id"===r.fileName?p.attr("id")?p.attr("id"):l.fn.tableExport.defaultFileName:r.fileName,c={xlsx:function(t,e){var o=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return[n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get()]}}).get(),a=n(JSON.stringify({data:o,fileName:e,mimeType:l.fn.tableExport.xlsx.mimeType,fileExtension:l.fn.tableExport.xlsx.fileExtension})),r=l.fn.tableExport.xlsx.buttonContent,i=l.fn.tableExport.xlsx.defaultClass;f(a,r,i)},xls:function(t,e){var o=l.fn.tableExport.xls.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.xls.mimeType,fileExtension:l.fn.tableExport.xls.fileExtension})),i=l.fn.tableExport.xls.buttonContent,p=l.fn.tableExport.xls.defaultClass;f(r,i,p)},csv:function(t,e){var o=l.fn.tableExport.csv.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.csv.mimeType,fileExtension:l.fn.tableExport.csv.fileExtension})),i=l.fn.tableExport.csv.buttonContent,p=l.fn.tableExport.csv.defaultClass;f(r,i,p)},txt:function(t,e){var o=l.fn.tableExport.txt.separator,a=u.map(function(t,e){if(!~s.indexOf(t-b)){var n=l(e).find("th, td");return n.map(function(t,e){return~x.indexOf(t)?void 0:l(e).text()}).get().join(o)}}).get().join(t),r=n(JSON.stringify({data:a,fileName:e,mimeType:l.fn.tableExport.txt.mimeType,fileExtension:l.fn.tableExport.txt.fileExtension})),i=l.fn.tableExport.txt.buttonContent,p=l.fn.tableExport.txt.defaultClass;f(r,i,p)}};r.formats.forEach(function(t){c[t](i,d)})}),l("button[data-fileblob]").on("click",function(){var t=l(this).data("fileblob"),e=t.data,n=t.fileName,o=t.mimeType,a=t.fileExtension;f(e,o,n,a)})},l.fn.tableExport.defaults={headings:!0,footers:!0,formats:["xls","csv","txt"],fileName:"id",bootstrap:!0,position:"bottom",ignoreRows:null,ignoreCols:null},l.fn.tableExport.charset="charset=utf-8",l.fn.tableExport.xlsx={defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},l.fn.tableExport.xls={defaultClass:"xls",buttonContent:"Export to xls",separator:" ",mimeType:"application/vnd.ms-excel",fileExtension:".xls"},l.fn.tableExport.csv={defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"application/csv",fileExtension:".csv"},l.fn.tableExport.txt={defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt"},l.fn.tableExport.defaultFileName="myDownload",l.fn.tableExport.defaultButton="button-default",l.fn.tableExport.bootstrap=["btn","btn-default","btn-toolbar"],l.fn.tableExport.rowDel="\r\n",l.fn.tableExport.entityMap={"&":"&","<":"<",">":">","'":"'","/":"/"}}(window); \ No newline at end of file