diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index 7e05545..4e481a0 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -18,7 +18,7 @@ } }(this, function ($, Blob, saveAs, XLSX) { 'use strict'; - // TODO: update typings (def file) + // TODO: update TS `definition` file /** * TableExport main library constructor * @param selectors {jQuery} jQuery selector(s) @@ -90,12 +90,26 @@ }; })(); + var formatMap = {}; + for (var type in _type) { + formatMap[type] = 0; + } settings.formats.forEach( function (key) { - XLSX && !isMobile && key === 'xls' ? key = 'xlsm' : false; - !XLSX || isMobile && key === 'xlsx' ? key = null : false; - key && context.setExportData(self.exporters[key].call(self, context)); + var before = key; + (XLSX && !isMobile) && key === _type.xls + ? key = _type.xlsm + : false; + + (!XLSX || isMobile) && key === _type.xlsx + ? key = _type.xls + : false; + + if (!formatMap[key]) { + context.setExportData(self.exporters[key].call(self, context)); + formatMap[key]++; + } } ); }); @@ -288,12 +302,12 @@ t: self.getType(val.className) }; }).filter(function (val) { - return val; + return typeof val !== 'undefined'; }); }).map(function (val) { return val && [].concat.apply([], val); }).filter(function (val) { - return val; + return typeof val !== 'undefined'; }), dataObject = TableExport.prototype.escapeHtml( JSON.stringify({ @@ -304,7 +318,7 @@ })), myContent = TableExport.prototype.xlsx.buttonContent, myClass = TableExport.prototype.xlsx.defaultClass, - hashKey = _hashCode({uuid: context.uuid, type: 'xlsx'}), + hashKey = _hashCode({uuid: context.uuid, type: _type.xlsx}), exportButton = settings.exportButtons && TableExport.prototype.createObjButton( hashKey, dataObject, @@ -363,12 +377,12 @@ t: self.getType(val.className) }; }).filter(function (val) { - return val; + return typeof val !== 'undefined'; }); }).map(function (val) { return val && [].concat.apply([], val); }).filter(function (val) { - return val; + return typeof val !== 'undefined'; }), dataObject = TableExport.prototype.escapeHtml( JSON.stringify({ @@ -379,7 +393,7 @@ })), myContent = TableExport.prototype.xls.buttonContent, myClass = TableExport.prototype.xls.defaultClass, - hashKey = _hashCode({uuid: context.uuid, type: 'xls'}), + hashKey = _hashCode({uuid: context.uuid, type: _type.xls}), exportButton = settings.exportButtons && TableExport.prototype.createObjButton( hashKey, dataObject, @@ -407,9 +421,12 @@ if (_hasClass(val, settings.emptyCSS)) { return ' ' } - return val.textContent; + }).filter(function (val) { + return typeof val !== 'undefined'; }).join(colD); + }).filter(function (val) { + return typeof val !== 'undefined'; }).join(self.rowDel), dataObject = TableExport.prototype.escapeHtml( JSON.stringify({ @@ -420,7 +437,7 @@ })), myContent = TableExport.prototype.xls.buttonContent, myClass = TableExport.prototype.xls.defaultClass, - hashKey = _hashCode({uuid: context.uuid, type: 'xls'}), + hashKey = _hashCode({uuid: context.uuid, type: _type.xls}), exportButton = settings.exportButtons && TableExport.prototype.createObjButton( hashKey, dataObject, @@ -450,7 +467,11 @@ return ' ' } return '"' + settings.formatValue(val.textContent.replace(/"/g, '""')) + '"'; + }).filter(function (val) { + return typeof val !== 'undefined'; }).join(colD); + }).filter(function (val) { + return typeof val !== 'undefined'; }).join(self.rowDel), dataObject = TableExport.prototype.escapeHtml( JSON.stringify({ @@ -461,7 +482,7 @@ })), myContent = TableExport.prototype.csv.buttonContent, myClass = TableExport.prototype.csv.defaultClass, - hashKey = _hashCode({uuid: context.uuid, type: 'csv'}), + hashKey = _hashCode({uuid: context.uuid, type: _type.csv}), exportButton = settings.exportButtons && TableExport.prototype.createObjButton( hashKey, dataObject, @@ -473,7 +494,6 @@ _store.getInstance().setItem(hashKey, dataObject, true); return hashKey; }, - // TODO: bug with `txt` ignoreRows and ignoreCols txt: function (context) { var self = this; var settings = self.settings; @@ -491,7 +511,11 @@ return ' ' } return settings.formatValue(val.textContent); + }).filter(function (val) { + return typeof val !== 'undefined'; }).join(colD); + }).filter(function (val) { + return typeof val !== 'undefined'; }).join(self.rowDel), dataObject = TableExport.prototype.escapeHtml( JSON.stringify({ @@ -502,7 +526,7 @@ })), myContent = TableExport.prototype.txt.buttonContent, myClass = TableExport.prototype.txt.defaultClass, - hashKey = _hashCode({uuid: context.uuid, type: 'txt'}), + hashKey = _hashCode({uuid: context.uuid, type: _type.txt}), exportButton = settings.exportButtons && TableExport.prototype.createObjButton( hashKey, dataObject, @@ -787,6 +811,17 @@ }; })(); + var _type = (function () { + return { + xlsx: 'xlsx', + xlsm: 'xlsm', + xls: 'xls', + csv: 'csv', + txt: 'txt' + }; + })(); + + var _hashCode = (function () { var hash = 0, i, char; @@ -827,8 +862,14 @@ } function _nodesArray(els) { - if (!(els instanceof NodeList) && (!$ || !(els instanceof $))) return [].concat(els); - return [].slice.call(els) + var result; + try { + result = [].slice.call(els); + if (!result.length) throw Error(); + } catch (e) { + result = [].concat(els); + } + return result; } function _hasClass(el, cls) { @@ -866,7 +907,6 @@ // alias the TableExport prototype for (var prop in TableExport.prototype) { - // TODO: check compat $.fn.tableExport[prop] = TableExport.prototype[prop]; } } diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index 7ade925..e99cad4 100644 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -3,4 +3,4 @@ * Copyright 2017 Travis Clarke * Licensed under the MIT license */ -!function(t,e){"function"==typeof define&&define.amd?define(["jquery","blobjs","file-saverjs","xlsx"],e):"object"==typeof exports&&"string"!=typeof exports.nodeName?module.exports=e(require("jquery"),require("blobjs"),require("file-saverjs"),require("xlsx")):t.TableExport=e(t.jQuery,t.Blob,t.saveAs,t.XLSX)}(this,function(t,e,r,o){"use strict";function n(){for(var t=arguments,e=1;e tr")),e.rows=a.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=a.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=a.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===a.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:a.filename?a.filename:r.defaultFilename,e.uuid=u(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=a.bootstrapSettings.bootstrapSpacing+a.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=p.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);c[e.uuid]=c[e.uuid]||{},c[e.uuid][o]=JSON.parse(r)}}(),a.formats.forEach(function(t){!(!o||m||"xls"!==t)&&(t="xlsm"),!(o&&(!m||"xlsx"!==t))&&(t=null),t&&e.setExportData(r.exporters[t].call(r,e))})});var d=document.querySelectorAll("button[tableexport-id]");return f(d,"click",r.downloadHandler,r),r};l.prototype={version:"4.0.0",defaults:{headers:!0,footers:!0,formats:["xls","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["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"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,r=e.settings,o={},n=i(t.rows).map(function(n,s){if(!~r.ignoreRows.indexOf(s-t.thAdj)&&!a(n,r.ignoreCSS)){var l=n.querySelectorAll("th, td");return i(l).map(function(t,n){if(!~r.ignoreCols.indexOf(n)&&!a(t,r.ignoreCSS)){if(a(t,r.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(o[s]=o[s]||{},o[s][n+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=n?p+o[s][i]:p:u++,u!==l);i++);return new Array(p).concat({v:r.formatValue(t.textContent),t:e.getType(t.className)})}return{v:r.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return t}),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.xlsx.mimeType,fileExtension:l.prototype.xlsx.fileExtension})),u=l.prototype.xlsx.buttonContent,f=l.prototype.xlsx.defaultClass,m=c({uuid:t.uuid,type:"xlsx"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},xlsm:function(t){var e=this,r=e.settings,o={},n=i(t.rows).map(function(n,s){if(!~r.ignoreRows.indexOf(s-t.thAdj)&&!a(n,r.ignoreCSS)){var l=n.querySelectorAll("th, td");return i(l).map(function(t,n){if(!~r.ignoreCols.indexOf(n)&&!a(t,r.ignoreCSS)){if(a(t,r.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(o[s]=o[s]||{},o[s][n+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=n?p+o[s][i]:p:u++,u!==l);i++);return new Array(p).concat({v:r.formatValue(t.textContent),t:e.getType(t.className)})}return{v:r.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return t}),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),u=l.prototype.xls.buttonContent,f=l.prototype.xls.defaultClass,m=c({uuid:t.uuid,type:"xls"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},xls:function(t){var e=this,r=e.settings,o=l.prototype.xls.separator,n=i(t.rows).map(function(e,n){if(!~r.ignoreRows.indexOf(n-t.thAdj)&&!a(e,r.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~r.ignoreCols.indexOf(e)&&!a(t,r.ignoreCSS))return a(t,r.emptyCSS)?" ":t.textContent}).join(o)}}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),u=l.prototype.xls.buttonContent,f=l.prototype.xls.defaultClass,m=c({uuid:t.uuid,type:"xls"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},csv:function(t){var e=this,r=e.settings,o=l.prototype.csv.separator,n=i(t.rows).map(function(e,n){if(!~r.ignoreRows.indexOf(n-t.thAdj)&&!a(e,r.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~r.ignoreCols.indexOf(e)&&!a(t,r.ignoreCSS))return a(t,r.emptyCSS)?" ":'"'+r.formatValue(t.textContent.replace(/"/g,'""'))+'"'}).join(o)}}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.csv.mimeType,fileExtension:l.prototype.csv.fileExtension})),u=l.prototype.csv.buttonContent,f=l.prototype.csv.defaultClass,m=c({uuid:t.uuid,type:"csv"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},txt:function(t){var e=this,r=e.settings,o=l.prototype.txt.separator,n=i(t.rows).map(function(e,n){if(!~r.ignoreRows.indexOf(n-t.thAdj)&&!a(e,r.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~r.ignoreCols.indexOf(e)&&!a(t,r.ignoreCSS))return a(t,r.emptyCSS)?" ":r.formatValue(t.textContent)}).join(o)}}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.txt.mimeType,fileExtension:l.prototype.txt.fileExtension})),u=l.prototype.txt.buttonContent,f=l.prototype.txt.defaultClass,m=c({uuid:t.uuid,type:"txt"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m}},createObjButton:function(t,e,r,o,n){var i=document.createElement("button");return i.setAttribute("tableexport-id",t),i.className=n.bootstrapClass+n.bootstrapTheme+o,i.textContent=r,i},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.prototype.entityMap[t]})},translateMimeType:function(t){return String(t).replace(///,"/").replace(this.xls.mimeType,this.csv.mimeType)},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=l.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t);return(r-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=l.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){r.s.r>i&&(r.s.r=i),r.s.c>a&&(r.s.c=a),r.e.r tr")),e.rows=a.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=a.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=a.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===a.filename?t.getAttribute("id")?t.getAttribute("id"):n.defaultFilename:a.filename?a.filename:n.defaultFilename,e.uuid=p(t),e.checkCaption=function(e){var n=t.querySelectorAll("caption.tableexport-caption");n.length?n[0].appendChild(e):(n=document.createElement("caption"),n.className=a.bootstrapSettings.bootstrapSpacing+a.position+" tableexport-caption",n.appendChild(e),t.insertBefore(n,t.firstChild))},e.setExportData=function(){return function(t){var n=u.getInstance().getItem(t),r=t.substring(t.indexOf("-")+1);f[e.uuid]=f[e.uuid]||{},f[e.uuid][r]=JSON.parse(n)}}();var o={};for(var s in c)o[s]=0;a.formats.forEach(function(t){!(!r||d||t!==c.xls)&&(t=c.xlsm),!(r&&!d||t!==c.xlsx)&&(t=c.xls),o[t]||(e.setExportData(n.exporters[t].call(n,e)),o[t]++)})});var x=document.querySelectorAll("button[tableexport-id]");return m(x,"click",n.downloadHandler,n),n};l.prototype={version:"4.0.0",defaults:{headers:!0,footers:!0,formats:["xls","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["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"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,n=e.settings,r={},o=i(t.rows).map(function(o,s){if(!~n.ignoreRows.indexOf(s-t.thAdj)&&!a(o,n.ignoreCSS)){var l=o.querySelectorAll("th, td");return i(l).map(function(t,o){if(!~n.ignoreCols.indexOf(o)&&!a(t,n.ignoreCSS)){if(a(t,n.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(r[s]=r[s]||{},r[s][o+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=o?u+r[s][i]:u:p++,p!==l);i++);return new Array(u).concat({v:n.formatValue(t.textContent),t:e.getType(t.className)})}return{v:n.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return"undefined"!=typeof t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return"undefined"!=typeof t}),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.xlsx.mimeType,fileExtension:l.prototype.xlsx.fileExtension})),p=l.prototype.xlsx.buttonContent,m=l.prototype.xlsx.defaultClass,d=f({uuid:t.uuid,type:c.xlsx}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},xlsm:function(t){var e=this,n=e.settings,r={},o=i(t.rows).map(function(o,s){if(!~n.ignoreRows.indexOf(s-t.thAdj)&&!a(o,n.ignoreCSS)){var l=o.querySelectorAll("th, td");return i(l).map(function(t,o){if(!~n.ignoreCols.indexOf(o)&&!a(t,n.ignoreCSS)){if(a(t,n.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(r[s]=r[s]||{},r[s][o+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=o?u+r[s][i]:u:p++,p!==l);i++);return new Array(u).concat({v:n.formatValue(t.textContent),t:e.getType(t.className)})}return{v:n.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return"undefined"!=typeof t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return"undefined"!=typeof t}),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),p=l.prototype.xls.buttonContent,m=l.prototype.xls.defaultClass,d=f({uuid:t.uuid,type:c.xls}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},xls:function(t){var e=this,n=e.settings,r=l.prototype.xls.separator,o=i(t.rows).map(function(e,o){if(!~n.ignoreRows.indexOf(o-t.thAdj)&&!a(e,n.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~n.ignoreCols.indexOf(e)&&!a(t,n.ignoreCSS))return a(t,n.emptyCSS)?" ":t.textContent}).filter(function(t){return"undefined"!=typeof t}).join(r)}}).filter(function(t){return"undefined"!=typeof t}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),p=l.prototype.xls.buttonContent,m=l.prototype.xls.defaultClass,d=f({uuid:t.uuid,type:c.xls}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},csv:function(t){var e=this,n=e.settings,r=l.prototype.csv.separator,o=i(t.rows).map(function(e,o){if(!~n.ignoreRows.indexOf(o-t.thAdj)&&!a(e,n.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~n.ignoreCols.indexOf(e)&&!a(t,n.ignoreCSS))return a(t,n.emptyCSS)?" ":'"'+n.formatValue(t.textContent.replace(/"/g,'""'))+'"'}).filter(function(t){return"undefined"!=typeof t}).join(r)}}).filter(function(t){return"undefined"!=typeof t}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.csv.mimeType,fileExtension:l.prototype.csv.fileExtension})),p=l.prototype.csv.buttonContent,m=l.prototype.csv.defaultClass,d=f({uuid:t.uuid,type:c.csv}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},txt:function(t){var e=this,n=e.settings,r=l.prototype.txt.separator,o=i(t.rows).map(function(e,o){if(!~n.ignoreRows.indexOf(o-t.thAdj)&&!a(e,n.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~n.ignoreCols.indexOf(e)&&!a(t,n.ignoreCSS))return a(t,n.emptyCSS)?" ":n.formatValue(t.textContent)}).filter(function(t){return"undefined"!=typeof t}).join(r)}}).filter(function(t){return"undefined"!=typeof t}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.txt.mimeType,fileExtension:l.prototype.txt.fileExtension})),p=l.prototype.txt.buttonContent,m=l.prototype.txt.defaultClass,d=f({uuid:t.uuid,type:c.txt}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d}},createObjButton:function(t,e,n,r,o){var i=document.createElement("button");return i.setAttribute("tableexport-id",t),i.className=o.bootstrapClass+o.bootstrapTheme+r,i.textContent=n,i},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.prototype.entityMap[t]})},translateMimeType:function(t){return String(t).replace(///,"/").replace(this.xls.mimeType,this.csv.mimeType)},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=l.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},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=l.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){n.s.r>i&&(n.s.r=i),n.s.c>a&&(n.s.c=a),n.e.r tr")),e.rows=a.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=a.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=a.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===a.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:a.filename?a.filename:r.defaultFilename,e.uuid=u(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=a.bootstrapSettings.bootstrapSpacing+a.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=p.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);c[e.uuid]=c[e.uuid]||{},c[e.uuid][o]=JSON.parse(r)}}(),a.formats.forEach(function(t){!(!o||m||"xls"!==t)&&(t="xlsm"),!(o&&(!m||"xlsx"!==t))&&(t=null),t&&e.setExportData(r.exporters[t].call(r,e))})});var d=document.querySelectorAll("button[tableexport-id]");return f(d,"click",r.downloadHandler,r),r};l.prototype={version:"4.0.0",defaults:{headers:!0,footers:!0,formats:["xls","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["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"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,r=e.settings,o={},n=i(t.rows).map(function(n,s){if(!~r.ignoreRows.indexOf(s-t.thAdj)&&!a(n,r.ignoreCSS)){var l=n.querySelectorAll("th, td");return i(l).map(function(t,n){if(!~r.ignoreCols.indexOf(n)&&!a(t,r.ignoreCSS)){if(a(t,r.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(o[s]=o[s]||{},o[s][n+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=n?p+o[s][i]:p:u++,u!==l);i++);return new Array(p).concat({v:r.formatValue(t.textContent),t:e.getType(t.className)})}return{v:r.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return t}),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.xlsx.mimeType,fileExtension:l.prototype.xlsx.fileExtension})),u=l.prototype.xlsx.buttonContent,f=l.prototype.xlsx.defaultClass,m=c({uuid:t.uuid,type:"xlsx"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},xlsm:function(t){var e=this,r=e.settings,o={},n=i(t.rows).map(function(n,s){if(!~r.ignoreRows.indexOf(s-t.thAdj)&&!a(n,r.ignoreCSS)){var l=n.querySelectorAll("th, td");return i(l).map(function(t,n){if(!~r.ignoreCols.indexOf(n)&&!a(t,r.ignoreCSS)){if(a(t,r.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(o[s]=o[s]||{},o[s][n+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=n?p+o[s][i]:p:u++,u!==l);i++);return new Array(p).concat({v:r.formatValue(t.textContent),t:e.getType(t.className)})}return{v:r.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return t}),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),u=l.prototype.xls.buttonContent,f=l.prototype.xls.defaultClass,m=c({uuid:t.uuid,type:"xls"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},xls:function(t){var e=this,r=e.settings,o=l.prototype.xls.separator,n=i(t.rows).map(function(e,n){if(!~r.ignoreRows.indexOf(n-t.thAdj)&&!a(e,r.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~r.ignoreCols.indexOf(e)&&!a(t,r.ignoreCSS))return a(t,r.emptyCSS)?" ":t.textContent}).join(o)}}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),u=l.prototype.xls.buttonContent,f=l.prototype.xls.defaultClass,m=c({uuid:t.uuid,type:"xls"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},csv:function(t){var e=this,r=e.settings,o=l.prototype.csv.separator,n=i(t.rows).map(function(e,n){if(!~r.ignoreRows.indexOf(n-t.thAdj)&&!a(e,r.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~r.ignoreCols.indexOf(e)&&!a(t,r.ignoreCSS))return a(t,r.emptyCSS)?" ":'"'+r.formatValue(t.textContent.replace(/"/g,'""'))+'"'}).join(o)}}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.csv.mimeType,fileExtension:l.prototype.csv.fileExtension})),u=l.prototype.csv.buttonContent,f=l.prototype.csv.defaultClass,m=c({uuid:t.uuid,type:"csv"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m},txt:function(t){var e=this,r=e.settings,o=l.prototype.txt.separator,n=i(t.rows).map(function(e,n){if(!~r.ignoreRows.indexOf(n-t.thAdj)&&!a(e,r.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~r.ignoreCols.indexOf(e)&&!a(t,r.ignoreCSS))return a(t,r.emptyCSS)?" ":r.formatValue(t.textContent)}).join(o)}}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:n,filename:t.filename,mimeType:l.prototype.txt.mimeType,fileExtension:l.prototype.txt.fileExtension})),u=l.prototype.txt.buttonContent,f=l.prototype.txt.defaultClass,m=c({uuid:t.uuid,type:"txt"}),d=r.exportButtons&&l.prototype.createObjButton(m,s,u,f,r.bootstrapSettings);return d&&t.checkCaption(d),p.getInstance().setItem(m,s,!0),m}},createObjButton:function(t,e,r,o,n){var i=document.createElement("button");return i.setAttribute("tableexport-id",t),i.className=n.bootstrapClass+n.bootstrapTheme+o,i.textContent=r,i},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.prototype.entityMap[t]})},translateMimeType:function(t){return String(t).replace(///,"/").replace(this.xls.mimeType,this.csv.mimeType)},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=l.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t);return(r-new Date(Date.UTC(1899,11,30)))/864e5},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=l.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){r.s.r>i&&(r.s.r=i),r.s.c>a&&(r.s.c=a),r.e.r tr")),e.rows=a.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=a.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=a.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===a.filename?t.getAttribute("id")?t.getAttribute("id"):n.defaultFilename:a.filename?a.filename:n.defaultFilename,e.uuid=p(t),e.checkCaption=function(e){var n=t.querySelectorAll("caption.tableexport-caption");n.length?n[0].appendChild(e):(n=document.createElement("caption"),n.className=a.bootstrapSettings.bootstrapSpacing+a.position+" tableexport-caption",n.appendChild(e),t.insertBefore(n,t.firstChild))},e.setExportData=function(){return function(t){var n=u.getInstance().getItem(t),r=t.substring(t.indexOf("-")+1);f[e.uuid]=f[e.uuid]||{},f[e.uuid][r]=JSON.parse(n)}}();var o={};for(var s in c)o[s]=0;a.formats.forEach(function(t){!(!r||d||t!==c.xls)&&(t=c.xlsm),!(r&&!d||t!==c.xlsx)&&(t=c.xls),o[t]||(e.setExportData(n.exporters[t].call(n,e)),o[t]++)})});var x=document.querySelectorAll("button[tableexport-id]");return m(x,"click",n.downloadHandler,n),n};l.prototype={version:"4.0.0",defaults:{headers:!0,footers:!0,formats:["xls","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},charset:"charset=utf-8",defaultFilename:"myDownload",defaultButton:"button-default",ignoreCSS:"tableexport-ignore",emptyCSS:"tableexport-empty",bootstrapConfig:["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"},types:{string:{defaultClass:"tableexport-string"},number:{defaultClass:"tableexport-number",assert:function(t){return!isNaN(t)}},"boolean":{defaultClass:"tableexport-boolean",assert:function(t){return"true"===t.toLowerCase()||"false"===t.toLowerCase()}},date:{defaultClass:"tableexport-date",assert:function(t){return!/.*%/.test(t)&&!isNaN(Date.parse(t))}}},exporters:{xlsx:function(t){var e=this,n=e.settings,r={},o=i(t.rows).map(function(o,s){if(!~n.ignoreRows.indexOf(s-t.thAdj)&&!a(o,n.ignoreCSS)){var l=o.querySelectorAll("th, td");return i(l).map(function(t,o){if(!~n.ignoreCols.indexOf(o)&&!a(t,n.ignoreCSS)){if(a(t,n.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(r[s]=r[s]||{},r[s][o+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=o?u+r[s][i]:u:p++,p!==l);i++);return new Array(u).concat({v:n.formatValue(t.textContent),t:e.getType(t.className)})}return{v:n.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return"undefined"!=typeof t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return"undefined"!=typeof t}),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.xlsx.mimeType,fileExtension:l.prototype.xlsx.fileExtension})),p=l.prototype.xlsx.buttonContent,m=l.prototype.xlsx.defaultClass,d=f({uuid:t.uuid,type:c.xlsx}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},xlsm:function(t){var e=this,n=e.settings,r={},o=i(t.rows).map(function(o,s){if(!~n.ignoreRows.indexOf(s-t.thAdj)&&!a(o,n.ignoreCSS)){var l=o.querySelectorAll("th, td");return i(l).map(function(t,o){if(!~n.ignoreCols.indexOf(o)&&!a(t,n.ignoreCSS)){if(a(t,n.emptyCSS))return" ";if(t.hasAttribute("colspan")&&(r[s]=r[s]||{},r[s][o+1]=t.getAttribute("colspan")-1),t.hasAttribute("rowspan"))for(var i=1;i=o?u+r[s][i]:u:p++,p!==l);i++);return new Array(u).concat({v:n.formatValue(t.textContent),t:e.getType(t.className)})}return{v:n.formatValue(t.textContent),t:e.getType(t.className)}}}).filter(function(t){return"undefined"!=typeof t})}}).map(function(t){return t&&[].concat.apply([],t)}).filter(function(t){return"undefined"!=typeof t}),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),p=l.prototype.xls.buttonContent,m=l.prototype.xls.defaultClass,d=f({uuid:t.uuid,type:c.xls}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},xls:function(t){var e=this,n=e.settings,r=l.prototype.xls.separator,o=i(t.rows).map(function(e,o){if(!~n.ignoreRows.indexOf(o-t.thAdj)&&!a(e,n.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~n.ignoreCols.indexOf(e)&&!a(t,n.ignoreCSS))return a(t,n.emptyCSS)?" ":t.textContent}).filter(function(t){return"undefined"!=typeof t}).join(r)}}).filter(function(t){return"undefined"!=typeof t}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.xls.mimeType,fileExtension:l.prototype.xls.fileExtension})),p=l.prototype.xls.buttonContent,m=l.prototype.xls.defaultClass,d=f({uuid:t.uuid,type:c.xls}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},csv:function(t){var e=this,n=e.settings,r=l.prototype.csv.separator,o=i(t.rows).map(function(e,o){if(!~n.ignoreRows.indexOf(o-t.thAdj)&&!a(e,n.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~n.ignoreCols.indexOf(e)&&!a(t,n.ignoreCSS))return a(t,n.emptyCSS)?" ":'"'+n.formatValue(t.textContent.replace(/"/g,'""'))+'"'}).filter(function(t){return"undefined"!=typeof t}).join(r)}}).filter(function(t){return"undefined"!=typeof t}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.csv.mimeType,fileExtension:l.prototype.csv.fileExtension})),p=l.prototype.csv.buttonContent,m=l.prototype.csv.defaultClass,d=f({uuid:t.uuid,type:c.csv}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d},txt:function(t){var e=this,n=e.settings,r=l.prototype.txt.separator,o=i(t.rows).map(function(e,o){if(!~n.ignoreRows.indexOf(o-t.thAdj)&&!a(e,n.ignoreCSS)){var s=e.querySelectorAll("th, td");return i(s).map(function(t,e){if(!~n.ignoreCols.indexOf(e)&&!a(t,n.ignoreCSS))return a(t,n.emptyCSS)?" ":n.formatValue(t.textContent)}).filter(function(t){return"undefined"!=typeof t}).join(r)}}).filter(function(t){return"undefined"!=typeof t}).join(e.rowDel),s=l.prototype.escapeHtml(JSON.stringify({data:o,filename:t.filename,mimeType:l.prototype.txt.mimeType,fileExtension:l.prototype.txt.fileExtension})),p=l.prototype.txt.buttonContent,m=l.prototype.txt.defaultClass,d=f({uuid:t.uuid,type:c.txt}),x=n.exportButtons&&l.prototype.createObjButton(d,s,p,m,n.bootstrapSettings);return x&&t.checkCaption(x),u.getInstance().setItem(d,s,!0),d}},createObjButton:function(t,e,n,r,o){var i=document.createElement("button");return i.setAttribute("tableexport-id",t),i.className=o.bootstrapClass+o.bootstrapTheme+r,i.textContent=n,i},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return l.prototype.entityMap[t]})},translateMimeType:function(t){return String(t).replace(///,"/").replace(this.xls.mimeType,this.csv.mimeType)},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=l.prototype.types;return~t.indexOf(e.string.defaultClass)?"s":~t.indexOf(e.number.defaultClass)?"n":~t.indexOf(e["boolean"].defaultClass)?"b":~t.indexOf(e.date.defaultClass)?"d":""},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=l.prototype.types,i=0;i!==t.length;++i)for(var a=0;a!==t[i].length;++a){n.s.r>i&&(n.s.r=i),n.s.c>a&&(n.s.c=a),n.e.r