diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index 6a9bccd..177da35 100755 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.0.0 (http://www.clarketravis.com) + * TableExport.js v3.1.0 (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 d290282..e0c8a09 100755 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.0.0 (http://www.clarketravis.com) + * TableExport.js v3.1.0 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ diff --git a/gulpfile.js b/gulpfile.js index 1dbfd72..be36b7b 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,10 +4,7 @@ var gulp = require('gulp'), js = require('gulp-uglify'); gulp.task('js', ['clean'], function () { - return gulp.src('./src/v3/tableexport-3.1.js') - .pipe(rename({ - basename: "tableexport" - })) + return gulp.src('./src/stable/js/tableexport.js') .pipe(gulp.dest('./dist/js/')) .pipe(js({output: {comments: /^!|@preserve|@license|@cc_on/i}})) .pipe(rename({ diff --git a/src/stable/js/tableexport.js b/src/stable/js/tableexport.js index 707e68d..177da35 100755 --- a/src/stable/js/tableexport.js +++ b/src/stable/js/tableexport.js @@ -1,5 +1,5 @@ /*! - * TableExport.js v3.0.0 (http://www.clarketravis.com) + * TableExport.js v3.1.0 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ @@ -40,13 +40,14 @@ data: dataURL, name: name }), + myFile = name + ".xlsx", myContent = $.fn.tableExport.xlsx.buttonContent, myClass = $.fn.tableExport.xlsx.defaultClass; - createObjButton(dataObject, myContent, myClass); + createObjButton(dataObject, myFile, myContent, myClass); }, xls: function (rdel, name) { var colD = $.fn.tableExport.xls.separator, - dataURL = 'data:application/vnd.ms-excel;charset=utf-8,' + + 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) { @@ -61,7 +62,7 @@ csv: function (rdel, name) { rdel = '"' + rdel + '"'; var colD = '"' + $.fn.tableExport.csv.separator + '"', - dataURL = 'data:text/csv;charset=utf-8,' + + 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) { @@ -75,7 +76,7 @@ }, txt: function (rdel, name) { var colD = $.fn.tableExport.txt.separator, - dataURL = 'data:text/plain;charset=utf-8,' + + 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) { @@ -105,8 +106,8 @@ checkCaption(exportButton); } - function createObjButton(dataObject, myContent, myClass) { - var exportButton = "" + myContent + ""; + function createObjButton(dataObject, myFile, myContent, myClass) { + var exportButton = "" + myContent + ""; checkCaption(exportButton); addListener(myClass) } diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 2057193..a3cda0f 100755 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -1,6 +1,6 @@ /*! - * TableExport.js v3.0.0 (http://www.clarketravis.com) + * TableExport.js v3.1.0 (http://www.clarketravis.com) * Copyright 2015 Travis Clarke * Licensed under the MIT license */ -(function(window,undefined){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);}});}});};$.fn.tableExport.defaults={headings:true,formats:["xls","csv","txt"],fileName:"id",bootstrap:true,position:"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+"")}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.r