diff --git a/dist/js/tableexport.js b/dist/js/tableexport.js index 9e375ac..83ffaaf 100644 --- a/dist/js/tableexport.js +++ b/dist/js/tableexport.js @@ -22,12 +22,20 @@ if (typeof define === 'function' && define.amd) { // AMD define(function (require) { - var $; try { $ = require('jquery') } catch (e) {} + var $; + try { + $ = require('jquery') + } catch (e) { + } return factory($, require('blobjs'), require('file-saverjs'), require('xlsx')); }); } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') { // CommonJS - var $; try { $ = require('jquery') } catch (e) {} + var $; + try { + $ = require('jquery') + } catch (e) { + } module.exports = factory($, require('blobjs'), require('file-saverjs'), require('xlsx')); } else { // Browser globals @@ -44,7 +52,7 @@ var TableExport = function (selectors, options) { var self = this; - if (!selectors) return new Error('"selectors" is required'); + if (!selectors) return _handleError('"selectors" is required. \nUsage: TableExport(selectors, options)'); if (!self) return new TableExport(selectors, options); /** @@ -108,14 +116,19 @@ context.rcMap = new RowColMap().build(context, settings); - var formatMap = {}; - for (var type in _FORMAT) { - formatMap[_FORMAT[type]] = 0; - } + var formatMap = _FORMAT_LIST + .reduce(function (acc, cur) { + acc[cur] = 0; + return acc; + }, {}); settings.formats.forEach( function (key) { - if (!formatMap[key]) { + if (!_isValidFormat(key)) { + return _handleError('"' + key + '" is not a valid format. \nFormats: ' + _FORMAT_LIST.join(', ')) + } else if (!_hasDependencies(key)) { + return _handleError('"' + key + '" requires "js-xlsx".'); + } else if (!formatMap[key]) { context.setExportData(self.exporters.build.call(self, context, key)); formatMap[key]++; } @@ -158,6 +171,8 @@ CONSTANTS: { FORMAT: { XLSX: 'xlsx', + XLSM: 'xlsm', + XLSB: 'xlsb', BIFF2: 'biff2', XLS: 'xls', CSV: 'csv', @@ -212,21 +227,33 @@ * @memberof TableExport.prototype */ entityMap: {'&': '&', '<': '<', '>': '>', "'": ''', '/': '/'}, - /** - * XLSX (Open XML spreadsheet) file extension configuration - * @memberof TableExport.prototype - */ /** * Format configuration * @memberof TableExport.prototype */ formatConfig: { + /** + * XLSX (Open XML spreadsheet) file extension configuration + * @memberof TableExport.prototype + */ xlsx: { defaultClass: 'xlsx', buttonContent: 'Export to xlsx', mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', fileExtension: '.xlsx' }, + xlsm: { + defaultClass: 'xlsm', + buttonContent: 'Export to xlsm', + mimeType: 'application/vnd.ms-excel.sheet.macroEnabled.main+xml', + fileExtension: '.xlsm' + }, + xlsb: { + defaultClass: 'xlsb', + buttonContent: 'Export to xlsb', + mimeType: 'application/vnd.ms-excel.sheet.binary.macroEnabled.main', + fileExtension: '.xlsb' + }, /** * XLS (Binary spreadsheet) file extension configuration * @memberof TableExport.prototype @@ -307,12 +334,10 @@ } } switch (key) { - case _FORMAT.XLSX: - case _FORMAT.XLS: - case _FORMAT.TXT: - return settings.formatValue(val.textContent); case _FORMAT.CSV: return '"' + settings.formatValue(val.textContent.replace(/"/g, '""')) + '"'; + default: + return settings.formatValue(val.textContent); } }; @@ -530,9 +555,9 @@ }, downloadDataURI: function (dataURI, name, extension) { var encodedUri = encodeURI(dataURI); - var link = document.createElement("a"); - link.setAttribute("href", encodedUri); - link.setAttribute("download", name + extension); + var link = document.createElement('a'); + link.setAttribute('href', encodedUri); + link.setAttribute('download', name + extension); document.body.appendChild(link); link.click(); }, @@ -618,7 +643,7 @@ if (this.exists(key) && !overwrite) { return; } - if (typeof value !== 'string') return this.error('"value" must be a string'); + if (typeof value !== 'string') return _handleError('"value" must be a string.'); this.store.setItem(key, value); return _key; }; @@ -634,9 +659,6 @@ var key = this.getKey(_key); return this.store.removeItem(key); }; - this.error = function (message) { - return new Error('error:', message); - }; }; LocalStorage.getInstance = function () { if (!this._instance) { @@ -825,6 +847,12 @@ return TableExport.prototype.CONSTANTS.FORMAT; })(); + var _FORMAT_LIST = (function () { + return Object.keys(_FORMAT).map(function (key) { + return _FORMAT[key]; + }); + })(); + var _TYPE = (function () { return TableExport.prototype.CONSTANTS.TYPE; })(); @@ -914,6 +942,30 @@ return val && [].concat.apply([], val); } + function _isValidFormat(key) { + return ~_FORMAT_LIST.indexOf(key); + } + + function _hasDependencies(key) { + var hasDependencies; + + switch (key) { + case _FORMAT.TXT: + case _FORMAT.CSV: + case _FORMAT.XLS: + hasDependencies = true; + break; + default: + hasDependencies = _isEnhanced(key); + } + return hasDependencies + } + + function _handleError(msg) { + console.error(msg); + return new Error(msg) + } + function _getBootstrapSettings(bootstrap, bootstrapConfig, defaultButton) { var config = {}; if (bootstrap) { diff --git a/dist/js/tableexport.min.js b/dist/js/tableexport.min.js index 61f0c50..9f46ef2 100644 --- a/dist/js/tableexport.min.js +++ b/dist/js/tableexport.min.js @@ -16,4 +16,4 @@ * limitations under the License. * */ -!function(t,e){if("function"==typeof define&&define.amd)define(function(t){var r;try{r=t("jquery")}catch(o){}return e(r,t("blobjs"),t("file-saverjs"),t("xlsx"))});else if("object"==typeof exports&&"string"!=typeof exports.nodeName){var r;try{r=require("jquery")}catch(o){}module.exports=e(r,require("blobjs"),require("file-saverjs"),require("xlsx"))}else 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=o.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=o.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=o.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===o.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:o.filename?o.filename:r.defaultFilename,e.uuid=y(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=o.bootstrapSettings.bootstrapSpacing+o.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=f.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);a[e.uuid]=a[e.uuid]||{},a[e.uuid][o]=JSON.parse(r)}}(),e.rcMap=(new d).build(e,o);var n={};for(var s in g)n[g[s]]=0;o.formats.forEach(function(t){n[t]||(e.setExportData(r.exporters.build.call(r,e,t)),n[t]++)})});var s=document.querySelectorAll("button[tableexport-id]");return w(s,"click",r.downloadHandler,r),r};p.prototype={version:"5.0.0-rc.3",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},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:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{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",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{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:{build:function(t,e){var r=this,o=r.settings,n=p.prototype.formatConfig[e],a=n.separator,s=t.rcMap,c=function(t){if(m(e))return{v:o.formatValue(t.textContent),t:r.getType(t.className)};switch(e){case g.XLSX:case g.XLS:case g.TXT:return o.formatValue(t.textContent);case g.CSV:return'"'+o.formatValue(t.textContent.replace(/"/g,'""'))+'"'}},u=i(t.rows).map(function(t,r){if(s.isIgnore(r))return s.handleRowColMapProp(s.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return i(o).map(function(t,o){var n=c(t);return s.isIgnore(r,o)?s.handleRowColMapProp(s.TYPE.IGNORE):s.isEmpty(r,o)?s.handleRowColMapProp(s.TYPE.EMPTY):s.handleRowColMapProp(s.TYPE.DEFAULT,r,o,e,n,a)}).processCols(e,a)}).processRows(e,r.rowDel),l=JSON.stringify({data:u,filename:t.filename,mimeType:n.mimeType,fileExtension:n.fileExtension}),d=v({uuid:t.uuid,type:e});return o.exportButtons&&t.checkCaption(p.prototype.createObjButton(d,l,n.buttonContent,n.defaultClass,o.bootstrapSettings)),f.getInstance().setItem(d,l,!0)}},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 p.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=p.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?b.STRING:~t.indexOf(e.number.defaultClass)?b.NUMBER:~t.indexOf(e["boolean"].defaultClass)?b.BOOLEAN:~t.indexOf(e.date.defaultClass)?b.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),o=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(o)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=p.prototype.typeConfig,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=e?a+u:a:c++,c!==i);p++);return m(r)?new Array(a).concat(o):new Array(a).concat(o).join(n)}return o},this.handleRowColMapProp=function(t,e,r,o,n,i){switch(t){case d.prototype.TYPE.IGNORE:return;case d.prototype.TYPE.EMPTY:return" ";case d.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,o,n,i)}}};d.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t,e){var r=this,o=r.OFFSET,n=r.rowLength=t.rows.length,s=function(t){r.setRowColMapProp(t,void 0,r.TYPE.IGNORE,!0)},c=function(t,e){r.setRowColMapProp(t,e,r.TYPE.IGNORE,!0)},u=function(t,e){r.setRowColMapProp(t,e,r.TYPE.EMPTY,!0)},l=function(t,e,o){for(var i=t.getAttribute("rowspan"),a=t.hasAttribute("colspan"),s=0;s=n)return;a&&p(t,s+e,o),s>=1&&(r.setRowColMapProp(s+e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(s+e,o,void 0,1))}},p=function(t,e,n){var i=t.getAttribute("colspan");i<=1||(r.setRowColMapProp(e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(e,n+o,void 0,i-o))};return i(t.rows).map(function(r,o){(~e.ignoreRows.indexOf(o-t.thAdj)||a(r,e.ignoreCSS))&&s(o);var n=r.querySelectorAll("th, td");return i(n).map(function(t,r){(~e.ignoreCols.indexOf(r)||a(t,e.ignoreCSS))&&c(o,r),a(t,e.emptyCSS)&&u(o,r),t.hasAttribute("rowspan")?l(t,o,r):t.hasAttribute("colspan")&&p(t,o,r)})}),r}};var h=function(t){return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substring(0,4))}(navigator.userAgent||navigator.vendor||window.opera),m=function(){return function(t){return o&&!h&&!p.prototype.formatConfig[t].enforceStrictRFC4180}}(),g=function(){return p.prototype.CONSTANTS.FORMAT}(),b=function(){return p.prototype.CONSTANTS.TYPE}();Array.prototype.processRows=function(t,e){return m(t)?this.map(u).filter(c):this.filter(c).join(e)},Array.prototype.processCols=function(t,e){return m(t)?this.filter(c):this.filter(c).join(e)};var y=function(){var t=0;return function(e){return e.id||(e.id="tableexport-"+ ++t),e.id}}(),v=function(){var t,e,r=0;return function(o){var n=o.type;if(o=JSON.stringify(o),0===o.length)return r;for(t=0;t tr")),e.rows=n.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=n.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=n.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===n.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:n.filename?n.filename:r.defaultFilename,e.uuid=C(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=n.bootstrapSettings.bootstrapSpacing+n.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=h.getInstance().getItem(t),n=t.substring(t.indexOf("-")+1);a[e.uuid]=a[e.uuid]||{},a[e.uuid][n]=JSON.parse(r)}}(),e.rcMap=(new g).build(e,n);var o=x.reduce(function(t,e){return t[e]=0,t},{});n.formats.forEach(function(t){return c(t)?p(t)?void(o[t]||(e.setExportData(r.exporters.build.call(r,e,t)),o[t]++)):f('"'+t+'" requires "js-xlsx".'):f('"'+t+'" is not a valid format. \nFormats: '+x.join(", "))})});var s=document.querySelectorAll("button[tableexport-id]");return E(s,"click",r.downloadHandler,r),r};m.prototype={version:"5.0.0-rc.3",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",XLSM:"xlsm",XLSB:"xlsb",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},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:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xlsm:{defaultClass:"xlsm",buttonContent:"Export to xlsm",mimeType:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",fileExtension:".xlsm"},xlsb:{defaultClass:"xlsb",buttonContent:"Export to xlsb",mimeType:"application/vnd.ms-excel.sheet.binary.macroEnabled.main",fileExtension:".xlsb"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{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:{build:function(t,e){var r=this,n=r.settings,o=m.prototype.formatConfig[e],a=o.separator,s=t.rcMap,l=function(t){if(y(e))return{v:n.formatValue(t.textContent),t:r.getType(t.className)};switch(e){case v.CSV:return'"'+n.formatValue(t.textContent.replace(/"/g,'""'))+'"';default:return n.formatValue(t.textContent)}},u=i(t.rows).map(function(t,r){if(s.isIgnore(r))return s.handleRowColMapProp(s.TYPE.IGNORE);var n=t.querySelectorAll("th, td");return i(n).map(function(t,n){var o=l(t);return s.isIgnore(r,n)?s.handleRowColMapProp(s.TYPE.IGNORE):s.isEmpty(r,n)?s.handleRowColMapProp(s.TYPE.EMPTY):s.handleRowColMapProp(s.TYPE.DEFAULT,r,n,e,o,a)}).processCols(e,a)}).processRows(e,r.rowDel),c=JSON.stringify({data:u,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),p=S({uuid:t.uuid,type:e});return n.exportButtons&&t.checkCaption(m.prototype.createObjButton(p,c,o.buttonContent,o.defaultClass,n.bootstrapSettings)),h.getInstance().setItem(p,c,!0)}},createObjButton:function(t,e,r,n,o){var i=document.createElement("button");return i.setAttribute("tableexport-id",t),i.className=o.bootstrapClass+o.bootstrapTheme+n,i.textContent=r,i},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return m.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=m.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?w.STRING:~t.indexOf(e.number.defaultClass)?w.NUMBER:~t.indexOf(e["boolean"].defaultClass)?w.BOOLEAN:~t.indexOf(e.date.defaultClass)?w.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),n=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(n)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=m.prototype.typeConfig,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=e?a+u:a:l++,l!==i);p++);return y(r)?new Array(a).concat(n):new Array(a).concat(n).join(o)}return n},this.handleRowColMapProp=function(t,e,r,n,o,i){switch(t){case g.prototype.TYPE.IGNORE:return;case g.prototype.TYPE.EMPTY:return" ";case g.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,n,o,i)}}};g.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t,e){var r=this,n=r.OFFSET,o=r.rowLength=t.rows.length,s=function(t){r.setRowColMapProp(t,void 0,r.TYPE.IGNORE,!0)},l=function(t,e){r.setRowColMapProp(t,e,r.TYPE.IGNORE,!0)},u=function(t,e){r.setRowColMapProp(t,e,r.TYPE.EMPTY,!0)},c=function(t,e,n){for(var i=t.getAttribute("rowspan"),a=t.hasAttribute("colspan"),s=0;s=o)return;a&&p(t,s+e,n),s>=1&&(r.setRowColMapProp(s+e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(s+e,n,void 0,1))}},p=function(t,e,o){var i=t.getAttribute("colspan");i<=1||(r.setRowColMapProp(e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(e,o+n,void 0,i-n))};return i(t.rows).map(function(r,n){(~e.ignoreRows.indexOf(n-t.thAdj)||a(r,e.ignoreCSS))&&s(n);var o=r.querySelectorAll("th, td");return i(o).map(function(t,r){(~e.ignoreCols.indexOf(r)||a(t,e.ignoreCSS))&&l(n,r),a(t,e.emptyCSS)&&u(n,r),t.hasAttribute("rowspan")?c(t,n,r):t.hasAttribute("colspan")&&p(t,n,r)})}),r}};var b=function(t){return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substring(0,4))}(navigator.userAgent||navigator.vendor||window.opera),y=function(){return function(t){return n&&!b&&!m.prototype.formatConfig[t].enforceStrictRFC4180}}(),v=function(){return m.prototype.CONSTANTS.FORMAT}(),x=function(){return Object.keys(v).map(function(t){return v[t]})}(),w=function(){return m.prototype.CONSTANTS.TYPE}();Array.prototype.processRows=function(t,e){return y(t)?this.map(u).filter(l):this.filter(l).join(e)},Array.prototype.processCols=function(t,e){return y(t)?this.filter(l):this.filter(l).join(e)};var C=function(){var t=0;return function(e){return e.id||(e.id="tableexport-"+ ++t),e.id}}(),S=function(){var t,e,r=0;return function(n){var o=n.type;if(n=JSON.stringify(n),0===n.length)return r;for(t=0;t': '>', "'": ''', '/': '/'}, - /** - * XLSX (Open XML spreadsheet) file extension configuration - * @memberof TableExport.prototype - */ /** * Format configuration * @memberof TableExport.prototype */ formatConfig: { + /** + * XLSX (Open XML spreadsheet) file extension configuration + * @memberof TableExport.prototype + */ xlsx: { defaultClass: 'xlsx', buttonContent: 'Export to xlsx', mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', fileExtension: '.xlsx' }, + xlsm: { + defaultClass: 'xlsm', + buttonContent: 'Export to xlsm', + mimeType: 'application/vnd.ms-excel.sheet.macroEnabled.main+xml', + fileExtension: '.xlsm' + }, + xlsb: { + defaultClass: 'xlsb', + buttonContent: 'Export to xlsb', + mimeType: 'application/vnd.ms-excel.sheet.binary.macroEnabled.main', + fileExtension: '.xlsb' + }, /** * XLS (Binary spreadsheet) file extension configuration * @memberof TableExport.prototype @@ -307,12 +334,10 @@ } } switch (key) { - case _FORMAT.XLSX: - case _FORMAT.XLS: - case _FORMAT.TXT: - return settings.formatValue(val.textContent); case _FORMAT.CSV: return '"' + settings.formatValue(val.textContent.replace(/"/g, '""')) + '"'; + default: + return settings.formatValue(val.textContent); } }; @@ -530,9 +555,9 @@ }, downloadDataURI: function (dataURI, name, extension) { var encodedUri = encodeURI(dataURI); - var link = document.createElement("a"); - link.setAttribute("href", encodedUri); - link.setAttribute("download", name + extension); + var link = document.createElement('a'); + link.setAttribute('href', encodedUri); + link.setAttribute('download', name + extension); document.body.appendChild(link); link.click(); }, @@ -618,7 +643,7 @@ if (this.exists(key) && !overwrite) { return; } - if (typeof value !== 'string') return this.error('"value" must be a string'); + if (typeof value !== 'string') return _handleError('"value" must be a string.'); this.store.setItem(key, value); return _key; }; @@ -634,9 +659,6 @@ var key = this.getKey(_key); return this.store.removeItem(key); }; - this.error = function (message) { - return new Error('error:', message); - }; }; LocalStorage.getInstance = function () { if (!this._instance) { @@ -825,6 +847,12 @@ return TableExport.prototype.CONSTANTS.FORMAT; })(); + var _FORMAT_LIST = (function () { + return Object.keys(_FORMAT).map(function (key) { + return _FORMAT[key]; + }); + })(); + var _TYPE = (function () { return TableExport.prototype.CONSTANTS.TYPE; })(); @@ -914,6 +942,30 @@ return val && [].concat.apply([], val); } + function _isValidFormat(key) { + return ~_FORMAT_LIST.indexOf(key); + } + + function _hasDependencies(key) { + var hasDependencies; + + switch (key) { + case _FORMAT.TXT: + case _FORMAT.CSV: + case _FORMAT.XLS: + hasDependencies = true; + break; + default: + hasDependencies = _isEnhanced(key); + } + return hasDependencies + } + + function _handleError(msg) { + console.error(msg); + return new Error(msg) + } + function _getBootstrapSettings(bootstrap, bootstrapConfig, defaultButton) { var config = {}; if (bootstrap) { diff --git a/src/stable/js/tableexport.min.js b/src/stable/js/tableexport.min.js index 61f0c50..9f46ef2 100644 --- a/src/stable/js/tableexport.min.js +++ b/src/stable/js/tableexport.min.js @@ -16,4 +16,4 @@ * limitations under the License. * */ -!function(t,e){if("function"==typeof define&&define.amd)define(function(t){var r;try{r=t("jquery")}catch(o){}return e(r,t("blobjs"),t("file-saverjs"),t("xlsx"))});else if("object"==typeof exports&&"string"!=typeof exports.nodeName){var r;try{r=require("jquery")}catch(o){}module.exports=e(r,require("blobjs"),require("file-saverjs"),require("xlsx"))}else 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=o.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=o.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=o.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===o.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:o.filename?o.filename:r.defaultFilename,e.uuid=y(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=o.bootstrapSettings.bootstrapSpacing+o.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=f.getInstance().getItem(t),o=t.substring(t.indexOf("-")+1);a[e.uuid]=a[e.uuid]||{},a[e.uuid][o]=JSON.parse(r)}}(),e.rcMap=(new d).build(e,o);var n={};for(var s in g)n[g[s]]=0;o.formats.forEach(function(t){n[t]||(e.setExportData(r.exporters.build.call(r,e,t)),n[t]++)})});var s=document.querySelectorAll("button[tableexport-id]");return w(s,"click",r.downloadHandler,r),r};p.prototype={version:"5.0.0-rc.3",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},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:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{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",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{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:{build:function(t,e){var r=this,o=r.settings,n=p.prototype.formatConfig[e],a=n.separator,s=t.rcMap,c=function(t){if(m(e))return{v:o.formatValue(t.textContent),t:r.getType(t.className)};switch(e){case g.XLSX:case g.XLS:case g.TXT:return o.formatValue(t.textContent);case g.CSV:return'"'+o.formatValue(t.textContent.replace(/"/g,'""'))+'"'}},u=i(t.rows).map(function(t,r){if(s.isIgnore(r))return s.handleRowColMapProp(s.TYPE.IGNORE);var o=t.querySelectorAll("th, td");return i(o).map(function(t,o){var n=c(t);return s.isIgnore(r,o)?s.handleRowColMapProp(s.TYPE.IGNORE):s.isEmpty(r,o)?s.handleRowColMapProp(s.TYPE.EMPTY):s.handleRowColMapProp(s.TYPE.DEFAULT,r,o,e,n,a)}).processCols(e,a)}).processRows(e,r.rowDel),l=JSON.stringify({data:u,filename:t.filename,mimeType:n.mimeType,fileExtension:n.fileExtension}),d=v({uuid:t.uuid,type:e});return o.exportButtons&&t.checkCaption(p.prototype.createObjButton(d,l,n.buttonContent,n.defaultClass,o.bootstrapSettings)),f.getInstance().setItem(d,l,!0)}},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 p.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=p.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?b.STRING:~t.indexOf(e.number.defaultClass)?b.NUMBER:~t.indexOf(e["boolean"].defaultClass)?b.BOOLEAN:~t.indexOf(e.date.defaultClass)?b.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),o=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(o)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},n=p.prototype.typeConfig,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=e?a+u:a:c++,c!==i);p++);return m(r)?new Array(a).concat(o):new Array(a).concat(o).join(n)}return o},this.handleRowColMapProp=function(t,e,r,o,n,i){switch(t){case d.prototype.TYPE.IGNORE:return;case d.prototype.TYPE.EMPTY:return" ";case d.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,o,n,i)}}};d.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t,e){var r=this,o=r.OFFSET,n=r.rowLength=t.rows.length,s=function(t){r.setRowColMapProp(t,void 0,r.TYPE.IGNORE,!0)},c=function(t,e){r.setRowColMapProp(t,e,r.TYPE.IGNORE,!0)},u=function(t,e){r.setRowColMapProp(t,e,r.TYPE.EMPTY,!0)},l=function(t,e,o){for(var i=t.getAttribute("rowspan"),a=t.hasAttribute("colspan"),s=0;s=n)return;a&&p(t,s+e,o),s>=1&&(r.setRowColMapProp(s+e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(s+e,o,void 0,1))}},p=function(t,e,n){var i=t.getAttribute("colspan");i<=1||(r.setRowColMapProp(e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(e,n+o,void 0,i-o))};return i(t.rows).map(function(r,o){(~e.ignoreRows.indexOf(o-t.thAdj)||a(r,e.ignoreCSS))&&s(o);var n=r.querySelectorAll("th, td");return i(n).map(function(t,r){(~e.ignoreCols.indexOf(r)||a(t,e.ignoreCSS))&&c(o,r),a(t,e.emptyCSS)&&u(o,r),t.hasAttribute("rowspan")?l(t,o,r):t.hasAttribute("colspan")&&p(t,o,r)})}),r}};var h=function(t){return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substring(0,4))}(navigator.userAgent||navigator.vendor||window.opera),m=function(){return function(t){return o&&!h&&!p.prototype.formatConfig[t].enforceStrictRFC4180}}(),g=function(){return p.prototype.CONSTANTS.FORMAT}(),b=function(){return p.prototype.CONSTANTS.TYPE}();Array.prototype.processRows=function(t,e){return m(t)?this.map(u).filter(c):this.filter(c).join(e)},Array.prototype.processCols=function(t,e){return m(t)?this.filter(c):this.filter(c).join(e)};var y=function(){var t=0;return function(e){return e.id||(e.id="tableexport-"+ ++t),e.id}}(),v=function(){var t,e,r=0;return function(o){var n=o.type;if(o=JSON.stringify(o),0===o.length)return r;for(t=0;t tr")),e.rows=n.headers?i(t.querySelectorAll("thead > tr")).concat(e.rows):e.rows,e.rows=n.footers?e.rows.concat(i(t.querySelectorAll("tfoot > tr"))):e.rows,e.thAdj=n.headers?t.querySelectorAll("thead > tr").length:0,e.filename="id"===n.filename?t.getAttribute("id")?t.getAttribute("id"):r.defaultFilename:n.filename?n.filename:r.defaultFilename,e.uuid=C(t),e.checkCaption=function(e){var r=t.querySelectorAll("caption.tableexport-caption");r.length?r[0].appendChild(e):(r=document.createElement("caption"),r.className=n.bootstrapSettings.bootstrapSpacing+n.position+" tableexport-caption",r.appendChild(e),t.insertBefore(r,t.firstChild))},e.setExportData=function(){return function(t){var r=h.getInstance().getItem(t),n=t.substring(t.indexOf("-")+1);a[e.uuid]=a[e.uuid]||{},a[e.uuid][n]=JSON.parse(r)}}(),e.rcMap=(new g).build(e,n);var o=x.reduce(function(t,e){return t[e]=0,t},{});n.formats.forEach(function(t){return c(t)?p(t)?void(o[t]||(e.setExportData(r.exporters.build.call(r,e,t)),o[t]++)):f('"'+t+'" requires "js-xlsx".'):f('"'+t+'" is not a valid format. \nFormats: '+x.join(", "))})});var s=document.querySelectorAll("button[tableexport-id]");return E(s,"click",r.downloadHandler,r),r};m.prototype={version:"5.0.0-rc.3",defaults:{headers:!0,footers:!0,formats:["xlsx","csv","txt"],filename:"id",bootstrap:!1,exportButtons:!0,position:"bottom",ignoreRows:null,ignoreCols:null,trimWhitespace:!0},CONSTANTS:{FORMAT:{XLSX:"xlsx",XLSM:"xlsm",XLSB:"xlsb",BIFF2:"biff2",XLS:"xls",CSV:"csv",TXT:"txt"},TYPE:{STRING:"s",NUMBER:"n",BOOLEAN:"b",DATE:"d"}},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:{"&":"&","<":"<",">":">","'":"'","/":"/"},formatConfig:{xlsx:{defaultClass:"xlsx",buttonContent:"Export to xlsx",mimeType:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",fileExtension:".xlsx"},xlsm:{defaultClass:"xlsm",buttonContent:"Export to xlsm",mimeType:"application/vnd.ms-excel.sheet.macroEnabled.main+xml",fileExtension:".xlsm"},xlsb:{defaultClass:"xlsb",buttonContent:"Export to xlsb",mimeType:"application/vnd.ms-excel.sheet.binary.macroEnabled.main",fileExtension:".xlsb"},xls:{defaultClass:"xls",buttonContent:"Export to xls",separator:"\t",mimeType:"application/vnd.ms-excel",fileExtension:".xls",enforceStrictRFC4180:!1},csv:{defaultClass:"csv",buttonContent:"Export to csv",separator:",",mimeType:"text/csv",fileExtension:".csv",enforceStrictRFC4180:!0},txt:{defaultClass:"txt",buttonContent:"Export to txt",separator:" ",mimeType:"text/plain",fileExtension:".txt",enforceStrictRFC4180:!0}},typeConfig:{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:{build:function(t,e){var r=this,n=r.settings,o=m.prototype.formatConfig[e],a=o.separator,s=t.rcMap,l=function(t){if(y(e))return{v:n.formatValue(t.textContent),t:r.getType(t.className)};switch(e){case v.CSV:return'"'+n.formatValue(t.textContent.replace(/"/g,'""'))+'"';default:return n.formatValue(t.textContent)}},u=i(t.rows).map(function(t,r){if(s.isIgnore(r))return s.handleRowColMapProp(s.TYPE.IGNORE);var n=t.querySelectorAll("th, td");return i(n).map(function(t,n){var o=l(t);return s.isIgnore(r,n)?s.handleRowColMapProp(s.TYPE.IGNORE):s.isEmpty(r,n)?s.handleRowColMapProp(s.TYPE.EMPTY):s.handleRowColMapProp(s.TYPE.DEFAULT,r,n,e,o,a)}).processCols(e,a)}).processRows(e,r.rowDel),c=JSON.stringify({data:u,filename:t.filename,mimeType:o.mimeType,fileExtension:o.fileExtension}),p=S({uuid:t.uuid,type:e});return n.exportButtons&&t.checkCaption(m.prototype.createObjButton(p,c,o.buttonContent,o.defaultClass,n.bootstrapSettings)),h.getInstance().setItem(p,c,!0)}},createObjButton:function(t,e,r,n,o){var i=document.createElement("button");return i.setAttribute("tableexport-id",t),i.className=o.bootstrapClass+o.bootstrapTheme+n,i.textContent=r,i},escapeHtml:function(t){return String(t).replace(/[&<>'\/]/g,function(t){return m.prototype.entityMap[t]})},unescapeHtml:function(t){var e=String(t);for(var r in this.entityMap)e=e.replace(RegExp(this.entityMap[r],"g"),r);return e},formatValue:function(t,e){return t?e.trim():e},getType:function(t){if(!t)return"";var e=m.prototype.typeConfig;return~t.indexOf(e.string.defaultClass)?w.STRING:~t.indexOf(e.number.defaultClass)?w.NUMBER:~t.indexOf(e["boolean"].defaultClass)?w.BOOLEAN:~t.indexOf(e.date.defaultClass)?w.DATE:""},dateNum:function(t,e){e&&(t+=1462);var r=Date.parse(t),n=(r-new Date(Date.UTC(1899,11,30)))/864e5;return Math.floor(n)},createSheet:function(t){for(var e={},r={s:{c:1e7,r:1e7},e:{c:0,r:0}},o=m.prototype.typeConfig,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=e?a+u:a:l++,l!==i);p++);return y(r)?new Array(a).concat(n):new Array(a).concat(n).join(o)}return n},this.handleRowColMapProp=function(t,e,r,n,o,i){switch(t){case g.prototype.TYPE.IGNORE:return;case g.prototype.TYPE.EMPTY:return" ";case g.prototype.TYPE.DEFAULT:default:return this.convertSpanToArray(e,r,n,o,i)}}};g.prototype={OFFSET:1,TYPE:{IGNORE:"ignore",EMPTY:"empty",SPAN:"span",DEFAULT:"default"},build:function(t,e){var r=this,n=r.OFFSET,o=r.rowLength=t.rows.length,s=function(t){r.setRowColMapProp(t,void 0,r.TYPE.IGNORE,!0)},l=function(t,e){r.setRowColMapProp(t,e,r.TYPE.IGNORE,!0)},u=function(t,e){r.setRowColMapProp(t,e,r.TYPE.EMPTY,!0)},c=function(t,e,n){for(var i=t.getAttribute("rowspan"),a=t.hasAttribute("colspan"),s=0;s=o)return;a&&p(t,s+e,n),s>=1&&(r.setRowColMapProp(s+e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(s+e,n,void 0,1))}},p=function(t,e,o){var i=t.getAttribute("colspan");i<=1||(r.setRowColMapProp(e,void 0,r.TYPE.SPAN,!0),r.setRowColMapProp(e,o+n,void 0,i-n))};return i(t.rows).map(function(r,n){(~e.ignoreRows.indexOf(n-t.thAdj)||a(r,e.ignoreCSS))&&s(n);var o=r.querySelectorAll("th, td");return i(o).map(function(t,r){(~e.ignoreCols.indexOf(r)||a(t,e.ignoreCSS))&&l(n,r),a(t,e.emptyCSS)&&u(n,r),t.hasAttribute("rowspan")?c(t,n,r):t.hasAttribute("colspan")&&p(t,n,r)})}),r}};var b=function(t){return/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(t)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(t.substring(0,4))}(navigator.userAgent||navigator.vendor||window.opera),y=function(){return function(t){return n&&!b&&!m.prototype.formatConfig[t].enforceStrictRFC4180}}(),v=function(){return m.prototype.CONSTANTS.FORMAT}(),x=function(){return Object.keys(v).map(function(t){return v[t]})}(),w=function(){return m.prototype.CONSTANTS.TYPE}();Array.prototype.processRows=function(t,e){return y(t)?this.map(u).filter(l):this.filter(l).join(e)},Array.prototype.processCols=function(t,e){return y(t)?this.filter(l):this.filter(l).join(e)};var C=function(){var t=0;return function(e){return e.id||(e.id="tableexport-"+ ++t),e.id}}(),S=function(){var t,e,r=0;return function(n){var o=n.type;if(n=JSON.stringify(n),0===n.length)return r;for(t=0;t