diff --git a/tableExport.js b/tableExport.js index a55cd0d..5f491a0 100644 --- a/tableExport.js +++ b/tableExport.js @@ -1,9 +1,9 @@ /** * @preserve tableExport.jquery.plugin * - * Version 1.10.14 + * Version 1.10.15 * - * Copyright (c) 2015-2019 hhurz, https://github.com/hhurz/tableExport.jquery.plugin + * Copyright (c) 2015-2020 hhurz, https://github.com/hhurz/tableExport.jquery.plugin * * Based on https://github.com/kayalshri/tableExport.jquery.plugin * @@ -148,14 +148,14 @@ 'credit-card': [153, 243] }; var FONT_ROW_RATIO = 1.15; - var el = this; - var DownloadEvt = null; - var $hrows = []; - var $rows = []; - var rowIndex = 0; - var trData = ''; - var colNames = []; - var ranges = []; + var el = this; + var DownloadEvt = null; + var $hrows = []; + var $rows = []; + var rowIndex = 0; + var trData = ''; + var colNames = []; + var ranges = []; var blob; var $hiddenTableElements = []; var checkCellVisibilty = false; @@ -186,7 +186,7 @@ defaults.mso.pageOrientation = (defaults.mso.pageOrientation.substr(0, 1) === 'l') ? 'landscape' : 'portrait'; defaults.date.html = defaults.date.html || ''; - if ( defaults.date.html.length ) { + if (defaults.date.html.length) { var patt = []; patt['dd'] = '(3[01]|[12][0-9]|0?[1-9])'; patt['mm'] = '(1[012]|0?[1-9])'; @@ -205,49 +205,48 @@ // e.g. '^\\s*(3[01]|[12][0-9]|0?[1-9])(.)(1[012]|0?[1-9])\\2((?:1[6-9]|2[0-2])\\d{2})\\s*$' defaults.date.pattern = new RegExp(defaults.date.regex, 'g'); - var f = formatItems.indexOf("dd")+1; + var f = formatItems.indexOf('dd') + 1; defaults.date.match_d = f + (f > 1 ? 1 : 0); - f = formatItems.indexOf("mm")+1; + f = formatItems.indexOf('mm') + 1; defaults.date.match_m = f + (f > 1 ? 1 : 0); - f = (formatItems.indexOf("yyyy") >= 0 ? formatItems.indexOf("yyyy") : formatItems.indexOf("yy"))+1; + f = (formatItems.indexOf('yyyy') >= 0 ? formatItems.indexOf('yyyy') : formatItems.indexOf('yy')) + 1; defaults.date.match_y = f + (f > 1 ? 1 : 0); } colNames = GetColumnNames(el); - if ( defaults.type === 'csv' || defaults.type === 'tsv' || defaults.type === 'txt' ) { + if (defaults.type === 'csv' || defaults.type === 'tsv' || defaults.type === 'txt') { - var csvData = ""; + var csvData = ''; var rowlength = 0; - ranges = []; - rowIndex = 0; + ranges = []; + rowIndex = 0; var csvString = function (cell, rowIndex, colIndex) { var result = ''; - if ( cell !== null ) { + if (cell !== null) { var dataString = parseString(cell, rowIndex, colIndex); var csvValue = (dataString === null || dataString === '') ? '' : dataString.toString(); - if ( defaults.type === 'tsv' ) { - if ( dataString instanceof Date ) + if (defaults.type === 'tsv') { + if (dataString instanceof Date) dataString.toLocaleString(); // According to http://www.iana.org/assignments/media-types/text/tab-separated-values // are fields that contain tabs not allowable in tsv encoding result = replaceAll(csvValue, '\t', ' '); - } - else { + } else { // Takes a string and encapsulates it (by default in double-quotes) if it // contains the csv field separator, spaces, or linebreaks. - if ( dataString instanceof Date ) + if (dataString instanceof Date) result = defaults.csvEnclosure + dataString.toLocaleString() + defaults.csvEnclosure; else { result = preventInjection(csvValue); result = replaceAll(result, defaults.csvEnclosure, defaults.csvEnclosure + defaults.csvEnclosure); - if ( result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result) ) + if (result.indexOf(defaults.csvSeparator) >= 0 || /[\r\n ]/g.test(result)) result = defaults.csvEnclosure + result + defaults.csvEnclosure; } } @@ -259,16 +258,16 @@ var CollectCsvData = function ($rows, rowselector, length) { $rows.each(function () { - trData = ""; + trData = ''; ForEachVisibleCell(this, rowselector, rowIndex, length + $rows.length, - function (cell, row, col) { - trData += csvString(cell, row, col) + (defaults.type === 'tsv' ? '\t' : defaults.csvSeparator); - }); + function (cell, row, col) { + trData += csvString(cell, row, col) + (defaults.type === 'tsv' ? '\t' : defaults.csvSeparator); + }); trData = $.trim(trData).substring(0, trData.length - 1); - if ( trData.length > 0 ) { + if (trData.length > 0) { - if ( csvData.length > 0 ) - csvData += "\n"; + if (csvData.length > 0) + csvData += '\n'; csvData += trData; } @@ -279,152 +278,152 @@ }; rowlength += CollectCsvData($(el).find('thead').first().find(defaults.theadSelector), 'th,td', rowlength); - findTableElements($(el),'tbody').each(function () { + findTableElements($(el), 'tbody').each(function () { rowlength += CollectCsvData(findTableElements($(this), defaults.tbodySelector), 'td,th', rowlength); }); - if ( defaults.tfootSelector.length ) + if (defaults.tfootSelector.length) CollectCsvData($(el).find('tfoot').first().find(defaults.tfootSelector), 'td,th', rowlength); - csvData += "\n"; + csvData += '\n'; //output - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return csvData; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(csvData); - if ( defaults.outputMode === 'window' ) { + if (defaults.outputMode === 'window') { downloadFile(false, 'data:text/' + (defaults.type === 'csv' ? 'csv' : 'plain') + ';charset=utf-8,', csvData); return; } - saveToFile ( csvData, - defaults.fileName + '.' + defaults.type, - "text/" + (defaults.type === 'csv' ? 'csv' : 'plain'), - "utf-8", - "", - (defaults.type === 'csv' && defaults.csvUseBOM) ); + saveToFile(csvData, + defaults.fileName + '.' + defaults.type, + 'text/' + (defaults.type === 'csv' ? 'csv' : 'plain'), + 'utf-8', + '', + (defaults.type === 'csv' && defaults.csvUseBOM)); - } else if ( defaults.type === 'sql' ) { + } else if (defaults.type === 'sql') { // Header rowIndex = 0; - ranges = []; - var tdData = "INSERT INTO " + defaults.sql.tableEnclosure + defaults.tableName + defaults.sql.tableEnclosure + " ("; - $hrows = collectHeadRows ($(el)); + ranges = []; + var tdData = 'INSERT INTO ' + defaults.sql.tableEnclosure + defaults.tableName + defaults.sql.tableEnclosure + ' ('; + $hrows = collectHeadRows($(el)); $($hrows).each(function () { ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, - function (cell, row, col) { - var colName = parseString(cell, row, col) || ''; - if ( colName.indexOf(defaults.sql.columnEnclosure) > -1 ) - colName = replaceAll(colName.toString(), defaults.sql.columnEnclosure, defaults.sql.columnEnclosure + defaults.sql.columnEnclosure); - tdData += defaults.sql.columnEnclosure + colName + defaults.sql.columnEnclosure + ","; - }); + function (cell, row, col) { + var colName = parseString(cell, row, col) || ''; + if (colName.indexOf(defaults.sql.columnEnclosure) > -1) + colName = replaceAll(colName.toString(), defaults.sql.columnEnclosure, defaults.sql.columnEnclosure + defaults.sql.columnEnclosure); + tdData += defaults.sql.columnEnclosure + colName + defaults.sql.columnEnclosure + ','; + }); rowIndex++; tdData = $.trim(tdData).substring(0, tdData.length - 1); }); - tdData += ") VALUES "; + tdData += ') VALUES '; // Data - $rows = collectRows ($(el)); + $rows = collectRows($(el)); $($rows).each(function () { - trData = ""; + trData = ''; ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, - function (cell, row, col) { - var dataString = parseString(cell, row, col) || ''; - if ( dataString.indexOf("'") > -1 ) - dataString = replaceAll(dataString.toString(), "'", "''"); - trData += "'" + dataString + "',"; - }); - if ( trData.length > 3 ) { - tdData += "(" + trData; + function (cell, row, col) { + var dataString = parseString(cell, row, col) || ''; + if (dataString.indexOf('\'') > -1) + dataString = replaceAll(dataString.toString(), '\'', '\'\''); + trData += '\'' + dataString + '\','; + }); + if (trData.length > 3) { + tdData += '(' + trData; tdData = $.trim(tdData).substring(0, tdData.length - 1); - tdData += "),"; + tdData += '),'; } rowIndex++; }); tdData = $.trim(tdData).substring(0, tdData.length - 1); - tdData += ";"; + tdData += ';'; // Output - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return tdData; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(tdData); - saveToFile ( tdData, defaults.fileName + '.sql', "application/sql", "utf-8", "", false ); + saveToFile(tdData, defaults.fileName + '.sql', 'application/sql', 'utf-8', '', false); - } else if ( defaults.type === 'json' ) { + } else if (defaults.type === 'json') { var jsonHeaderArray = []; ranges = []; - $hrows = collectHeadRows ($(el)); + $hrows = collectHeadRows($(el)); $($hrows).each(function () { var jsonArrayTd = []; ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, - function (cell, row, col) { - jsonArrayTd.push(parseString(cell, row, col)); - }); + function (cell, row, col) { + jsonArrayTd.push(parseString(cell, row, col)); + }); jsonHeaderArray.push(jsonArrayTd); }); // Data var jsonArray = []; - $rows = collectRows ($(el)); + $rows = collectRows($(el)); $($rows).each(function () { var jsonObjectTd = {}; var colIndex = 0; ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, - function (cell, row, col) { - if ( jsonHeaderArray.length ) { - jsonObjectTd[jsonHeaderArray[jsonHeaderArray.length - 1][colIndex]] = parseString(cell, row, col); - } else { - jsonObjectTd[colIndex] = parseString(cell, row, col); - } - colIndex++; - }); - if ( $.isEmptyObject(jsonObjectTd) === false ) + function (cell, row, col) { + if (jsonHeaderArray.length) { + jsonObjectTd[jsonHeaderArray[jsonHeaderArray.length - 1][colIndex]] = parseString(cell, row, col); + } else { + jsonObjectTd[colIndex] = parseString(cell, row, col); + } + colIndex++; + }); + if ($.isEmptyObject(jsonObjectTd) === false) jsonArray.push(jsonObjectTd); rowIndex++; }); - var sdata = ""; + var sdata = ''; - if ( defaults.jsonScope === 'head' ) + if (defaults.jsonScope === 'head') sdata = JSON.stringify(jsonHeaderArray); - else if ( defaults.jsonScope === 'data' ) + else if (defaults.jsonScope === 'data') sdata = JSON.stringify(jsonArray); else // all sdata = JSON.stringify({header: jsonHeaderArray, data: jsonArray}); - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return sdata; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(sdata); - saveToFile ( sdata, defaults.fileName + '.json', "application/json", "utf-8", "base64", false ); + saveToFile(sdata, defaults.fileName + '.json', 'application/json', 'utf-8', 'base64', false); - } else if ( defaults.type === 'xml' ) { + } else if (defaults.type === 'xml') { rowIndex = 0; - ranges = []; - var xml = ''; + ranges = []; + var xml = ''; xml += ''; // Header - $hrows = collectHeadRows ($(el)); + $hrows = collectHeadRows($(el)); $($hrows).each(function () { ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, - function (cell, row, col) { - xml += "" + parseString(cell, row, col) + ""; - }); + function (cell, row, col) { + xml += '' + parseString(cell, row, col) + ''; + }); rowIndex++; }); xml += ''; @@ -432,16 +431,16 @@ // Data var rowCount = 1; - $rows = collectRows ($(el)); + $rows = collectRows($(el)); $($rows).each(function () { var colCount = 1; - trData = ""; + trData = ''; ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, - function (cell, row, col) { - trData += "" + parseString(cell, row, col) + ""; - colCount++; - }); - if ( trData.length > 0 && trData !== "" ) { + function (cell, row, col) { + trData += '' + parseString(cell, row, col) + ''; + colCount++; + }); + if (trData.length > 0 && trData !== '') { xml += '' + trData + ''; rowCount++; } @@ -451,44 +450,43 @@ xml += ''; // Output - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return xml; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(xml); - saveToFile ( xml, defaults.fileName + '.xml', "application/xml", "utf-8", "base64", false ); - } - else if ( defaults.type === 'excel' && defaults.mso.fileFormat === 'xmlss' ) { + saveToFile(xml, defaults.fileName + '.xml', 'application/xml', 'utf-8', 'base64', false); + } else if (defaults.type === 'excel' && defaults.mso.fileFormat === 'xmlss') { var docDatas = []; var docNames = []; $(el).filter(function () { return isVisible($(this)); }).each(function () { - var $table = $(this); + var $table = $(this); var ssName = ''; - if ( typeof defaults.mso.worksheetName === 'string' && defaults.mso.worksheetName.length ) + if (typeof defaults.mso.worksheetName === 'string' && defaults.mso.worksheetName.length) ssName = defaults.mso.worksheetName + ' ' + (docNames.length + 1); - else if ( typeof defaults.mso.worksheetName[docNames.length] !== 'undefined' ) + else if (typeof defaults.mso.worksheetName[docNames.length] !== 'undefined') ssName = defaults.mso.worksheetName[docNames.length]; - if ( ! ssName.length ) + if (!ssName.length) ssName = $table.find('caption').text() || ''; - if ( ! ssName.length ) + if (!ssName.length) ssName = 'Table ' + (docNames.length + 1); - ssName = $.trim(ssName.replace(/[\\\/[\]*:?'"]/g,'').substring(0,31)); + ssName = $.trim(ssName.replace(/[\\\/[\]*:?'"]/g, '').substring(0, 31)); docNames.push($('
').text(ssName).html()); - if ( defaults.exportHiddenCells === false ) { - $hiddenTableElements = $table.find("tr, th, td").filter(":hidden"); + if (defaults.exportHiddenCells === false) { + $hiddenTableElements = $table.find('tr, th, td').filter(':hidden'); checkCellVisibilty = $hiddenTableElements.length > 0; } rowIndex = 0; colNames = GetColumnNames(this); - docData = '\r'; + docData = '
\r'; function CollectXmlssData ($rows, rowselector, length) { var spans = []; @@ -496,76 +494,75 @@ $($rows).each(function () { var ssIndex = 0; var nCols = 0; - trData = ""; + trData = ''; ForEachVisibleCell(this, 'td,th', rowIndex, length + $rows.length, - function (cell, row, col) { - if ( cell !== null ) { - var style = ""; - var data = parseString(cell, row, col); - var type = "String"; - - if ( jQuery.isNumeric(data) !== false ) { - type = "Number"; - } - else { - var number = parsePercent(data); - if ( number !== false ) { - data = number; - type = "Number"; - style += ' ss:StyleID="pct1"'; - } - } - - if ( type !== "Number" ) - data = data.replace(/\n/g, '
'); - - var colspan = getColspan (cell); - var rowspan = getRowspan (cell); - - // Skip spans - $.each(spans, function () { - var range = this; - if ( rowIndex >= range.s.r && rowIndex <= range.e.r && nCols >= range.s.c && nCols <= range.e.c ) { - for ( var i = 0; i <= range.e.c - range.s.c; ++i ) { - nCols++; - ssIndex++; - } - } - }); - - // Handle Row Span - if ( rowspan || colspan ) { - rowspan = rowspan || 1; - colspan = colspan || 1; - spans.push({ - s: {r: rowIndex, c: nCols}, - e: {r: rowIndex + rowspan - 1, c: nCols + colspan - 1} - }); - } - - // Handle Colspan - if ( colspan > 1 ) { - style += ' ss:MergeAcross="' + (colspan-1) + '"'; - nCols += (colspan - 1); - } - - if ( rowspan > 1 ) { - style += ' ss:MergeDown="' + (rowspan-1) + '" ss:StyleID="rsp1"'; - } - - if ( ssIndex > 0 ) { - style += ' ss:Index="' + (nCols+1) + '"'; - ssIndex = 0; - } - - trData += '' + - $('
').text(data).html() + - '\r'; - nCols++; - } - }); - if ( trData.length > 0 ) + function (cell, row, col) { + if (cell !== null) { + var style = ''; + var data = parseString(cell, row, col); + var type = 'String'; + + if (jQuery.isNumeric(data) !== false) { + type = 'Number'; + } else { + var number = parsePercent(data); + if (number !== false) { + data = number; + type = 'Number'; + style += ' ss:StyleID="pct1"'; + } + } + + if (type !== 'Number') + data = data.replace(/\n/g, '
'); + + var colspan = getColspan(cell); + var rowspan = getRowspan(cell); + + // Skip spans + $.each(spans, function () { + var range = this; + if (rowIndex >= range.s.r && rowIndex <= range.e.r && nCols >= range.s.c && nCols <= range.e.c) { + for (var i = 0; i <= range.e.c - range.s.c; ++i) { + nCols++; + ssIndex++; + } + } + }); + + // Handle Row Span + if (rowspan || colspan) { + rowspan = rowspan || 1; + colspan = colspan || 1; + spans.push({ + s: {r: rowIndex, c: nCols}, + e: {r: rowIndex + rowspan - 1, c: nCols + colspan - 1} + }); + } + + // Handle Colspan + if (colspan > 1) { + style += ' ss:MergeAcross="' + (colspan - 1) + '"'; + nCols += (colspan - 1); + } + + if (rowspan > 1) { + style += ' ss:MergeDown="' + (rowspan - 1) + '" ss:StyleID="rsp1"'; + } + + if (ssIndex > 0) { + style += ' ss:Index="' + (nCols + 1) + '"'; + ssIndex = 0; + } + + trData += '' + + $('
').text(data).html() + + '\r'; + nCols++; + } + }); + if (trData.length > 0) docData += '\r' + trData + '\r'; rowIndex++; }); @@ -573,8 +570,8 @@ return $rows.length; } - var rowLength = CollectXmlssData (collectHeadRows ($table), 'th,td', 0); - CollectXmlssData (collectRows ($table), 'td,th', rowLength); + var rowLength = CollectXmlssData(collectHeadRows($table), 'th,td', 0); + CollectXmlssData(collectRows($table), 'td,th', rowLength); docData += '
\r'; docDatas.push(docData); @@ -583,16 +580,15 @@ var count = {}; var firstOccurences = {}; var item, itemCount; - for (var n = 0, c = docNames.length; n < c; n++) - { + for (var n = 0, c = docNames.length; n < c; n++) { item = docNames[n]; itemCount = count[item]; itemCount = count[item] = (itemCount == null ? 1 : itemCount + 1); - if( itemCount === 2 ) - docNames[firstOccurences[item]] = docNames[firstOccurences[item]].substring(0,29) + "-1"; - if( count[ item ] > 1 ) - docNames[n] = docNames[n].substring(0,29) + "-" + count[item]; + if (itemCount === 2) + docNames[firstOccurences[item]] = docNames[firstOccurences[item]].substring(0, 29) + '-1'; + if (count[item] > 1) + docNames[n] = docNames[n].substring(0, 29) + '-' + count[item]; else firstOccurences[item] = n; } @@ -636,30 +632,28 @@ ' \r' + '\r'; - for ( var j = 0; j < docDatas.length; j++ ) { + for (var j = 0; j < docDatas.length; j++) { xmlssDocFile += '\r' + docDatas[j]; if (defaults.mso.rtl) { xmlssDocFile += '\r' + '\r' + '\r'; - } - else + } else xmlssDocFile += '\r'; xmlssDocFile += '\r'; } xmlssDocFile += '\r'; - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return xmlssDocFile; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(xmlssDocFile); - saveToFile ( xmlssDocFile, defaults.fileName + '.xml', "application/xml", "utf-8", "base64", false ); - } - else if ( defaults.type === 'excel' && defaults.mso.fileFormat === 'xlsx' ) { + saveToFile(xmlssDocFile, defaults.fileName + '.xml', 'application/xml', 'utf-8', 'base64', false); + } else if (defaults.type === 'excel' && defaults.mso.fileFormat === 'xlsx') { var sheetNames = []; var workbook = XLSX.utils.book_new(); @@ -673,15 +667,15 @@ var ws = xlsxTableToSheet(this); var sheetName = ''; - if ( typeof defaults.mso.worksheetName === 'string' && defaults.mso.worksheetName.length ) + if (typeof defaults.mso.worksheetName === 'string' && defaults.mso.worksheetName.length) sheetName = defaults.mso.worksheetName + ' ' + (sheetNames.length + 1); - else if ( typeof defaults.mso.worksheetName[sheetNames.length] !== 'undefined' ) + else if (typeof defaults.mso.worksheetName[sheetNames.length] !== 'undefined') sheetName = defaults.mso.worksheetName[sheetNames.length]; - if ( ! sheetName.length ) + if (!sheetName.length) sheetName = $table.find('caption').text() || ''; - if ( ! sheetName.length ) + if (!sheetName.length) sheetName = 'Table ' + (sheetNames.length + 1); - sheetName = $.trim(sheetName.replace(/[\\\/[\]*:?'"]/g,'').substring(0,31)); + sheetName = $.trim(sheetName.replace(/[\\\/[\]*:?'"]/g, '').substring(0, 31)); sheetNames.push(sheetName); XLSX.utils.book_append_sheet(workbook, ws, sheetName); @@ -690,18 +684,17 @@ // add worksheet to workbook var wbout = XLSX.write(workbook, {type: 'binary', bookType: defaults.mso.fileFormat, bookSST: false}); - saveToFile ( xlsxWorkbookToArrayBuffer(wbout), - defaults.fileName + '.' + defaults.mso.fileFormat, - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "UTF-8", "", false ); - } - else if ( defaults.type === 'excel' || defaults.type === 'xls' || defaults.type === 'word' || defaults.type === 'doc' ) { + saveToFile(xlsxWorkbookToArrayBuffer(wbout), + defaults.fileName + '.' + defaults.mso.fileFormat, + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'UTF-8', '', false); + } else if (defaults.type === 'excel' || defaults.type === 'xls' || defaults.type === 'word' || defaults.type === 'doc') { - var MSDocType = (defaults.type === 'excel' || defaults.type === 'xls') ? 'excel' : 'word'; - var MSDocExt = (MSDocType === 'excel') ? 'xls' : 'doc'; + var MSDocType = (defaults.type === 'excel' || defaults.type === 'xls') ? 'excel' : 'word'; + var MSDocExt = (MSDocType === 'excel') ? 'xls' : 'doc'; var MSDocSchema = 'xmlns:x="urn:schemas-microsoft-com:office:' + MSDocType + '"'; - var docData = ''; - var docName = ''; + var docData = ''; + var docName = ''; $(el).filter(function () { return isVisible($(this)); @@ -713,121 +706,121 @@ docName = $.trim(docName.replace(/[\\\/[\]*:?'"]/g, '').substring(0, 31)); } - if ( defaults.exportHiddenCells === false ) { - $hiddenTableElements = $table.find("tr, th, td").filter(":hidden"); + if (defaults.exportHiddenCells === false) { + $hiddenTableElements = $table.find('tr, th, td').filter(':hidden'); checkCellVisibilty = $hiddenTableElements.length > 0; } rowIndex = 0; - ranges = []; + ranges = []; colNames = GetColumnNames(this); // Header docData += ''; - $hrows = collectHeadRows ($table); + $hrows = collectHeadRows($table); $($hrows).each(function () { var $row = $(this); - trData = ""; + trData = ''; ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, - function (cell, row, col) { - if ( cell !== null ) { - var thstyle = ''; - - trData += ' 0 ) - trData += ' colspan="' + tdcolspan + '"'; - - var tdrowspan = getRowspan (cell); - if ( tdrowspan > 0 ) - trData += ' rowspan="' + tdrowspan + '"'; - - trData += '>' + parseString(cell, row, col) + ''; - } - }); - if ( trData.length > 0 ) + function (cell, row, col) { + if (cell !== null) { + var thstyle = ''; + + trData += ' 0) + trData += ' colspan="' + tdcolspan + '"'; + + var tdrowspan = getRowspan(cell); + if (tdrowspan > 0) + trData += ' rowspan="' + tdrowspan + '"'; + + trData += '>' + parseString(cell, row, col) + ''; + } + }); + if (trData.length > 0) docData += '' + trData + ''; rowIndex++; }); docData += ''; // Data - $rows = collectRows ($table); + $rows = collectRows($table); $($rows).each(function () { var $row = $(this); - trData = ""; + trData = ''; ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, - function (cell, row, col) { - if ( cell !== null ) { - var tdvalue = parseString(cell, row, col); - var tdstyle = ''; - var tdcss = $(cell).attr("data-tableexport-msonumberformat"); - - if ( typeof tdcss === 'undefined' && typeof defaults.mso.onMsoNumberFormat === 'function' ) - tdcss = defaults.mso.onMsoNumberFormat(cell, row, col); - - if ( typeof tdcss !== 'undefined' && tdcss !== '' ) - tdstyle = 'style="mso-number-format:\'' + tdcss + '\''; - - if ( defaults.mso.styles.length ) { - var cellstyles = document.defaultView.getComputedStyle(cell, null); - var rowstyles = document.defaultView.getComputedStyle($row[0], null); - - for ( var cssStyle in defaults.mso.styles ) { - tdcss = cellstyles[defaults.mso.styles[cssStyle]]; - if ( tdcss === '' ) - tdcss = rowstyles[defaults.mso.styles[cssStyle]]; - - if ( tdcss !== '' && tdcss !== '0px none rgb(0, 0, 0)' && tdcss !== 'rgba(0, 0, 0, 0)' ) { - tdstyle += (tdstyle === '') ? 'style="' : ';'; - tdstyle += defaults.mso.styles[cssStyle] + ':' + tdcss; - } - } - } - - trData += ' 0 ) - trData += ' colspan="' + tdcolspan + '"'; - - var tdrowspan = getRowspan (cell); - if ( tdrowspan > 0 ) - trData += ' rowspan="' + tdrowspan + '"'; - - if ( typeof tdvalue === 'string' && tdvalue !== '' ) { - tdvalue = preventInjection(tdvalue); - tdvalue = tdvalue.replace(/\n/g, '
'); - } - - trData += '>' + tdvalue + ''; - } - }); - if ( trData.length > 0 ) + function (cell, row, col) { + if (cell !== null) { + var tdvalue = parseString(cell, row, col); + var tdstyle = ''; + var tdcss = $(cell).attr('data-tableexport-msonumberformat'); + + if (typeof tdcss === 'undefined' && typeof defaults.mso.onMsoNumberFormat === 'function') + tdcss = defaults.mso.onMsoNumberFormat(cell, row, col); + + if (typeof tdcss !== 'undefined' && tdcss !== '') + tdstyle = 'style="mso-number-format:\'' + tdcss + '\''; + + if (defaults.mso.styles.length) { + var cellstyles = document.defaultView.getComputedStyle(cell, null); + var rowstyles = document.defaultView.getComputedStyle($row[0], null); + + for (var cssStyle in defaults.mso.styles) { + tdcss = cellstyles[defaults.mso.styles[cssStyle]]; + if (tdcss === '') + tdcss = rowstyles[defaults.mso.styles[cssStyle]]; + + if (tdcss !== '' && tdcss !== '0px none rgb(0, 0, 0)' && tdcss !== 'rgba(0, 0, 0, 0)') { + tdstyle += (tdstyle === '') ? 'style="' : ';'; + tdstyle += defaults.mso.styles[cssStyle] + ':' + tdcss; + } + } + } + + trData += ' 0) + trData += ' colspan="' + tdcolspan + '"'; + + var tdrowspan = getRowspan(cell); + if (tdrowspan > 0) + trData += ' rowspan="' + tdrowspan + '"'; + + if (typeof tdvalue === 'string' && tdvalue !== '') { + tdvalue = preventInjection(tdvalue); + tdvalue = tdvalue.replace(/\n/g, '
'); + } + + trData += '>' + tdvalue + ''; + } + }); + if (trData.length > 0) docData += '
' + trData + ''; rowIndex++; }); - if ( defaults.displayTableName ) + if (defaults.displayTableName) docData += ''; docData += '
' + parseString($('

' + defaults.tableName + '

')) + '
'; @@ -836,91 +829,90 @@ //noinspection XmlUnusedNamespaceDeclaration var docFile = ''; docFile += ''; - docFile += ""; + docFile += ''; if (MSDocType === 'excel') { - docFile += ""; + docFile += ''; + docFile += ''; + docFile += ''; + docFile += ''; + docFile += ''; + docFile += ''; + docFile += ''; } - docFile += ""; - docFile += ""; - docFile += ""; - docFile += "
"; + docFile += ''; + docFile += ''; + docFile += ''; + docFile += '
'; docFile += docData; - docFile += "
"; - docFile += ""; - docFile += ""; + docFile += '
'; + docFile += ''; + docFile += ''; - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return docFile; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(docFile); - saveToFile ( docFile, defaults.fileName + '.' + MSDocExt, "application/vnd.ms-" + MSDocType, "", "base64", false ); - } - else if ( defaults.type === 'png' ) { + saveToFile(docFile, defaults.fileName + '.' + MSDocExt, 'application/vnd.ms-' + MSDocType, '', 'base64', false); + } else if (defaults.type === 'png') { html2canvas($(el)[0]).then( function (canvas) { - var image = canvas.toDataURL(); + var image = canvas.toDataURL(); var byteString = atob(image.substring(22)); // remove data stuff - var buffer = new ArrayBuffer(byteString.length); - var intArray = new Uint8Array(buffer); + var buffer = new ArrayBuffer(byteString.length); + var intArray = new Uint8Array(buffer); - for ( var i = 0; i < byteString.length; i++ ) + for (var i = 0; i < byteString.length; i++) intArray[i] = byteString.charCodeAt(i); - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return byteString; - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(image); - if ( defaults.outputMode === 'window' ) { + if (defaults.outputMode === 'window') { window.open(image); return; } - saveToFile ( buffer, defaults.fileName + '.png', "image/png", "", "", false ); + saveToFile(buffer, defaults.fileName + '.png', 'image/png', '', '', false); }); - } else if ( defaults.type === 'pdf' ) { + } else if (defaults.type === 'pdf') { - if ( defaults.pdfmake.enabled === true ) { + if (defaults.pdfmake.enabled === true) { // pdf output using pdfmake // https://github.com/bpampuch/pdfmake var widths = []; - var body = []; - rowIndex = 0; - ranges = []; + var body = []; + rowIndex = 0; + ranges = []; /** * @return {number} @@ -932,30 +924,28 @@ var r = []; ForEachVisibleCell(this, colselector, rowIndex, length, - function (cell, row, col) { - if ( typeof cell !== 'undefined' && cell !== null ) { - - var colspan = getColspan (cell); - var rowspan = getRowspan (cell); - - var cellValue = parseString(cell, row, col) || " "; - - if ( colspan > 1 || rowspan > 1 ) { - colspan = colspan || 1; - rowspan = rowspan || 1; - r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); - } - else - r.push(cellValue); - } - else - r.push(" "); - }); - - if ( r.length ) + function (cell, row, col) { + if (typeof cell !== 'undefined' && cell !== null) { + + var colspan = getColspan(cell); + var rowspan = getRowspan(cell); + + var cellValue = parseString(cell, row, col) || ' '; + + if (colspan > 1 || rowspan > 1) { + colspan = colspan || 1; + rowspan = rowspan || 1; + r.push({colSpan: colspan, rowSpan: rowspan, text: cellValue}); + } else + r.push(cellValue); + } else + r.push(' '); + }); + + if (r.length) body.push(r); - if ( rlength < r.length ) + if (rlength < r.length) rlength = r.length; rowIndex++; @@ -964,15 +954,15 @@ return rlength; }; - $hrows = collectHeadRows ($(this)); + $hrows = collectHeadRows($(this)); var colcount = CollectPdfmakeData($hrows, 'th,td', $hrows.length); - for ( var i = widths.length; i < colcount; i++ ) - widths.push("*"); + for (var i = widths.length; i < colcount; i++) + widths.push('*'); // Data - $rows = collectRows ($(this)); + $rows = collectRows($(this)); CollectPdfmakeData($rows, 'th,td', $hrows.length + $rows.length); @@ -980,8 +970,8 @@ content: [{ table: { headerRows: $hrows.length, - widths: widths, - body: body + widths: widths, + body: body } }] }; @@ -990,9 +980,9 @@ pdfMake.fonts = { Roboto: { - normal: 'Roboto-Regular.ttf', - bold: 'Roboto-Medium.ttf', - italics: 'Roboto-Italic.ttf', + normal: 'Roboto-Regular.ttf', + bold: 'Roboto-Medium.ttf', + italics: 'Roboto-Italic.ttf', bolditalics: 'Roboto-MediumItalic.ttf' } }; @@ -1000,15 +990,14 @@ $.extend(true, pdfMake.fonts, defaults.pdfmake.fonts); pdfMake.createPdf(docDefinition).getBuffer(function (buffer) { - saveToFile ( buffer, defaults.fileName + '.pdf', "application/pdf", "", "", false ); + saveToFile(buffer, defaults.fileName + '.pdf', 'application/pdf', '', '', false); }); - } - else if ( defaults.jspdf.autotable === false ) { + } else if (defaults.jspdf.autotable === false) { // pdf output using jsPDF's core html support var addHtmlOptions = { - dim: { + dim: { w: getPropertyUnitValue($(el).first().get(0), 'width', 'mm'), h: getPropertyUnitValue($(el).first().get(0), 'height', 'mm') }, @@ -1017,15 +1006,14 @@ var doc = new jsPDF(defaults.jspdf.orientation, defaults.jspdf.unit, defaults.jspdf.format); doc.addHTML($(el).first(), - defaults.jspdf.margins.left, - defaults.jspdf.margins.top, - addHtmlOptions, - function () { - jsPdfOutput(doc, false); - }); + defaults.jspdf.margins.left, + defaults.jspdf.margins.top, + addHtmlOptions, + function () { + jsPdfOutput(doc, false); + }); //delete doc; - } - else { + } else { // pdf output using jsPDF AutoTable plugin // https://github.com/simonbengtsson/jsPDF-AutoTable @@ -1034,25 +1022,25 @@ // When setting jspdf.format to 'bestfit' tableExport tries to choose // the minimum required paper format and orientation in which the table // (or tables in multitable mode) completely fits without column adjustment - if ( typeof defaults.jspdf.format === 'string' && defaults.jspdf.format.toLowerCase() === 'bestfit' ) { + if (typeof defaults.jspdf.format === 'string' && defaults.jspdf.format.toLowerCase() === 'bestfit') { var rk = '', ro = ''; var mw = 0; $(el).each(function () { - if ( isVisible($(this)) ) { + if (isVisible($(this))) { var w = getPropertyUnitValue($(this).get(0), 'width', 'pt'); - if ( w > mw ) { - if ( w > pageFormats.a0[0] ) { + if (w > mw) { + if (w > pageFormats.a0[0]) { rk = 'a0'; ro = 'l'; } - for ( var key in pageFormats ) { - if ( pageFormats.hasOwnProperty(key) ) { - if ( pageFormats[key][1] > w ) { + for (var key in pageFormats) { + if (pageFormats.hasOwnProperty(key)) { + if (pageFormats[key][1] > w) { rk = key; ro = 'l'; - if ( pageFormats[key][0] > w ) + if (pageFormats[key][0] > w) ro = 'p'; } } @@ -1061,52 +1049,52 @@ } } }); - defaults.jspdf.format = (rk === '' ? 'a4' : rk); + defaults.jspdf.format = (rk === '' ? 'a4' : rk); defaults.jspdf.orientation = (ro === '' ? 'w' : ro); } // The jsPDF doc object is stored in defaults.jspdf.autotable.tableExport, // thus it can be accessed from any callback function - if ( teOptions.doc == null ) { + if (teOptions.doc == null) { teOptions.doc = new jsPDF(defaults.jspdf.orientation, - defaults.jspdf.unit, - defaults.jspdf.format); + defaults.jspdf.unit, + defaults.jspdf.format); teOptions.wScaleFactor = 1; teOptions.hScaleFactor = 1; - if ( typeof defaults.jspdf.onDocCreated === 'function' ) + if (typeof defaults.jspdf.onDocCreated === 'function') defaults.jspdf.onDocCreated(teOptions.doc); } - if ( teOptions.outputImages === true ) + if (teOptions.outputImages === true) teOptions.images = {}; - if ( typeof teOptions.images !== 'undefined' ) { + if (typeof teOptions.images !== 'undefined') { $(el).filter(function () { return isVisible($(this)); }).each(function () { var rowCount = 0; - ranges = []; + ranges = []; - if ( defaults.exportHiddenCells === false ) { - $hiddenTableElements = $(this).find("tr, th, td").filter(":hidden"); + if (defaults.exportHiddenCells === false) { + $hiddenTableElements = $(this).find('tr, th, td').filter(':hidden'); checkCellVisibilty = $hiddenTableElements.length > 0; } - $hrows = collectHeadRows ($(this)); - $rows = collectRows ($(this)); + $hrows = collectHeadRows($(this)); + $rows = collectRows($(this)); $($rows).each(function () { ForEachVisibleCell(this, 'td,th', $hrows.length + rowCount, $hrows.length + $rows.length, - function (cell) { - collectImages(cell, $(cell).children(), teOptions); - }); + function (cell) { + collectImages(cell, $(cell).children(), teOptions); + }); rowCount++; }); }); $hrows = []; - $rows = []; + $rows = []; } loadImages(teOptions, function () { @@ -1115,29 +1103,29 @@ }).each(function () { var colKey; rowIndex = 0; - ranges = []; + ranges = []; - if ( defaults.exportHiddenCells === false ) { - $hiddenTableElements = $(this).find("tr, th, td").filter(":hidden"); + if (defaults.exportHiddenCells === false) { + $hiddenTableElements = $(this).find('tr, th, td').filter(':hidden'); checkCellVisibilty = $hiddenTableElements.length > 0; } colNames = GetColumnNames(this); teOptions.columns = []; - teOptions.rows = []; + teOptions.rows = []; teOptions.teCells = {}; // onTable: optional callback function for every matching table that can be used // to modify the tableExport options or to skip the output of a particular table // if the table selector targets multiple tables - if ( typeof teOptions.onTable === 'function' ) - if ( teOptions.onTable($(this), defaults) === false ) + if (typeof teOptions.onTable === 'function') + if (teOptions.onTable($(this), defaults) === false) return true; // continue to next iteration step (table) // each table works with an own copy of AutoTable options defaults.jspdf.autotable.tableExport = null; // avoid deep recursion error - var atOptions = $.extend(true, {}, defaults.jspdf.autotable); + var atOptions = $.extend(true, {}, defaults.jspdf.autotable); defaults.jspdf.autotable.tableExport = teOptions; atOptions.margin = {}; @@ -1145,13 +1133,13 @@ atOptions.tableExport = teOptions; // Fix jsPDF Autotable's row height calculation - if ( typeof atOptions.beforePageContent !== 'function' ) { + if (typeof atOptions.beforePageContent !== 'function') { atOptions.beforePageContent = function (data) { - if ( data.pageCount === 1 ) { + if (data.pageCount === 1) { var all = data.table.rows.concat(data.table.headerRow); $.each(all, function () { var row = this; - if ( row.height > 0 ) { + if (row.height > 0) { row.height += (2 - FONT_ROW_RATIO) / 2 * row.styles.fontSize; data.table.height += (2 - FONT_ROW_RATIO) / 2 * row.styles.fontSize; } @@ -1160,23 +1148,23 @@ }; } - if ( typeof atOptions.createdHeaderCell !== 'function' ) { + if (typeof atOptions.createdHeaderCell !== 'function') { // apply some original css styles to pdf header cells atOptions.createdHeaderCell = function (cell, data) { // jsPDF AutoTable plugin v2.0.14 fix: each cell needs its own styles object cell.styles = $.extend({}, data.row.styles); - if ( typeof teOptions.columns [data.column.dataKey] !== 'undefined' ) { + if (typeof teOptions.columns [data.column.dataKey] !== 'undefined') { var col = teOptions.columns [data.column.dataKey]; - if ( typeof col.rect !== 'undefined' ) { + if (typeof col.rect !== 'undefined') { var rh; cell.contentWidth = col.rect.width; - if ( typeof teOptions.heightRatio === 'undefined' || teOptions.heightRatio === 0 ) { - if ( data.row.raw [data.column.dataKey].rowspan ) + if (typeof teOptions.heightRatio === 'undefined' || teOptions.heightRatio === 0) { + if (data.row.raw [data.column.dataKey].rowspan) rh = data.row.raw [data.column.dataKey].rect.height / data.row.raw [data.column.dataKey].rowspan; else rh = data.row.raw [data.column.dataKey].rect.height; @@ -1185,75 +1173,75 @@ } rh = data.row.raw [data.column.dataKey].rect.height * teOptions.heightRatio; - if ( rh > cell.styles.rowHeight ) + if (rh > cell.styles.rowHeight) cell.styles.rowHeight = rh; } cell.styles.halign = (atOptions.headerStyles.halign === 'inherit') ? 'center' : atOptions.headerStyles.halign; cell.styles.valign = atOptions.headerStyles.valign; - if ( typeof col.style !== 'undefined' && col.style.hidden !== true ) { - if ( atOptions.headerStyles.halign === 'inherit' ) + if (typeof col.style !== 'undefined' && col.style.hidden !== true) { + if (atOptions.headerStyles.halign === 'inherit') cell.styles.halign = col.style.align; - if ( atOptions.styles.fillColor === 'inherit' ) + if (atOptions.styles.fillColor === 'inherit') cell.styles.fillColor = col.style.bcolor; - if ( atOptions.styles.textColor === 'inherit' ) + if (atOptions.styles.textColor === 'inherit') cell.styles.textColor = col.style.color; - if ( atOptions.styles.fontStyle === 'inherit' ) + if (atOptions.styles.fontStyle === 'inherit') cell.styles.fontStyle = col.style.fstyle; } } }; } - if ( typeof atOptions.createdCell !== 'function' ) { + if (typeof atOptions.createdCell !== 'function') { // apply some original css styles to pdf table cells atOptions.createdCell = function (cell, data) { - var tecell = teOptions.teCells [data.row.index + ":" + data.column.dataKey]; + var tecell = teOptions.teCells [data.row.index + ':' + data.column.dataKey]; cell.styles.halign = (atOptions.styles.halign === 'inherit') ? 'center' : atOptions.styles.halign; cell.styles.valign = atOptions.styles.valign; - if ( typeof tecell !== 'undefined' && typeof tecell.style !== 'undefined' && tecell.style.hidden !== true ) { - if ( atOptions.styles.halign === 'inherit' ) + if (typeof tecell !== 'undefined' && typeof tecell.style !== 'undefined' && tecell.style.hidden !== true) { + if (atOptions.styles.halign === 'inherit') cell.styles.halign = tecell.style.align; - if ( atOptions.styles.fillColor === 'inherit' ) + if (atOptions.styles.fillColor === 'inherit') cell.styles.fillColor = tecell.style.bcolor; - if ( atOptions.styles.textColor === 'inherit' ) + if (atOptions.styles.textColor === 'inherit') cell.styles.textColor = tecell.style.color; - if ( atOptions.styles.fontStyle === 'inherit' ) + if (atOptions.styles.fontStyle === 'inherit') cell.styles.fontStyle = tecell.style.fstyle; } }; } - if ( typeof atOptions.drawHeaderCell !== 'function' ) { + if (typeof atOptions.drawHeaderCell !== 'function') { atOptions.drawHeaderCell = function (cell, data) { var colopt = teOptions.columns [data.column.dataKey]; - if ( (colopt.style.hasOwnProperty("hidden") !== true || colopt.style.hidden !== true) && - colopt.rowIndex >= 0 ) + if ((colopt.style.hasOwnProperty('hidden') !== true || colopt.style.hidden !== true) && + colopt.rowIndex >= 0) return prepareAutoTableText(cell, data, colopt); else return false; // cell is hidden }; } - if ( typeof atOptions.drawCell !== 'function' ) { + if (typeof atOptions.drawCell !== 'function') { atOptions.drawCell = function (cell, data) { - var tecell = teOptions.teCells [data.row.index + ":" + data.column.dataKey]; + var tecell = teOptions.teCells [data.row.index + ':' + data.column.dataKey]; var draw2canvas = (typeof tecell !== 'undefined' && tecell.isCanvas); - if ( draw2canvas !== true ) { - if ( prepareAutoTableText(cell, data, tecell) ) { + if (draw2canvas !== true) { + if (prepareAutoTableText(cell, data, tecell)) { teOptions.doc.rect(cell.x, cell.y, cell.width, cell.height, cell.styles.fillStyle); - if ( typeof tecell !== 'undefined' && - typeof tecell.elements !== 'undefined' && tecell.elements.length ) { + if (typeof tecell !== 'undefined' && + typeof tecell.elements !== 'undefined' && tecell.elements.length) { var hScale = cell.height / tecell.rect.height; - if ( hScale > teOptions.hScaleFactor ) + if (hScale > teOptions.hScaleFactor) teOptions.hScaleFactor = hScale; teOptions.wScaleFactor = cell.width / tecell.rect.width; @@ -1262,21 +1250,19 @@ cell.textPos.y = ySave; drawAutotableText(cell, tecell.elements, teOptions); - } - else + } else drawAutotableText(cell, {}, teOptions); } - } - else { + } else { var container = tecell.elements[0]; - var imgId = $(container).attr("data-tableexport-canvas"); + var imgId = $(container).attr('data-tableexport-canvas'); var r = container.getBoundingClientRect(); cell.width = r.width * teOptions.wScaleFactor; cell.height = r.height * teOptions.hScaleFactor; data.row.height = cell.height; - jsPdfDrawImage (cell, container, imgId, teOptions); + jsPdfDrawImage(cell, container, imgId, teOptions); } return false; }; @@ -1284,34 +1270,34 @@ // collect header and data rows teOptions.headerrows = []; - $hrows = collectHeadRows ($(this)); + $hrows = collectHeadRows($(this)); $($hrows).each(function () { colKey = 0; teOptions.headerrows[rowIndex] = []; ForEachVisibleCell(this, 'th,td', rowIndex, $hrows.length, - function (cell, row, col) { - var obj = getCellStyles(cell); - obj.title = parseString(cell, row, col); - obj.key = colKey++; - obj.rowIndex = rowIndex; - teOptions.headerrows[rowIndex].push(obj); - }); + function (cell, row, col) { + var obj = getCellStyles(cell); + obj.title = parseString(cell, row, col); + obj.key = colKey++; + obj.rowIndex = rowIndex; + teOptions.headerrows[rowIndex].push(obj); + }); rowIndex++; }); - if ( rowIndex > 0 ) { + if (rowIndex > 0) { // iterate through last row var lastrow = rowIndex - 1; - while ( lastrow >= 0 ) { + while (lastrow >= 0) { $.each(teOptions.headerrows[lastrow], function () { var obj = this; - if ( lastrow > 0 && this.rect === null ) + if (lastrow > 0 && this.rect === null) obj = teOptions.headerrows[lastrow - 1][this.key]; - if ( obj !== null && obj.rowIndex >= 0 && - (obj.style.hasOwnProperty("hidden") !== true || obj.style.hidden !== true) ) + if (obj !== null && obj.rowIndex >= 0 && + (obj.style.hasOwnProperty('hidden') !== true || obj.style.hidden !== true)) teOptions.columns.push(obj); }); @@ -1320,42 +1306,41 @@ } var rowCount = 0; - $rows = []; - $rows = collectRows ($(this)); + $rows = []; + $rows = collectRows($(this)); $($rows).each(function () { var rowData = []; - colKey = 0; + colKey = 0; ForEachVisibleCell(this, 'td,th', rowIndex, $hrows.length + $rows.length, - function (cell, row, col) { - var obj; - - if ( typeof teOptions.columns[colKey] === 'undefined' ) { - // jsPDF-Autotable needs columns. Thus define hidden ones for tables without thead - obj = { - title: '', - key: colKey, - style: { - hidden: true - } - }; - teOptions.columns.push(obj); - } - if ( typeof cell !== 'undefined' && cell !== null ) { - obj = getCellStyles(cell); - obj.isCanvas = cell.hasAttribute("data-tableexport-canvas"); - obj.elements = obj.isCanvas ? $(cell) : $(cell).children(); - teOptions.teCells [rowCount + ":" + colKey++] = obj; - } - else { - obj = $.extend(true, {}, teOptions.teCells [rowCount + ":" + (colKey - 1)]); - obj.colspan = -1; - teOptions.teCells [rowCount + ":" + colKey++] = obj; - } - - rowData.push(parseString(cell, row, col)); - }); - if ( rowData.length ) { + function (cell, row, col) { + var obj; + + if (typeof teOptions.columns[colKey] === 'undefined') { + // jsPDF-Autotable needs columns. Thus define hidden ones for tables without thead + obj = { + title: '', + key: colKey, + style: { + hidden: true + } + }; + teOptions.columns.push(obj); + } + if (typeof cell !== 'undefined' && cell !== null) { + obj = getCellStyles(cell); + obj.isCanvas = cell.hasAttribute('data-tableexport-canvas'); + obj.elements = obj.isCanvas ? $(cell) : $(cell).children(); + teOptions.teCells [rowCount + ':' + colKey++] = obj; + } else { + obj = $.extend(true, {}, teOptions.teCells [rowCount + ':' + (colKey - 1)]); + obj.colspan = -1; + teOptions.teCells [rowCount + ':' + colKey++] = obj; + } + + rowData.push(parseString(cell, row, col)); + }); + if (rowData.length) { teOptions.rows.push(rowData); rowCount++; } @@ -1364,14 +1349,14 @@ // onBeforeAutotable: optional callback function before calling // jsPDF AutoTable that can be used to modify the AutoTable options - if ( typeof teOptions.onBeforeAutotable === 'function' ) + if (typeof teOptions.onBeforeAutotable === 'function') teOptions.onBeforeAutotable($(this), teOptions.columns, teOptions.rows, atOptions); teOptions.doc.autoTable(teOptions.columns, teOptions.rows, atOptions); // onAfterAutotable: optional callback function after returning // from jsPDF AutoTable that can be used to modify the AutoTable options - if ( typeof teOptions.onAfterAutotable === 'function' ) + if (typeof teOptions.onAfterAutotable === 'function') teOptions.onAfterAutotable($(this), atOptions); // set the start position for the next table (in case there is one) @@ -1381,11 +1366,11 @@ jsPdfOutput(teOptions.doc, (typeof teOptions.images !== 'undefined' && jQuery.isEmptyObject(teOptions.images) === false)); - if ( typeof teOptions.headerrows !== 'undefined' ) + if (typeof teOptions.headerrows !== 'undefined') teOptions.headerrows.length = 0; - if ( typeof teOptions.columns !== 'undefined' ) + if (typeof teOptions.columns !== 'undefined') teOptions.columns.length = 0; - if ( typeof teOptions.rows !== 'undefined' ) + if (typeof teOptions.rows !== 'undefined') teOptions.rows.length = 0; delete teOptions.doc; teOptions.doc = null; @@ -1395,7 +1380,7 @@ function collectHeadRows ($table) { var result = []; - findTableElements($table,'thead').each(function () { + findTableElements($table, 'thead').each(function () { result.push.apply(result, findTableElements($(this), defaults.theadSelector).toArray()); }); return result; @@ -1403,11 +1388,11 @@ function collectRows ($table) { var result = []; - findTableElements($table,'tbody').each(function () { + findTableElements($table, 'tbody').each(function () { result.push.apply(result, findTableElements($(this), defaults.tbodySelector).toArray()); }); - if ( defaults.tfootSelector.length ) { - findTableElements($table,'tfoot').each(function () { + if (defaults.tfootSelector.length) { + findTableElements($table, 'tfoot').each(function () { result.push.apply(result, findTableElements($(this), defaults.tfootSelector).toArray()); }); } @@ -1417,7 +1402,7 @@ function findTableElements ($parent, selector) { var parentSelector = $parent[0].tagName; var parentLevel = $parent.parents(parentSelector).length; - return $parent.find(selector).filter (function () { + return $parent.find(selector).filter(function () { return parentLevel === $(this).closest(parentSelector).parents(parentSelector).length; }); } @@ -1425,8 +1410,8 @@ function GetColumnNames (table) { var result = []; $(table).find('thead').first().find('th').each(function (index, el) { - if ( $(el).attr("data-field") !== undefined ) - result[index] = $(el).attr("data-field"); + if ($(el).attr('data-field') !== undefined) + result[index] = $(el).attr('data-field'); else result[index] = index.toString(); }); @@ -1437,15 +1422,15 @@ var isRow = typeof $element[0].rowIndex !== 'undefined'; var isCell = isRow === false && typeof $element[0].cellIndex !== 'undefined'; var isElementVisible = (isCell || isRow) ? isTableElementVisible($element) : $element.is(':visible'); - var tableexportDisplay = $element.attr("data-tableexport-display"); + var tableexportDisplay = $element.attr('data-tableexport-display'); if (isCell && tableexportDisplay !== 'none' && tableexportDisplay !== 'always') { $element = $($element[0].parentNode); isRow = typeof $element[0].rowIndex !== 'undefined'; - tableexportDisplay = $element.attr("data-tableexport-display"); + tableexportDisplay = $element.attr('data-tableexport-display'); } if (isRow && tableexportDisplay !== 'none' && tableexportDisplay !== 'always') { - tableexportDisplay = $element.closest('table').attr("data-tableexport-display"); + tableexportDisplay = $element.closest('table').attr('data-tableexport-display'); } return tableexportDisplay !== 'none' && (isElementVisible === true || tableexportDisplay === 'always'); @@ -1454,8 +1439,8 @@ function isTableElementVisible ($element) { var hiddenEls = []; - if ( checkCellVisibilty ) { - hiddenEls = $hiddenTableElements.filter (function () { + if (checkCellVisibilty) { + hiddenEls = $hiddenTableElements.filter(function () { var found = false; if (this.nodeType === $element[0].nodeType) { @@ -1477,32 +1462,31 @@ var result = false; if (isVisible($cell)) { - if ( defaults.ignoreColumn.length > 0 ) { - if ( $.inArray(colIndex, defaults.ignoreColumn) !== -1 || + if (defaults.ignoreColumn.length > 0) { + if ($.inArray(colIndex, defaults.ignoreColumn) !== -1 || $.inArray(colIndex - rowLength, defaults.ignoreColumn) !== -1 || (colNames.length > colIndex && typeof colNames[colIndex] !== 'undefined' && - $.inArray(colNames[colIndex], defaults.ignoreColumn) !== -1) ) + $.inArray(colNames[colIndex], defaults.ignoreColumn) !== -1)) result = true; } - } - else + } else result = true; return result; } function ForEachVisibleCell (tableRow, selector, rowIndex, rowCount, cellcallback) { - if ( typeof (cellcallback) === 'function' ) { + if (typeof (cellcallback) === 'function') { var ignoreRow = false; if (typeof defaults.onIgnoreRow === 'function') ignoreRow = defaults.onIgnoreRow($(tableRow), rowIndex); if (ignoreRow === false && - (defaults.ignoreRow.length === 0 || - ($.inArray(rowIndex, defaults.ignoreRow) === -1 && + (defaults.ignoreRow.length === 0 || + ($.inArray(rowIndex, defaults.ignoreRow) === -1 && $.inArray(rowIndex - rowCount, defaults.ignoreRow) === -1)) && - isVisible($(tableRow))) { + isVisible($(tableRow))) { var $cells = findTableElements($(tableRow), selector); var cellCount = 0; @@ -1510,27 +1494,27 @@ $cells.each(function (colIndex) { var $cell = $(this); var c; - var colspan = getColspan (this); - var rowspan = getRowspan (this); + var colspan = getColspan(this); + var rowspan = getRowspan(this); // Skip ranges $.each(ranges, function () { var range = this; - if ( rowIndex >= range.s.r && rowIndex <= range.e.r && cellCount >= range.s.c && cellCount <= range.e.c ) { - for ( c = 0; c <= range.e.c - range.s.c; ++c ) + if (rowIndex >= range.s.r && rowIndex <= range.e.r && cellCount >= range.s.c && cellCount <= range.e.c) { + for (c = 0; c <= range.e.c - range.s.c; ++c) cellcallback(null, rowIndex, cellCount++); } }); - if ( isColumnIgnored($cell, $cells.length, colIndex) === false ) { + if (isColumnIgnored($cell, $cells.length, colIndex) === false) { // Handle Row Span - if ( rowspan || colspan ) { + if (rowspan || colspan) { rowspan = rowspan || 1; colspan = colspan || 1; ranges.push({ - s: {r: rowIndex, c: cellCount}, - e: {r: rowIndex + rowspan - 1, c: cellCount + colspan - 1} - }); + s: {r: rowIndex, c: cellCount}, + e: {r: rowIndex + rowspan - 1, c: cellCount + colspan - 1} + }); } // Handle Value @@ -1538,16 +1522,16 @@ } // Handle Colspan - if ( colspan ) - for ( c = 0; c < colspan - 1; ++c ) + if (colspan) + for (c = 0; c < colspan - 1; ++c) cellcallback(null, rowIndex, cellCount++); }); // Skip ranges $.each(ranges, function () { var range = this; - if ( rowIndex >= range.s.r && rowIndex <= range.e.r && cellCount >= range.s.c && cellCount <= range.e.c ) { - for ( c = 0; c <= range.e.c - range.s.c; ++c ) + if (rowIndex >= range.s.r && rowIndex <= range.e.r && cellCount >= range.s.c && cellCount <= range.e.c) { + for (c = 0; c <= range.e.c - range.s.c; ++c) cellcallback(null, rowIndex, cellCount++); } }); @@ -1556,37 +1540,35 @@ } function jsPdfDrawImage (cell, container, imgId, teOptions) { - if ( typeof teOptions.images !== 'undefined' ) { + if (typeof teOptions.images !== 'undefined') { var image = teOptions.images[imgId]; - if ( typeof image !== 'undefined' ) { - var r = container.getBoundingClientRect(); - var arCell = cell.width / cell.height; - var arImg = r.width / r.height; - var imgWidth = cell.width; - var imgHeight = cell.height; - var px2pt = 0.264583 * 72 / 25.4; - var uy = 0; + if (typeof image !== 'undefined') { + var r = container.getBoundingClientRect(); + var arCell = cell.width / cell.height; + var arImg = r.width / r.height; + var imgWidth = cell.width; + var imgHeight = cell.height; + var px2pt = 0.264583 * 72 / 25.4; + var uy = 0; - if ( arImg <= arCell ) { + if (arImg <= arCell) { imgHeight = Math.min(cell.height, r.height); - imgWidth = r.width * imgHeight / r.height; - } - else if ( arImg > arCell ) { - imgWidth = Math.min(cell.width, r.width); + imgWidth = r.width * imgHeight / r.height; + } else if (arImg > arCell) { + imgWidth = Math.min(cell.width, r.width); imgHeight = r.height * imgWidth / r.width; } imgWidth *= px2pt; imgHeight *= px2pt; - if ( imgHeight < cell.height ) + if (imgHeight < cell.height) uy = (cell.height - imgHeight) / 2; try { teOptions.doc.addImage(image.src, cell.textPos.x, cell.y + uy, imgWidth, imgHeight); - } - catch (e) { + } catch (e) { // TODO: IE -> convert png to jpeg } cell.textPos.x += imgWidth; @@ -1595,23 +1577,22 @@ } function jsPdfOutput (doc, hasimages) { - if ( defaults.outputMode === 'string' ) + if (defaults.outputMode === 'string') return doc.output(); - if ( defaults.outputMode === 'base64' ) + if (defaults.outputMode === 'base64') return base64encode(doc.output()); - if ( defaults.outputMode === 'window' ) { + if (defaults.outputMode === 'window') { window.URL = window.URL || window.webkitURL; - window.open(window.URL.createObjectURL(doc.output("blob"))); + window.open(window.URL.createObjectURL(doc.output('blob'))); return; } try { var blob = doc.output('blob'); saveAs(blob, defaults.fileName + '.pdf'); - } - catch (e) { + } catch (e) { downloadFile(defaults.fileName + '.pdf', 'data:application/pdf' + (hasimages ? '' : ';base64') + ',', hasimages ? doc.output('blob') : doc.output()); @@ -1620,61 +1601,59 @@ function prepareAutoTableText (cell, data, cellopt) { var cs = 0; - if ( typeof cellopt !== 'undefined' ) + if (typeof cellopt !== 'undefined') cs = cellopt.colspan; - if ( cs >= 0 ) { + if (cs >= 0) { // colspan handling var cellWidth = cell.width; - var textPosX = cell.textPos.x; - var i = data.table.columns.indexOf(data.column); + var textPosX = cell.textPos.x; + var i = data.table.columns.indexOf(data.column); - for ( var c = 1; c < cs; c++ ) { + for (var c = 1; c < cs; c++) { var column = data.table.columns[i + c]; cellWidth += column.width; } - if ( cs > 1 ) { - if ( cell.styles.halign === 'right' ) + if (cs > 1) { + if (cell.styles.halign === 'right') textPosX = cell.textPos.x + cellWidth - cell.width; - else if ( cell.styles.halign === 'center' ) + else if (cell.styles.halign === 'center') textPosX = cell.textPos.x + (cellWidth - cell.width) / 2; } - cell.width = cellWidth; + cell.width = cellWidth; cell.textPos.x = textPosX; - if ( typeof cellopt !== 'undefined' && cellopt.rowspan > 1 ) + if (typeof cellopt !== 'undefined' && cellopt.rowspan > 1) cell.height = cell.height * cellopt.rowspan; // fix jsPDF's calculation of text position - if ( cell.styles.valign === 'middle' || cell.styles.valign === 'bottom' ) { + if (cell.styles.valign === 'middle' || cell.styles.valign === 'bottom') { var splittedText = typeof cell.text === 'string' ? cell.text.split(/\r\n|\r|\n/g) : cell.text; - var lineCount = splittedText.length || 1; - if ( lineCount > 2 ) + var lineCount = splittedText.length || 1; + if (lineCount > 2) cell.textPos.y -= ((2 - FONT_ROW_RATIO) / 2 * data.row.styles.fontSize) * (lineCount - 2) / 3; } return true; - } - else + } else return false; // cell is hidden (colspan = -1), don't draw it } function collectImages (cell, elements, teOptions) { - if ( typeof cell !== 'undefined' && cell !== null ) { + if (typeof cell !== 'undefined' && cell !== null) { - if ( cell.hasAttribute("data-tableexport-canvas") ) { + if (cell.hasAttribute('data-tableexport-canvas')) { var imgId = new Date().getTime(); - $(cell).attr("data-tableexport-canvas", imgId); + $(cell).attr('data-tableexport-canvas', imgId); teOptions.images[imgId] = { - url: '[data-tableexport-canvas="'+imgId+'"]', + url: '[data-tableexport-canvas="' + imgId + '"]', src: null }; - } - else if (elements !== 'undefined' && elements != null) { + } else if (elements !== 'undefined' && elements != null) { elements.each(function () { - if ($(this).is("img")) { + if ($(this).is('img')) { var imgId = strHashCode(this.src); teOptions.images[imgId] = { url: this.src, @@ -1702,37 +1681,36 @@ if ($imgContainer.length) { imageCount = ++pendingCount; - html2canvas($imgContainer[0]).then(function(canvas) { - image.src = canvas.toDataURL("image/png"); - if ( !--pendingCount ) + html2canvas($imgContainer[0]).then(function (canvas) { + image.src = canvas.toDataURL('image/png'); + if (!--pendingCount) done(); }); } - } - else { + } else { var img = new Image(); imageCount = ++pendingCount; img.crossOrigin = 'Anonymous'; img.onerror = img.onload = function () { - if ( img.complete ) { + if (img.complete) { - if ( img.src.indexOf('data:image/') === 0 ) { + if (img.src.indexOf('data:image/') === 0) { img.width = image.width || img.width || 0; img.height = image.height || img.height || 0; } - if ( img.width + img.height ) { - var canvas = document.createElement("canvas"); - var ctx = canvas.getContext("2d"); + if (img.width + img.height) { + var canvas = document.createElement('canvas'); + var ctx = canvas.getContext('2d'); canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); - image.src = canvas.toDataURL("image/png"); + image.src = canvas.toDataURL('image/png'); } } - if ( !--pendingCount ) + if (!--pendingCount) done(); }; img.src = image.url; @@ -1740,9 +1718,9 @@ } } - if ( typeof teOptions.images !== 'undefined' ) { - for ( var i in teOptions.images ) - if ( teOptions.images.hasOwnProperty(i) ) + if (typeof teOptions.images !== 'undefined') { + for (var i in teOptions.images) + if (teOptions.images.hasOwnProperty(i)) loadImage(teOptions.images[i]); } @@ -1751,12 +1729,12 @@ function drawAutotableElements (cell, elements, teOptions) { elements.each(function () { - if ( $(this).is("div") ) { + if ($(this).is('div')) { var bcolor = rgb2array(getStyle(this, 'background-color'), [255, 255, 255]); var lcolor = rgb2array(getStyle(this, 'border-top-color'), [0, 0, 0]); var lwidth = getPropertyUnitValue(this, 'border-top-width', defaults.jspdf.unit); - var r = this.getBoundingClientRect(); + var r = this.getBoundingClientRect(); var ux = this.offsetLeft * teOptions.wScaleFactor; var uy = this.offsetTop * teOptions.hScaleFactor; var uw = r.width * teOptions.wScaleFactor; @@ -1765,11 +1743,10 @@ teOptions.doc.setDrawColor.apply(undefined, lcolor); teOptions.doc.setFillColor.apply(undefined, bcolor); teOptions.doc.setLineWidth(lwidth); - teOptions.doc.rect(cell.x + ux, cell.y + uy, uw, uh, lwidth ? "FD" : "F"); - } - else if ( $(this).is("img") ) { - var imgId = strHashCode(this.src); - jsPdfDrawImage (cell, this, imgId, teOptions); + teOptions.doc.rect(cell.x + ux, cell.y + uy, uw, uh, lwidth ? 'FD' : 'F'); + } else if ($(this).is('img')) { + var imgId = strHashCode(this.src); + jsPdfDrawImage(cell, this, imgId, teOptions); } drawAutotableElements(cell, $(this).children(), teOptions); @@ -1777,54 +1754,53 @@ } function drawAutotableText (cell, texttags, teOptions) { - if ( typeof teOptions.onAutotableText === 'function' ) { + if (typeof teOptions.onAutotableText === 'function') { teOptions.onAutotableText(teOptions.doc, cell, texttags); - } - else { - var x = cell.textPos.x; - var y = cell.textPos.y; + } else { + var x = cell.textPos.x; + var y = cell.textPos.y; var style = {halign: cell.styles.halign, valign: cell.styles.valign}; - if ( texttags.length ) { + if (texttags.length) { var tag = texttags[0]; - while ( tag.previousSibling ) + while (tag.previousSibling) tag = tag.previousSibling; var b = false, i = false; - while ( tag ) { - var txt = tag.innerText || tag.textContent || ""; - var leadingspace = (txt.length && txt[0] === " ") ? " " : ""; - var trailingspace = (txt.length > 1 && txt[txt.length - 1] === " ") ? " " : ""; + while (tag) { + var txt = tag.innerText || tag.textContent || ''; + var leadingspace = (txt.length && txt[0] === ' ') ? ' ' : ''; + var trailingspace = (txt.length > 1 && txt[txt.length - 1] === ' ') ? ' ' : ''; if (defaults.preserve.leadingWS !== true) txt = leadingspace + trimLeft(txt); if (defaults.preserve.trailingWS !== true) txt = trimRight(txt) + trailingspace; - if ( $(tag).is("br") ) { + if ($(tag).is('br')) { x = cell.textPos.x; y += teOptions.doc.internal.getFontSize(); } - if ( $(tag).is("b") ) + if ($(tag).is('b')) b = true; - else if ( $(tag).is("i") ) + else if ($(tag).is('i')) i = true; - if ( b || i ) - teOptions.doc.setFontType((b && i) ? "bolditalic" : b ? "bold" : "italic"); + if (b || i) + teOptions.doc.setFontType((b && i) ? 'bolditalic' : b ? 'bold' : 'italic'); var w = teOptions.doc.getStringUnitWidth(txt) * teOptions.doc.internal.getFontSize(); - if ( w ) { - if ( cell.styles.overflow === 'linebreak' && - x > cell.textPos.x && (x + w) > (cell.textPos.x + cell.width) ) { - var chars = ".,!%*;:=-"; - if ( chars.indexOf(txt.charAt(0)) >= 0 ) { + if (w) { + if (cell.styles.overflow === 'linebreak' && + x > cell.textPos.x && (x + w) > (cell.textPos.x + cell.width)) { + var chars = '.,!%*;:=-'; + if (chars.indexOf(txt.charAt(0)) >= 0) { var s = txt.charAt(0); - w = teOptions.doc.getStringUnitWidth(s) * teOptions.doc.internal.getFontSize(); - if ( (x + w) <= (cell.textPos.x + cell.width) ) { + w = teOptions.doc.getStringUnitWidth(s) * teOptions.doc.internal.getFontSize(); + if ((x + w) <= (cell.textPos.x + cell.width)) { teOptions.doc.autoTableText(s, x, y, style); txt = txt.substring(1, txt.length); } @@ -1834,10 +1810,10 @@ y += teOptions.doc.internal.getFontSize(); } - if ( cell.styles.overflow !== 'visible' ) { - while ( txt.length && (x + w) > (cell.textPos.x + cell.width) ) { + if (cell.styles.overflow !== 'visible') { + while (txt.length && (x + w) > (cell.textPos.x + cell.width)) { txt = txt.substring(0, txt.length - 1); - w = teOptions.doc.getStringUnitWidth(txt) * teOptions.doc.internal.getFontSize(); + w = teOptions.doc.getStringUnitWidth(txt) * teOptions.doc.internal.getFontSize(); } } @@ -1845,43 +1821,42 @@ x += w; } - if ( b || i ) { - if ( $(tag).is("b") ) + if (b || i) { + if ($(tag).is('b')) b = false; - else if ( $(tag).is("i") ) + else if ($(tag).is('i')) i = false; - teOptions.doc.setFontType((!b && !i) ? "normal" : b ? "bold" : "italic"); + teOptions.doc.setFontType((!b && !i) ? 'normal' : b ? 'bold' : 'italic'); } tag = tag.nextSibling; } cell.textPos.x = x; cell.textPos.y = y; - } - else { + } else { teOptions.doc.autoTableText(cell.text, cell.textPos.x, cell.textPos.y, style); } } } function escapeRegExp (string) { - return string == null ? "" : string.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1"); + return string == null ? '' : string.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'); } function replaceAll (string, find, replace) { - return string == null ? "" : string.toString().replace(new RegExp(escapeRegExp(find), 'g'), replace); + return string == null ? '' : string.toString().replace(new RegExp(escapeRegExp(find), 'g'), replace); } function trimLeft (string) { - return string == null ? "" : string.toString().replace(/^\s+/, ""); + return string == null ? '' : string.toString().replace(/^\s+/, ''); } function trimRight (string) { - return string == null ? "" : string.toString().replace(/\s+$/, ""); + return string == null ? '' : string.toString().replace(/\s+$/, ''); } - function parseDate(s) { + function parseDateUTC (s) { defaults.date.pattern.lastIndex = 0; var match = defaults.date.pattern.exec(s); @@ -1889,35 +1864,34 @@ return false; var y = +match[defaults.date.match_y]; - if(y < 0 || y > 8099) return false; - var m = match[defaults.date.match_m]*1; - var d = match[defaults.date.match_d]*1; - if(isNaN(d)) return false; + if (y < 0 || y > 8099) return false; + var m = match[defaults.date.match_m] * 1; + var d = match[defaults.date.match_d] * 1; + if (isNaN(d)) return false; - var o = new Date(y, m - 1, d); + var o = new Date(y, m - 1, d, 0, 0, 0); if (o.getFullYear() === y && o.getMonth() === (m - 1) && o.getDate() === d) - return o; + return new Date(Date.UTC(y, m - 1, d, 0, 0, 0)); else return false; } function parseNumber (value) { - value = value || "0"; + value = value || '0'; if ('' !== defaults.numbers.html.thousandsSeparator) value = replaceAll(value, defaults.numbers.html.thousandsSeparator, ''); if ('.' !== defaults.numbers.html.decimalMark) value = replaceAll(value, defaults.numbers.html.decimalMark, '.'); - return typeof value === "number" || jQuery.isNumeric(value) !== false ? value : false; + return typeof value === 'number' || jQuery.isNumeric(value) !== false ? value : false; } function parsePercent (value) { - if ( value.indexOf("%") > -1 ) { - value = parseNumber(value.replace(/%/g, "")); - if ( value !== false ) + if (value.indexOf('%') > -1) { + value = parseNumber(value.replace(/%/g, '')); + if (value !== false) value = value / 100; - } - else + } else value = false; return value; } @@ -1926,49 +1900,47 @@ var result = ''; var cellType = 'text'; - if ( cell !== null ) { + if (cell !== null) { var $cell = $(cell); var htmlData; - if ( $cell[0].hasAttribute("data-tableexport-canvas") ) { + if ($cell[0].hasAttribute('data-tableexport-canvas')) { htmlData = ''; - } - else if ( $cell[0].hasAttribute("data-tableexport-value") ) { - htmlData = $cell.attr("data-tableexport-value"); + } else if ($cell[0].hasAttribute('data-tableexport-value')) { + htmlData = $cell.attr('data-tableexport-value'); htmlData = htmlData ? htmlData + '' : ''; - } - else { + } else { htmlData = $cell.html(); - if ( typeof defaults.onCellHtmlData === 'function' ) + if (typeof defaults.onCellHtmlData === 'function') htmlData = defaults.onCellHtmlData($cell, rowIndex, colIndex, htmlData); - else if ( htmlData !== '' ) { - var html = $.parseHTML(htmlData); - var inputidx = 0; + else if (htmlData !== '') { + var html = $.parseHTML(htmlData); + var inputidx = 0; var selectidx = 0; htmlData = ''; $.each(html, function () { - if ( $(this).is("input") ) + if ($(this).is('input')) htmlData += $cell.find('input').eq(inputidx++).val(); - else if ( $(this).is("select") ) + else if ($(this).is('select')) htmlData += $cell.find('select option:selected').eq(selectidx++).text(); - else if ( $(this).is("br") ) - htmlData += "
"; + else if ($(this).is('br')) + htmlData += '
'; else { - if ( typeof $(this).html() === 'undefined' ) + if (typeof $(this).html() === 'undefined') htmlData += $(this).text(); - else if ( jQuery().bootstrapTable === undefined || + else if (jQuery().bootstrapTable === undefined || ($(this).hasClass('fht-cell') === false && // BT 4 - $(this).hasClass('filterControl') === false && - $cell.parents('.detail-view').length === 0) ) + $(this).hasClass('filterControl') === false && + $cell.parents('.detail-view').length === 0)) htmlData += $(this).html(); - if ( $(this).is("a") ) { + if ($(this).is('a')) { var href = $cell.find('a').attr('href') || ''; - if ( typeof defaults.onCellHtmlHyperlink === 'function' ) + if (typeof defaults.onCellHtmlHyperlink === 'function') result += defaults.onCellHtmlHyperlink($cell, rowIndex, colIndex, href, htmlData); - else if ( defaults.htmlHyperlink === 'href' ) + else if (defaults.htmlHyperlink === 'href') result += href; else // 'content' result += htmlData; @@ -1979,77 +1951,74 @@ } } - if ( htmlData && htmlData !== '' && defaults.htmlContent === true ) { + if (htmlData && htmlData !== '' && defaults.htmlContent === true) { result = $.trim(htmlData); - } - else if ( htmlData && htmlData !== '' ) { - var cellFormat = $cell.attr("data-tableexport-cellformat"); + } else if (htmlData && htmlData !== '') { + var cellFormat = $cell.attr('data-tableexport-cellformat'); - if ( cellFormat !== '' ) { - var text = htmlData.replace(/\n/g, '\u2028').replace(/(<\s*br([^>]*)>)/gi, '\u2060'); - var obj = $('
').html(text).contents(); + if (cellFormat !== '') { + var text = htmlData.replace(/\n/g, '\u2028').replace(/(<\s*br([^>]*)>)/gi, '\u2060'); + var obj = $('
').html(text).contents(); var number = false; - text = ''; + text = ''; - $.each(obj.text().split("\u2028"), function (i, v) { - if ( i > 0 ) - text += " "; + $.each(obj.text().split('\u2028'), function (i, v) { + if (i > 0) + text += ' '; if (defaults.preserve.leadingWS !== true) v = trimLeft(v); text += (defaults.preserve.trailingWS !== true) ? trimRight(v) : v; }); - $.each(text.split("\u2060"), function (i, v) { - if ( i > 0 ) - result += "\n"; + $.each(text.split('\u2060'), function (i, v) { + if (i > 0) + result += '\n'; if (defaults.preserve.leadingWS !== true) v = trimLeft(v); if (defaults.preserve.trailingWS !== true) v = trimRight(v); - result += v.replace(/\u00AD/g, ""); // remove soft hyphens + result += v.replace(/\u00AD/g, ''); // remove soft hyphens }); - result = result.replace(/\u00A0/g, " "); // replace nbsp's with spaces + result = result.replace(/\u00A0/g, ' '); // replace nbsp's with spaces - if ( defaults.type === 'json' || + if (defaults.type === 'json' || (defaults.type === 'excel' && defaults.mso.fileFormat === 'xmlss') || - defaults.numbers.output === false ) { + defaults.numbers.output === false) { number = parseNumber(result); - if ( number !== false ) { + if (number !== false) { cellType = 'number'; result = Number(number); } - } - else if ( defaults.numbers.html.decimalMark !== defaults.numbers.output.decimalMark || - defaults.numbers.html.thousandsSeparator !== defaults.numbers.output.thousandsSeparator ) { + } else if (defaults.numbers.html.decimalMark !== defaults.numbers.output.decimalMark || + defaults.numbers.html.thousandsSeparator !== defaults.numbers.output.thousandsSeparator) { number = parseNumber(result); - if ( number !== false ) { - var frac = ("" + number.substr(number < 0 ? 1 : 0)).split('.'); - if ( frac.length === 1 ) - frac[1] = ""; + if (number !== false) { + var frac = ('' + number.substr(number < 0 ? 1 : 0)).split('.'); + if (frac.length === 1) + frac[1] = ''; var mod = frac[0].length > 3 ? frac[0].length % 3 : 0; cellType = 'number'; - result = (number < 0 ? "-" : "") + - (defaults.numbers.output.thousandsSeparator ? ((mod ? frac[0].substr(0, mod) + defaults.numbers.output.thousandsSeparator : "") + frac[0].substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + defaults.numbers.output.thousandsSeparator)) : frac[0]) + - (frac[1].length ? defaults.numbers.output.decimalMark + frac[1] : ""); + result = (number < 0 ? '-' : '') + + (defaults.numbers.output.thousandsSeparator ? ((mod ? frac[0].substr(0, mod) + defaults.numbers.output.thousandsSeparator : '') + frac[0].substr(mod).replace(/(\d{3})(?=\d)/g, '$1' + defaults.numbers.output.thousandsSeparator)) : frac[0]) + + (frac[1].length ? defaults.numbers.output.decimalMark + frac[1] : ''); } } - } - else + } else result = htmlData; } - if ( defaults.escape === true ) { + if (defaults.escape === true) { //noinspection JSDeprecatedSymbols result = escape(result); } - if ( typeof defaults.onCellData === 'function' ) { + if (typeof defaults.onCellData === 'function') { result = defaults.onCellData($cell, rowIndex, colIndex, result, cellType); } } @@ -2061,57 +2030,57 @@ } function preventInjection (str) { - if ( str.length > 0 && defaults.preventInjection === true ) { - var chars = "=+-@"; - if ( chars.indexOf(str.charAt(0)) >= 0 ) - return ( "'" + str ); + if (str.length > 0 && defaults.preventInjection === true) { + var chars = '=+-@'; + if (chars.indexOf(str.charAt(0)) >= 0) + return ('\'' + str); } return str; } //noinspection JSUnusedLocalSymbols function hyphenate (a, b, c) { - return b + "-" + c.toLowerCase(); + return b + '-' + c.toLowerCase(); } function rgb2array (rgb_string, default_result) { - var re = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/; - var bits = re.exec(rgb_string); + var re = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/; + var bits = re.exec(rgb_string); var result = default_result; - if ( bits ) + if (bits) result = [parseInt(bits[1]), parseInt(bits[2]), parseInt(bits[3])]; return result; } function getCellStyles (cell) { - var a = getStyle(cell, 'text-align'); + var a = getStyle(cell, 'text-align'); var fw = getStyle(cell, 'font-weight'); var fs = getStyle(cell, 'font-style'); - var f = ''; - if ( a === 'start' ) + var f = ''; + if (a === 'start') a = getStyle(cell, 'direction') === 'rtl' ? 'right' : 'left'; - if ( fw >= 700 ) + if (fw >= 700) f = 'bold'; - if ( fs === 'italic' ) + if (fs === 'italic') f += fs; - if ( f === '' ) + if (f === '') f = 'normal'; var result = { - style: { - align: a, + style: { + align: a, bcolor: rgb2array(getStyle(cell, 'background-color'), [255, 255, 255]), - color: rgb2array(getStyle(cell, 'color'), [0, 0, 0]), + color: rgb2array(getStyle(cell, 'color'), [0, 0, 0]), fstyle: f }, - colspan: getColspan (cell), - rowspan: getRowspan (cell) + colspan: getColspan(cell), + rowspan: getRowspan(cell) }; - if ( cell !== null ) { - var r = cell.getBoundingClientRect(); + if (cell !== null) { + var r = cell.getBoundingClientRect(); result.rect = { - width: r.width, + width: r.width, height: r.height }; } @@ -2120,16 +2089,16 @@ } function getColspan (cell) { - var result = $(cell).attr("data-tableexport-colspan"); - if ( typeof result === 'undefined' && $(cell).is("[colspan]") ) + var result = $(cell).attr('data-tableexport-colspan'); + if (typeof result === 'undefined' && $(cell).is('[colspan]')) result = $(cell).attr('colspan'); return (parseInt(result) || 0); } function getRowspan (cell) { - var result = $(cell).attr("data-tableexport-rowspan"); - if ( typeof result === 'undefined' && $(cell).is("[rowspan]") ) + var result = $(cell).attr('data-tableexport-rowspan'); + if (typeof result === 'undefined' && $(cell).is('[rowspan]')) result = $(cell).attr('rowspan'); return (parseInt(result) || 0); @@ -2138,31 +2107,30 @@ // get computed style property function getStyle (target, prop) { try { - if ( window.getComputedStyle ) { // gecko and webkit + if (window.getComputedStyle) { // gecko and webkit prop = prop.replace(/([a-z])([A-Z])/, hyphenate); // requires hyphenated, not camel return window.getComputedStyle(target, null).getPropertyValue(prop); } - if ( target.currentStyle ) { // ie + if (target.currentStyle) { // ie return target.currentStyle[prop]; } return target.style[prop]; + } catch (e) { } - catch (e) { - } - return ""; + return ''; } function getUnitValue (parent, value, unit) { var baseline = 100; // any number serves - var temp = document.createElement("div"); // create temporary element - temp.style.overflow = "hidden"; // in case baseline is set too low - temp.style.visibility = "hidden"; // no need to show it + var temp = document.createElement('div'); // create temporary element + temp.style.overflow = 'hidden'; // in case baseline is set too low + temp.style.visibility = 'hidden'; // no need to show it parent.appendChild(temp); // insert it into the parent for em, ex and % temp.style.width = baseline + unit; - var factor = baseline / temp.offsetWidth; + var factor = baseline / temp.offsetWidth; parent.removeChild(temp); // clean up @@ -2173,7 +2141,7 @@ var value = getStyle(target, prop); // get the computed style value var numeric = value.match(/\d+/); // get the numeric component - if ( numeric !== null ) { + if (numeric !== null) { numeric = numeric[0]; // get the string return getUnitValue(target.parentElement, numeric, unit); @@ -2182,24 +2150,24 @@ } function xlsxWorkbookToArrayBuffer (s) { - var buf = new ArrayBuffer(s.length); + 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; + for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF; return buf; } - function xlsxTableToSheet(table) { + function xlsxTableToSheet (table) { var ws = ({}); var rows = table.getElementsByTagName('tr'); var sheetRows = 10000000; - var range = {s:{r:0,c:0},e:{r:0,c:0}}; + var range = {s: {r: 0, c: 0}, e: {r: 0, c: 0}}; var merges = [], midx = 0; var rowinfo = []; var _R = 0, R = 0, _C, C, RS, CS; var elt; var ssfTable = XLSX.SSF.get_table(); - for(; _R < rows.length && R < sheetRows; ++_R) { + for (; _R < rows.length && R < sheetRows; ++_R) { var row = rows[_R]; var ignoreRow = false; @@ -2207,155 +2175,166 @@ ignoreRow = defaults.onIgnoreRow($(row), _R); if (!(ignoreRow === false && - $.inArray(rowIndex, defaults.ignoreRow) === -1 && - $.inArray(rowIndex - rowCount, defaults.ignoreRow) === -1 && - isVisible($(row)))) { + $.inArray(rowIndex, defaults.ignoreRow) === -1 && + $.inArray(rowIndex - rowCount, defaults.ignoreRow) === -1 && + isVisible($(row)))) { continue; } var elts = (row.children); var _CLength = 0; - for(_C = 0; _C < elts.length; ++_C) { + for (_C = 0; _C < elts.length; ++_C) { elt = elts[_C]; CS = +getColspan(elt) || 1; _CLength += CS; } var CSOffset = 0; - for(_C = C = 0; _C < elts.length; ++_C) { + for (_C = C = 0; _C < elts.length; ++_C) { elt = elts[_C]; CS = +getColspan(elt) || 1; var col = _C + CSOffset; - if (isColumnIgnored($(elt), _CLength, col + (col < C ? C-col : 0))) + if (isColumnIgnored($(elt), _CLength, col + (col < C ? C - col : 0))) continue; - CSOffset += CS-1; + CSOffset += CS - 1; - for(midx = 0; midx < merges.length; ++midx) { + for (midx = 0; midx < merges.length; ++midx) { var m = merges[midx]; - if(m.s.c == C && m.s.r <= R && R <= m.e.r) { - C = m.e.c+1; + if (m.s.c == C && m.s.r <= R && R <= m.e.r) { + C = m.e.c + 1; midx = -1; } } - if((RS = +getRowspan(elt))>0 || CS>1) - merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}}); + if ((RS = +getRowspan(elt)) > 0 || CS > 1) + merges.push({s: {r: R, c: C}, e: {r: R + (RS || 1) - 1, c: C + CS - 1}}); - var cellInfo = { type: '' }; - var v = parseString(elt,_R,_C + CSOffset, cellInfo); - var o = {t:'s', v:v}; + var cellInfo = {type: ''}; + var v = parseString(elt, _R, _C + CSOffset, cellInfo); + var o = {t: 's', v: v}; var _t = ''; - var cellFormat = $(elt).attr("data-tableexport-cellformat"); + var cellFormat = $(elt).attr('data-tableexport-cellformat'); - if (cellFormat !== '') - { - var ssfId = parseInt($(elt).attr("data-tableexport-xlsxformatid") || 0); + if (cellFormat !== '') { + var ssfId = parseInt($(elt).attr('data-tableexport-xlsxformatid') || 0); if (ssfId === 0 && - typeof defaults.mso.xslx.formatId.numbers === 'function') - ssfId = defaults.mso.xslx.formatId.numbers($(elt),_R,_C + CSOffset); + typeof defaults.mso.xslx.formatId.numbers === 'function') + ssfId = defaults.mso.xslx.formatId.numbers($(elt), _R, _C + CSOffset); if (ssfId === 0 && - typeof defaults.mso.xslx.formatId.date === 'function') - ssfId = defaults.mso.xslx.formatId.date($(elt),_R,_C + CSOffset); + typeof defaults.mso.xslx.formatId.date === 'function') + ssfId = defaults.mso.xslx.formatId.date($(elt), _R, _C + CSOffset); if (ssfId === 49 || ssfId === '@') _t = 's'; else if (cellInfo.type === 'number' || - (ssfId > 0 && ssfId < 14) || (ssfId > 36 && ssfId < 41) || ssfId === 48) + (ssfId > 0 && ssfId < 14) || (ssfId > 36 && ssfId < 41) || ssfId === 48) _t = 'n'; else if (cellInfo.type === 'date' || - (ssfId > 13 && ssfId < 37) || (ssfId > 44 && ssfId < 48) || ssfId === 56) + (ssfId > 13 && ssfId < 37) || (ssfId > 44 && ssfId < 48) || ssfId === 56) _t = 'd'; - } - else + } else _t = 's'; - if(v != null) { - if(v.length === 0) + if (v != null) { + var vd; + + if (v.length === 0) o.t = _t || 'z'; - else if(v.trim().length === 0 || _t === 's') { - } - else if (cellInfo.type === 'function') + else if (v.trim().length === 0 || _t === 's') { + } else if (cellInfo.type === 'function') o = {f: v}; - else if(v === 'TRUE') - o = {t:'b', v:true}; - else if(v === 'FALSE') - o = {t:'b', v:false}; - else if(_t === '' && $(elt).find('a').length) { + else if (v === 'TRUE') + o = {t: 'b', v: true}; + else if (v === 'FALSE') + o = {t: 'b', v: false}; + else if (_t === '' && $(elt).find('a').length) { v = defaults.htmlHyperlink !== 'href' ? v : ''; o = {f: '=HYPERLINK("' + $(elt).find('a').attr('href') + (v.length ? '","' + v : '') + '")'}; - } - else if(_t === 'n' || !isNaN(xlsxToNumber(v, defaults.numbers.output))) { // yes, defaults.numbers.output is right + } else if (_t === 'n' || !isNaN(xlsxToNumber(v, defaults.numbers.output))) { // yes, defaults.numbers.output is right var vn = xlsxToNumber(v, defaults.numbers.output); if (ssfId === 0 && typeof defaults.mso.xslx.formatId.numbers !== 'function') ssfId = defaults.mso.xslx.formatId.numbers; if (!isNaN(vn) || !isNaN(v)) - o = {t:'n', - v:(!isNaN(vn) ? vn : v), - z:(typeof ssfId === 'string') ? ssfId : (ssfId in ssfTable ? ssfTable[ssfId] : '0.00') - }; - } - else if(_t === 'd' || parseDate(v) !== false) { - var vd = parseDate(v); + o = { + t: 'n', + v: (!isNaN(vn) ? vn : v), + z: (typeof ssfId === 'string') ? ssfId : (ssfId in ssfTable ? ssfTable[ssfId] : '0.00') + }; + } else if ((vd = parseDateUTC(v)) !== false || _t === 'd') { if (ssfId === 0 && typeof defaults.mso.xslx.formatId.date !== 'function') ssfId = defaults.mso.xslx.formatId.date; - o = {t:'d', - v:(vd !== false ? vd : v), - z:(typeof ssfId === 'string') ? ssfId : (ssfId in ssfTable ? ssfTable[ssfId] : 'm/d/yy') - }; + o = { + t: 'd', + v: (vd !== false ? vd : v), + z: (typeof ssfId === 'string') ? ssfId : (ssfId in ssfTable ? ssfTable[ssfId] : 'm/d/yy') + }; } } - ws[xlsxEncodeCell({c:C, r:R})] = o; - if(range.e.c < C) + ws[xlsxEncodeCell({c: C, r: R})] = o; + if (range.e.c < C) range.e.c = C; C += CS; } ++R; } - if(merges.length) ws['!merges'] = merges; - if(rowinfo.length) ws['!rows'] = rowinfo; + if (merges.length) ws['!merges'] = merges; + if (rowinfo.length) ws['!rows'] = rowinfo; range.e.r = R - 1; ws['!ref'] = xlsxEncodeRange(range); - if(R >= sheetRows) - ws['!fullref'] = xlsxEncodeRange((range.e.r = rows.length-_R+R-1,range)); + if (R >= sheetRows) + ws['!fullref'] = xlsxEncodeRange((range.e.r = rows.length - _R + R - 1, range)); return ws; } - function xlsxEncodeRow(row) { return "" + (row + 1); } - function xlsxEncodeCol(col) { var s=""; for(++col; col; col=Math.floor((col-1)/26)) s = String.fromCharCode(((col-1)%26) + 65) + s; return s; } - function xlsxEncodeCell(cell) { return xlsxEncodeCol(cell.c) + xlsxEncodeRow(cell.r); } - function xlsxEncodeRange(cs,ce) { - if(typeof ce === 'undefined' || typeof ce === 'number') { + function xlsxEncodeRow (row) { return '' + (row + 1); } + + function xlsxEncodeCol (col) { + var s = ''; + for (++col; col; col = Math.floor((col - 1) / 26)) s = String.fromCharCode(((col - 1) % 26) + 65) + s; + return s; + } + + function xlsxEncodeCell (cell) { return xlsxEncodeCol(cell.c) + xlsxEncodeRow(cell.r); } + + function xlsxEncodeRange (cs, ce) { + if (typeof ce === 'undefined' || typeof ce === 'number') { return xlsxEncodeRange(cs.s, cs.e); } - if(typeof cs !== 'string') cs = xlsxEncodeCell((cs)); - if(typeof ce !== 'string') ce = xlsxEncodeCell((ce)); - return cs === ce ? cs : cs + ":" + ce; + if (typeof cs !== 'string') cs = xlsxEncodeCell((cs)); + if (typeof ce !== 'string') ce = xlsxEncodeCell((ce)); + return cs === ce ? cs : cs + ':' + ce; } - function xlsxToNumber(s, numbersFormat) { + function xlsxToNumber (s, numbersFormat) { var v = Number(s); - if(!isNaN(v)) return v; + if (!isNaN(v)) return v; var wt = 1; var ss = s; if ('' !== numbersFormat.thousandsSeparator) - ss = ss.replace(new RegExp('([\\d])' + numbersFormat.thousandsSeparator + '([\\d])','g'),"$1$2"); + ss = ss.replace(new RegExp('([\\d])' + numbersFormat.thousandsSeparator + '([\\d])', 'g'), '$1$2'); if ('.' !== numbersFormat.decimalMark) - ss = ss.replace(new RegExp('([\\d])' + numbersFormat.decimalMark + '([\\d])','g'),"$1.$2"); - ss = ss.replace(/[$]/g,"").replace(/[%]/g, function() { wt *= 100; return "";}); - if(!isNaN(v = Number(ss))) return v / wt; - ss = ss.replace(/[(](.*)[)]/,function($$, $1) { wt = -wt; return $1;}); - if(!isNaN(v = Number(ss))) return v / wt; + ss = ss.replace(new RegExp('([\\d])' + numbersFormat.decimalMark + '([\\d])', 'g'), '$1.$2'); + ss = ss.replace(/[$]/g, '').replace(/[%]/g, function () { + wt *= 100; + return ''; + }); + if (!isNaN(v = Number(ss))) return v / wt; + ss = ss.replace(/[(](.*)[)]/, function ($$, $1) { + wt = -wt; + return $1; + }); + if (!isNaN(v = Number(ss))) return v / wt; return v; } function strHashCode (str) { var hash = 0, i, chr, len; - if ( str.length === 0 ) return hash; - for ( i = 0, len = str.length; i < len; i++ ) { - chr = str.charCodeAt(i); + if (str.length === 0) return hash; + for (i = 0, len = str.length; i < len; i++) { + chr = str.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } @@ -2364,104 +2343,104 @@ function saveToFile (data, fileName, type, charset, encoding, bom) { var saveIt = true; - if ( typeof defaults.onBeforeSaveToFile === 'function' ) { + if (typeof defaults.onBeforeSaveToFile === 'function') { saveIt = defaults.onBeforeSaveToFile(data, fileName, type, charset, encoding); - if ( typeof saveIt !== 'boolean' ) + if (typeof saveIt !== 'boolean') saveIt = true; } if (saveIt) { try { blob = new Blob([data], {type: type + ';charset=' + charset}); - saveAs (blob, fileName, bom === false); + saveAs(blob, fileName, bom === false); - if ( typeof defaults.onAfterSaveToFile === 'function' ) + if (typeof defaults.onAfterSaveToFile === 'function') defaults.onAfterSaveToFile(data, fileName); - } - catch (e) { - downloadFile (fileName, - 'data:' + type + - (charset.length ? ';charset=' + charset : '') + - (encoding.length ? ';' + encoding : '') + ',', - (bom ? ('\ufeff' + data) : data)); + } catch (e) { + downloadFile(fileName, + 'data:' + type + + (charset.length ? ';charset=' + charset : '') + + (encoding.length ? ';' + encoding : '') + ',', + (bom ? ('\ufeff' + data) : data)); } } } function downloadFile (filename, header, data) { var ua = window.navigator.userAgent; - if ( filename !== false && window.navigator.msSaveOrOpenBlob ) { + if (filename !== false && window.navigator.msSaveOrOpenBlob) { //noinspection JSUnresolvedFunction window.navigator.msSaveOrOpenBlob(new Blob([data]), filename); - } - else if ( filename !== false && (ua.indexOf("MSIE ") > 0 || !!ua.match(/Trident.*rv\:11\./)) ) { + } else if (filename !== false && (ua.indexOf('MSIE ') > 0 || !!ua.match(/Trident.*rv\:11\./))) { // Internet Explorer (<= 9) workaround by Darryl (https://github.com/dawiong/tableExport.jquery.plugin) // based on sampopes answer on http://stackoverflow.com/questions/22317951 // ! Not working for json and pdf format ! - var frame = document.createElement("iframe"); + var frame = document.createElement('iframe'); - if ( frame ) { + if (frame) { document.body.appendChild(frame); - frame.setAttribute("style", "display:none"); - frame.contentDocument.open("txt/plain", "replace"); + frame.setAttribute('style', 'display:none'); + frame.contentDocument.open('txt/plain', 'replace'); frame.contentDocument.write(data); frame.contentDocument.close(); frame.contentWindow.focus(); - var extension = filename.substr((filename.lastIndexOf('.') +1)); - switch(extension) { - case 'doc': case 'json': case 'png': case 'pdf': case 'xls': case 'xlsx': - filename += ".txt"; - break; + var extension = filename.substr((filename.lastIndexOf('.') + 1)); + switch (extension) { + case 'doc': + case 'json': + case 'png': + case 'pdf': + case 'xls': + case 'xlsx': + filename += '.txt'; + break; } - frame.contentDocument.execCommand("SaveAs", true, filename); + frame.contentDocument.execCommand('SaveAs', true, filename); document.body.removeChild(frame); } - } - else { + } else { var DownloadLink = document.createElement('a'); - if ( DownloadLink ) { + if (DownloadLink) { var blobUrl = null; DownloadLink.style.display = 'none'; - if ( filename !== false ) + if (filename !== false) DownloadLink.download = filename; else DownloadLink.target = '_blank'; - if ( typeof data === 'object' ) { + if (typeof data === 'object') { window.URL = window.URL || window.webkitURL; var binaryData = []; binaryData.push(data); blobUrl = window.URL.createObjectURL(new Blob(binaryData, {type: header})); DownloadLink.href = blobUrl; - } - else if ( header.toLowerCase().indexOf("base64,") >= 0 ) + } else if (header.toLowerCase().indexOf('base64,') >= 0) DownloadLink.href = header + base64encode(data); else DownloadLink.href = header + encodeURIComponent(data); document.body.appendChild(DownloadLink); - if ( document.createEvent ) { - if ( DownloadEvt === null ) + if (document.createEvent) { + if (DownloadEvt === null) DownloadEvt = document.createEvent('MouseEvents'); DownloadEvt.initEvent('click', true, false); DownloadLink.dispatchEvent(DownloadEvt); - } - else if ( document.createEventObject ) + } else if (document.createEventObject) DownloadLink.fireEvent('onclick'); - else if ( typeof DownloadLink.onclick === 'function' ) + else if (typeof DownloadLink.onclick === 'function') DownloadLink.onclick(); - setTimeout(function(){ - if ( blobUrl ) + setTimeout(function () { + if (blobUrl) window.URL.revokeObjectURL(blobUrl); document.body.removeChild(DownloadLink); - if ( typeof defaults.onAfterSaveToFile === 'function' ) + if (typeof defaults.onAfterSaveToFile === 'function') defaults.onAfterSaveToFile(data, filename); }, 100); } @@ -2470,18 +2449,16 @@ function utf8Encode (text) { if (typeof text === 'string') { - text = text.replace(/\x0d\x0a/g, "\x0a"); - var utftext = ""; - for ( var n = 0; n < text.length; n++ ) { + text = text.replace(/\x0d\x0a/g, '\x0a'); + var utftext = ''; + for (var n = 0; n < text.length; n++) { var c = text.charCodeAt(n); - if ( c < 128 ) { + if (c < 128) { utftext += String.fromCharCode(c); - } - else if ( (c > 127) && (c < 2048) ) { + } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); - } - else { + } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); @@ -2494,11 +2471,11 @@ function base64encode (input) { var chr1, chr2, chr3, enc1, enc2, enc3, enc4; - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - var output = ""; - var i = 0; - input = utf8Encode(input); - while ( i < input.length ) { + var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + var output = ''; + var i = 0; + input = utf8Encode(input); + while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); @@ -2506,9 +2483,9 @@ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; - if ( isNaN(chr2) ) { + if (isNaN(chr2)) { enc3 = enc4 = 64; - } else if ( isNaN(chr3) ) { + } else if (isNaN(chr3)) { enc4 = 64; } output = output + @@ -2519,5 +2496,5 @@ } return this; - } + }; })(jQuery); diff --git a/tableExport.min.js b/tableExport.min.js index 307f046..c110d7c 100644 --- a/tableExport.min.js +++ b/tableExport.min.js @@ -1,90 +1,90 @@ /* tableExport.jquery.plugin - Version 1.10.14 + Version 1.10.15 - Copyright (c) 2015-2019 hhurz, https://github.com/hhurz/tableExport.jquery.plugin + Copyright (c) 2015-2020 hhurz, https://github.com/hhurz/tableExport.jquery.plugin Based on https://github.com/kayalshri/tableExport.jquery.plugin Licensed under the MIT License */ -var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(c,h,y){c instanceof String&&(c=String(c));for(var B=c.length,C=0;Ce&&"undefined"!==typeof T[e]&&-1!==c.inArray(T[e],a.ignoreColumn))&&(q=!0):q=!0;return q}function E(b,d,e,q,f){if("function"===typeof f){var m=!1;"function"===typeof a.onIgnoreRow&&(m=a.onIgnoreRow(c(b),e));if(!1===m&&(0===a.ignoreRow.length||-1===c.inArray(e,a.ignoreRow)&&-1===c.inArray(e-q,a.ignoreRow))&&I(c(b))){var t=C(c(b),d),k=0;t.each(function(b){var a=c(this),d,m=O(this),q=U(this);c.each(G, -function(){if(e>=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(d=0;d<=this.e.c-this.s.c;++d)f(null,e,k++)});if(!1===ta(a,t.length,b)){if(q||m)m=m||1,G.push({s:{r:e,c:k},e:{r:e+(q||1)-1,c:k+m-1}});f(this,e,k++)}if(m)for(d=0;d=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(da=0;da<=this.e.c-this.s.c;++da)f(null,e,k++)})}}}function ua(b,a,e,c){if("undefined"!==typeof c.images&&(e=c.images[e],"undefined"!==typeof e)){a=a.getBoundingClientRect(); -var d=b.width/b.height,m=a.width/a.height,q=b.width,k=b.height,z=19.049976/25.4,g=0;m<=d?(k=Math.min(b.height,a.height),q=a.width*k/a.height):m>d&&(q=Math.min(b.width,a.width),k=a.height*q/a.width);q*=z;k*=z;ke&&"undefined"!==typeof T[e]&&-1!==d.inArray(T[e],a.ignoreColumn))&&(q=!0):q=!0;return q}function E(b,c,e,q,f){if("function"===typeof f){var m=!1;"function"===typeof a.onIgnoreRow&&(m=a.onIgnoreRow(d(b),e));if(!1===m&&(0===a.ignoreRow.length||-1===d.inArray(e,a.ignoreRow)&&-1===d.inArray(e-q,a.ignoreRow))&&I(d(b))){var t=C(d(b),c),k=0;t.each(function(b){var a=d(this),c,m=O(this),q=U(this);d.each(G, +function(){if(e>=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(c=0;c<=this.e.c-this.s.c;++c)f(null,e,k++)});if(!1===ta(a,t.length,b)){if(q||m)m=m||1,G.push({s:{r:e,c:k},e:{r:e+(q||1)-1,c:k+m-1}});f(this,e,k++)}if(m)for(c=0;c=this.s.r&&e<=this.e.r&&k>=this.s.c&&k<=this.e.c)for(da=0;da<=this.e.c-this.s.c;++da)f(null,e,k++)})}}}function ua(b,a,e,d){if("undefined"!==typeof d.images&&(e=d.images[e],"undefined"!==typeof e)){a=a.getBoundingClientRect(); +var c=b.width/b.height,m=a.width/a.height,q=b.width,k=b.height,z=19.049976/25.4,g=0;m<=c?(k=Math.min(b.height,a.height),q=a.width*k/a.height):m>c&&(q=Math.min(b.width,a.width),k=a.height*q/a.width);q*=z;k*=z;kb.textPos.x&&q+g>b.textPos.x+b.width&&(0<=".,!%*;:=-".indexOf(z.charAt(0))&&(h=z.charAt(0),g=e.doc.getStringUnitWidth(h)*e.doc.internal.getFontSize(),q+g<=b.textPos.x+b.width&&(e.doc.autoTableText(h,q,f,m),z=z.substring(1,z.length)),g=e.doc.getStringUnitWidth(z)*e.doc.internal.getFontSize()),q=b.textPos.x,f+=e.doc.internal.getFontSize());if("visible"!==b.styles.overflow)for(;z.length&&q+g>b.textPos.x+b.width;)z=z.substring(0,z.length-1),g=e.doc.getStringUnitWidth(z)*e.doc.internal.getFontSize(); -e.doc.autoTableText(z,q,f,m);q+=g}if(t||k)c(d).is("b")?t=!1:c(d).is("i")&&(k=!1),e.doc.setFontType(t||k?t?"bold":"italic":"normal");d=d.nextSibling}b.textPos.x=q;b.textPos.y=f}else e.doc.autoTableText(b.text,b.textPos.x,b.textPos.y,m)}}function W(b,a,e){return null==b?"":b.toString().replace(new RegExp(null==a?"":a.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),e)}function ka(b){return null==b?"":b.toString().replace(/^\s+/,"")}function la(b){return null==b?"":b.toString().replace(/\s+$/, -"")}function Ba(b){a.date.pattern.lastIndex=0;var d=a.date.pattern.exec(b);if(null==d)return!1;b=+d[a.date.match_y];if(0>b||8099]*)>)/gi,"\u2060"),p=c("
").html(l).contents();b=!1;l="";c.each(p.text().split("\u2028"),function(b,d){0b?1:0)).split(".");1===p.length&&(p[1]="");var n=3b?"-":"")+ -(a.numbers.output.thousandsSeparator?(n?p[0].substr(0,n)+a.numbers.output.thousandsSeparator:"")+p[0].substr(n).replace(/(\d{3})(?=\d)/g,"$1"+a.numbers.output.thousandsSeparator):p[0])+(p[1].length?a.numbers.output.decimalMark+p[1]:"")}}else f=k;!0===a.escape&&(f=escape(f));"function"===typeof a.onCellData&&(f=a.onCellData(t,d,e,f,m))}void 0!==q&&(q.type=m);return f}function Ca(b){return 0m?f+=String.fromCharCode(m):(127m?f+=String.fromCharCode(m>>6|192):(f+=String.fromCharCode(m>>12|224),f+=String.fromCharCode(m>>6&63|128)),f+=String.fromCharCode(m&63|128))}a=f}for(;q>2;t=(t&3)<<4|f>>4;var k=(f&15)<<2|b>>6;var g=b&63;isNaN(f)?k=g=64:isNaN(b)&& -(g=64);c=c+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(m)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(t)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(k)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)}return c}var a={csvEnclosure:'"',csvSeparator:",",csvUseBOM:!0,date:{html:"dd/mm/yyyy"},displayTableName:!1,escape:!1,exportHiddenCells:!1,fileName:"tableExport",htmlContent:!1,htmlHyperlink:"content", +e.doc.autoTableText(z,q,f,m);q+=g}if(t||k)d(c).is("b")?t=!1:d(c).is("i")&&(k=!1),e.doc.setFontType(t||k?t?"bold":"italic":"normal");c=c.nextSibling}b.textPos.x=q;b.textPos.y=f}else e.doc.autoTableText(b.text,b.textPos.x,b.textPos.y,m)}}function W(b,a,e){return null==b?"":b.toString().replace(new RegExp(null==a?"":a.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g,"\\$1"),"g"),e)}function ka(b){return null==b?"":b.toString().replace(/^\s+/,"")}function la(b){return null==b?"":b.toString().replace(/\s+$/, +"")}function La(b){a.date.pattern.lastIndex=0;var c=a.date.pattern.exec(b);if(null==c)return!1;b=+c[a.date.match_y];if(0>b||8099]*)>)/gi,"\u2060"),p=d("
").html(l).contents();b=!1;l="";d.each(p.text().split("\u2028"),function(b,c){0b?1:0)).split(".");1===p.length&&(p[1]="");var n=3 +b?"-":"")+(a.numbers.output.thousandsSeparator?(n?p[0].substr(0,n)+a.numbers.output.thousandsSeparator:"")+p[0].substr(n).replace(/(\d{3})(?=\d)/g,"$1"+a.numbers.output.thousandsSeparator):p[0])+(p[1].length?a.numbers.output.decimalMark+p[1]:"")}}else f=k;!0===a.escape&&(f=escape(f));"function"===typeof a.onCellData&&(f=a.onCellData(t,c,e,f,m))}void 0!==q&&(q.type=m);return f}function Ba(b){return 0m?f+=String.fromCharCode(m):(127m?f+=String.fromCharCode(m>>6|192):(f+=String.fromCharCode(m>>12|224),f+=String.fromCharCode(m>>6&63|128)),f+=String.fromCharCode(m&63|128))}a=f}for(;q>2;t=(t&3)<<4|f>>4;var k=(f&15)<<2|b>>6;var g=b&63;isNaN(f)?k=g=64:isNaN(b)&& +(g=64);d=d+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(m)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(t)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(k)+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".charAt(g)}return d}var a={csvEnclosure:'"',csvSeparator:",",csvUseBOM:!0,date:{html:"dd/mm/yyyy"},displayTableName:!1,escape:!1,exportHiddenCells:!1,fileName:"tableExport",htmlContent:!1,htmlHyperlink:"content", ignoreColumn:[],ignoreRow:[],jsonScope:"all",jspdf:{orientation:"p",unit:"pt",format:"a4",margins:{left:20,right:10,top:10,bottom:10},onDocCreated:null,autotable:{styles:{cellPadding:2,rowHeight:12,fontSize:8,fillColor:255,textColor:50,fontStyle:"normal",overflow:"ellipsize",halign:"inherit",valign:"middle"},headerStyles:{fillColor:[52,73,94],textColor:255,fontStyle:"bold",halign:"inherit",valign:"middle"},alternateRowStyles:{fillColor:245},tableExport:{doc:null,onAfterAutotable:null,onBeforeAutotable:null, onAutotableText:null,onTable:null,outputImages:!0}}},mso:{fileFormat:"xlshtml",onMsoNumberFormat:null,pageFormat:"a4",pageOrientation:"portrait",rtl:!1,styles:[],worksheetName:"",xslx:{formatId:{date:14,numbers:2}}},numbers:{html:{decimalMark:".",thousandsSeparator:","},output:{decimalMark:".",thousandsSeparator:","}},onAfterSaveToFile:null,onBeforeSaveToFile:null,onCellData:null,onCellHtmlData:null,onCellHtmlHyperlink:null,onIgnoreRow:null,outputMode:"file",pdfmake:{enabled:!1,docDefinition:{pageOrientation:"portrait", defaultStyle:{font:"Roboto"}},fonts:{}},preserve:{leadingWS:!1,trailingWS:!1},preventInjection:!0,sql:{tableEnclosure:"`",columnEnclosure:"`"},tbodySelector:"tr",tfootSelector:"tr",theadSelector:"tr",tableName:"Table",type:"csv"},N={a0:[2383.94,3370.39],a1:[1683.78,2383.94],a2:[1190.55,1683.78],a3:[841.89,1190.55],a4:[595.28,841.89],a5:[419.53,595.28],a6:[297.64,419.53],a7:[209.76,297.64],a8:[147.4,209.76],a9:[104.88,147.4],a10:[73.7,104.88],b0:[2834.65,4008.19],b1:[2004.09,2834.65],b2:[1417.32,2004.09], b3:[1000.63,1417.32],b4:[708.66,1000.63],b5:[498.9,708.66],b6:[354.33,498.9],b7:[249.45,354.33],b8:[175.75,249.45],b9:[124.72,175.75],b10:[87.87,124.72],c0:[2599.37,3676.54],c1:[1836.85,2599.37],c2:[1298.27,1836.85],c3:[918.43,1298.27],c4:[649.13,918.43],c5:[459.21,649.13],c6:[323.15,459.21],c7:[229.61,323.15],c8:[161.57,229.61],c9:[113.39,161.57],c10:[79.37,113.39],dl:[311.81,623.62],letter:[612,792],"government-letter":[576,756],legal:[612,1008],"junior-legal":[576,360],ledger:[1224,792],tabloid:[792, -1224],"credit-card":[153,243]},A=this,ha=null,u=[],r=[],p=0,n="",T=[],G=[],Fa,J=[],V=!1;c.extend(!0,a,h);"xlsx"===a.type&&(a.mso.fileFormat=a.type,a.type="excel");"undefined"!==typeof a.excelFileFormat&&"undefined"===a.mso.fileFormat&&(a.mso.fileFormat=a.excelFileFormat);"undefined"!==typeof a.excelPageFormat&&"undefined"===a.mso.pageFormat&&(a.mso.pageFormat=a.excelPageFormat);"undefined"!==typeof a.excelPageOrientation&&"undefined"===a.mso.pageOrientation&&(a.mso.pageOrientation=a.excelPageOrientation); +1224],"credit-card":[153,243]},A=this,ha=null,u=[],r=[],p=0,n="",T=[],G=[],Ea,J=[],V=!1;d.extend(!0,a,h);"xlsx"===a.type&&(a.mso.fileFormat=a.type,a.type="excel");"undefined"!==typeof a.excelFileFormat&&"undefined"===a.mso.fileFormat&&(a.mso.fileFormat=a.excelFileFormat);"undefined"!==typeof a.excelPageFormat&&"undefined"===a.mso.pageFormat&&(a.mso.pageFormat=a.excelPageFormat);"undefined"!==typeof a.excelPageOrientation&&"undefined"===a.mso.pageOrientation&&(a.mso.pageOrientation=a.excelPageOrientation); "undefined"!==typeof a.excelRTL&&"undefined"===a.mso.rtl&&(a.mso.rtl=a.excelRTL);"undefined"!==typeof a.excelstyles&&"undefined"===a.mso.styles&&(a.mso.styles=a.excelstyles);"undefined"!==typeof a.onMsoNumberFormat&&"undefined"===a.mso.onMsoNumberFormat&&(a.mso.onMsoNumberFormat=a.onMsoNumberFormat);"undefined"!==typeof a.worksheetName&&"undefined"===a.mso.worksheetName&&(a.mso.worksheetName=a.worksheetName);a.mso.pageOrientation="l"===a.mso.pageOrientation.substr(0,1)?"landscape":"portrait";a.date.html= a.date.html||"";if(a.date.html.length){h=[];h.dd="(3[01]|[12][0-9]|0?[1-9])";h.mm="(1[012]|0?[1-9])";h.yyyy="((?:1[6-9]|2[0-2])\\d{2})";h.yy="(\\d{2})";var v=a.date.html.match(/[^a-zA-Z0-9]/)[0];v=a.date.html.toLowerCase().split(v);a.date.regex="^\\s*";a.date.regex+=h[v[0]];a.date.regex+="(.)";a.date.regex+=h[v[1]];a.date.regex+="\\2";a.date.regex+=h[v[2]];a.date.regex+="\\s*$";a.date.pattern=new RegExp(a.date.regex,"g");h=v.indexOf("dd")+1;a.date.match_d=h+(1"+F(a,c,e)+""});p++});Q+="";var ra= -1;r=B(c(A));c(r).each(function(){var a=1;n="";E(this,"td,th",p,u.length+r.length,function(b,c,g){n+=""+F(b,c,g)+"";a++});0"!==n&&(Q+=''+n+"",ra++);p++});Q+="";if("string"===a.outputMode)return Q;if("base64"===a.outputMode)return K(Q);M(Q,a.fileName+".xml","application/xml","utf-8","base64",!1)}else if("excel"===a.type&&"xmlss"===a.mso.fileFormat){var sa=[],D=[];c(A).filter(function(){return I(c(this))}).each(function(){function b(a, -b,d){var f=[];c(a).each(function(){var b=0,e=0;n="";E(this,"td,th",p,d+a.length,function(a,d,m){if(null!==a){var k="";d=F(a,d,m);m="String";if(!1!==jQuery.isNumeric(d))m="Number";else{var g=Ma(d);!1!==g&&(d=g,m="Number",k+=' ss:StyleID="pct1"')}"Number"!==m&&(d=d.replace(/\n/g,"
"));g=O(a);a=U(a);c.each(f,function(){if(p>=this.s.r&&p<=this.e.r&&e>=this.s.c&&e<=this.e.c)for(var a=0;a<=this.e.c-this.s.c;++a)e++,b++});if(a||g)a=a||1,g=g||1,f.push({s:{r:p,c:e},e:{r:p+a-1,c:e+g-1}});1'+c("
").text(d).html()+"\r";e++}});0\r'+n+"\r");p++});return a.length}var d=c(this),e="";"string"===typeof a.mso.worksheetName&&a.mso.worksheetName.length?e=a.mso.worksheetName+" "+(D.length+1):"undefined"!==typeof a.mso.worksheetName[D.length]&&(e=a.mso.worksheetName[D.length]);e.length|| -(e=d.find("caption").text()||"");e.length||(e="Table "+(D.length+1));e=c.trim(e.replace(/[\\\/[\]*:?'"]/g,"").substring(0,31));D.push(c("
").text(e).html());!1===a.exportHiddenCells&&(J=d.find("tr, th, td").filter(":hidden"),V=0\r";e=b(y(d),"th,td",0);b(B(d),"td,th",e);H+="\r";sa.push(H)});h={};v={};for(var l,R,Y=0,da=D.length;Y"+F(a,d,e)+""});p++});Q+="";var ra= +1;r=B(d(A));d(r).each(function(){var a=1;n="";E(this,"td,th",p,u.length+r.length,function(b,d,g){n+=""+F(b,d,g)+"";a++});0"!==n&&(Q+=''+n+"",ra++);p++});Q+="";if("string"===a.outputMode)return Q;if("base64"===a.outputMode)return K(Q);M(Q,a.fileName+".xml","application/xml","utf-8","base64",!1)}else if("excel"===a.type&&"xmlss"===a.mso.fileFormat){var sa=[],D=[];d(A).filter(function(){return I(d(this))}).each(function(){function b(a, +b,c){var f=[];d(a).each(function(){var b=0,e=0;n="";E(this,"td,th",p,c+a.length,function(a,c,m){if(null!==a){var k="";c=F(a,c,m);m="String";if(!1!==jQuery.isNumeric(c))m="Number";else{var g=Ma(c);!1!==g&&(c=g,m="Number",k+=' ss:StyleID="pct1"')}"Number"!==m&&(c=c.replace(/\n/g,"
"));g=O(a);a=U(a);d.each(f,function(){if(p>=this.s.r&&p<=this.e.r&&e>=this.s.c&&e<=this.e.c)for(var a=0;a<=this.e.c-this.s.c;++a)e++,b++});if(a||g)a=a||1,g=g||1,f.push({s:{r:p,c:e},e:{r:p+a-1,c:e+g-1}});1'+d("
").text(c).html()+"\r";e++}});0\r'+n+"\r");p++});return a.length}var c=d(this),e="";"string"===typeof a.mso.worksheetName&&a.mso.worksheetName.length?e=a.mso.worksheetName+" "+(D.length+1):"undefined"!==typeof a.mso.worksheetName[D.length]&&(e=a.mso.worksheetName[D.length]);e.length|| +(e=c.find("caption").text()||"");e.length||(e="Table "+(D.length+1));e=d.trim(e.replace(/[\\\/[\]*:?'"]/g,"").substring(0,31));D.push(d("
").text(e).html());!1===a.exportHiddenCells&&(J=c.find("tr, th, td").filter(":hidden"),V=0\r";e=b(y(c),"th,td",0);b(B(c),"td,th",e);H+="\r";sa.push(H)});h={};v={};for(var l,R,Y=0,da=D.length;Y\r\r\r\r '+(new Date).toISOString()+'\r\r\r \r\r\r 9000\r 13860\r 0\r 0\r False\r False\r\r\r \r \r \r\r'; for(v=0;v\r'+sa[v],h=a.mso.rtl?h+'\r\r\r':h+'\r',h+="\r";h+="\r";if("string"===a.outputMode)return h;if("base64"===a.outputMode)return K(h);M(h,a.fileName+".xml","application/xml","utf-8","base64",!1)}else if("excel"=== -a.type&&"xlsx"===a.mso.fileFormat){var aa=[],Ga=XLSX.utils.book_new();c(A).filter(function(){return I(c(this))}).each(function(){for(var b=c(this),d={},e=this.getElementsByTagName("tr"),g={s:{r:0,c:0},e:{r:0,c:0}},f=[],m,t=[],k=0,h=0,l,n,u,v,r,y=XLSX.SSF.get_table();kh;++k)if(l=e[k],n=!1,"function"===typeof a.onIgnoreRow&&(n=a.onIgnoreRow(c(l),k)),!1===n&&-1===c.inArray(p,a.ignoreRow)&&-1===c.inArray(p-ra,a.ignoreRow)&&I(c(l))){var A=l.children,C=0;for(l=0;lx||36x||48===x)D="n";else if("date"===E.type||13x||44x||56===x)D="d"}else D="s";if(null!=m)if(0===m.length)w.t=D||"z";else if(0!==m.trim().length&&"s"!==D)if("function"===E.type)w={f:m};else if("TRUE"===m)w={t:"b",v:!0};else if("FALSE"===m)w={t:"b",v:!1};else if(""===D&&c(r).find("a").length)m="href"!==a.htmlHyperlink? -m:"",w={f:'=HYPERLINK("'+c(r).find("a").attr("href")+(m.length?'","'+m:"")+'")'};else if("n"===D||!isNaN(Ea(m,a.numbers.output)))r=Ea(m,a.numbers.output),0===x&&"function"!==typeof a.mso.xslx.formatId.numbers&&(x=a.mso.xslx.formatId.numbers),isNaN(r)&&isNaN(m)||(w={t:"n",v:isNaN(r)?m:r,z:"string"===typeof x?x:x in y?y[x]:"0.00"});else if("d"===D||!1!==Ba(m))r=Ba(m),0===x&&"function"!==typeof a.mso.xslx.formatId.date&&(x=a.mso.xslx.formatId.date),w={t:"d",v:!1!==r?r:m,z:"string"===typeof x?x:x in y? -y[x]:"m/d/yy"};d[na({c:n,r:h})]=w;g.e.c";u=y(b);c(u).each(function(){var b=c(this);n="";E(this,"th,td",p,u.length,function(c,d,f){if(null!==c){var e="";n+=""}});0"+n+"");p++});H+="";r=B(b);c(r).each(function(){var b=c(this);n="";E(this,"td,th",p,u.length+r.length,function(d,g,f){if(null!==d){var e=F(d,g,f), -h="",k=c(d).attr("data-tableexport-msonumberformat");"undefined"===typeof k&&"function"===typeof a.mso.onMsoNumberFormat&&(k=a.mso.onMsoNumberFormat(d,g,f));"undefined"!==typeof k&&""!==k&&(h="style=\"mso-number-format:'"+k+"'");if(a.mso.styles.length){g=document.defaultView.getComputedStyle(d,null);f=document.defaultView.getComputedStyle(b[0],null);for(var l in a.mso.styles)k=g[a.mso.styles[l]],""===k&&(k=f[a.mso.styles[l]]),""!==k&&"0px none rgb(0, 0, 0)"!==k&&"rgba(0, 0, 0, 0)"!==k&&(h+=""===h? -'style="':";",h+=a.mso.styles[l]+":"+k)}n+=""));n+=">"+e+""}});0"+n+"");p++});a.displayTableName&&(H+=""+F(c("

"+a.tableName+"

"))+"");H+=""});l=''+ +a.type&&"xlsx"===a.mso.fileFormat){var aa=[],Fa=XLSX.utils.book_new();d(A).filter(function(){return I(d(this))}).each(function(){for(var b=d(this),c={},e=this.getElementsByTagName("tr"),g={s:{r:0,c:0},e:{r:0,c:0}},f=[],m,t=[],k=0,h=0,l,n,u,v,r,y=XLSX.SSF.get_table();kh;++k)if(l=e[k],n=!1,"function"===typeof a.onIgnoreRow&&(n=a.onIgnoreRow(d(l),k)),!1===n&&-1===d.inArray(p,a.ignoreRow)&&-1===d.inArray(p-ra,a.ignoreRow)&&I(d(l))){var A=l.children,C=0;for(l=0;lx||36x||48===x)D="n";else if("date"===E.type||13x||44x||56===x)D="d"}else D="s";if(null!=m)if(0===m.length)w.t=D||"z";else if(0!==m.trim().length&&"s"!==D)if("function"===E.type)w={f:m};else if("TRUE"===m)w={t:"b",v:!0};else if("FALSE"===m)w={t:"b",v:!1};else if(""===D&&d(r).find("a").length)m="href"!==a.htmlHyperlink? +m:"",w={f:'=HYPERLINK("'+d(r).find("a").attr("href")+(m.length?'","'+m:"")+'")'};else if("n"===D||!isNaN(Da(m,a.numbers.output)))r=Da(m,a.numbers.output),0===x&&"function"!==typeof a.mso.xslx.formatId.numbers&&(x=a.mso.xslx.formatId.numbers),isNaN(r)&&isNaN(m)||(w={t:"n",v:isNaN(r)?m:r,z:"string"===typeof x?x:x in y?y[x]:"0.00"});else if(!1!==(r=La(m))||"d"===D)0===x&&"function"!==typeof a.mso.xslx.formatId.date&&(x=a.mso.xslx.formatId.date),w={t:"d",v:!1!==r?r:m,z:"string"===typeof x?x:x in y?y[x]: +"m/d/yy"};c[na({c:n,r:h})]=w;g.e.c";u=y(b);d(u).each(function(){var b=d(this);n="";E(this,"th,td",p,u.length,function(d,c,f){if(null!==d){var e="";n+=""}});0"+n+"");p++});H+="";r=B(b);d(r).each(function(){var b=d(this);n="";E(this,"td,th",p,u.length+r.length,function(c,g,f){if(null!==c){var e=F(c,g,f), +h="",k=d(c).attr("data-tableexport-msonumberformat");"undefined"===typeof k&&"function"===typeof a.mso.onMsoNumberFormat&&(k=a.mso.onMsoNumberFormat(c,g,f));"undefined"!==typeof k&&""!==k&&(h="style=\"mso-number-format:'"+k+"'");if(a.mso.styles.length){g=document.defaultView.getComputedStyle(c,null);f=document.defaultView.getComputedStyle(b[0],null);for(var l in a.mso.styles)k=g[a.mso.styles[l]],""===k&&(k=f[a.mso.styles[l]]),""!==k&&"0px none rgb(0, 0, 0)"!==k&&"rgba(0, 0, 0, 0)"!==k&&(h+=""===h? +'style="':";",h+=a.mso.styles[l]+":"+k)}n+=""));n+=">"+e+""}});0"+n+"");p++});a.displayTableName&&(H+=""+F(d("

"+a.tableName+"

"))+"");H+=""});l=''+ ('');l+="";"excel"===h&&(l+="\x3c!--[if gte mso 9]>",l+="",l+="",l+="",l+="",l+="",l+=ba,l+="",l+="",l+="",a.mso.rtl&&(l+=""),l+="",l+="",l+="",l+="",l+="",l+=""; l+="@page { size:"+a.mso.pageOrientation+"; mso-page-orientation:"+a.mso.pageOrientation+"; }";l+="@page Section1 {size:"+N[a.mso.pageFormat][0]+"pt "+N[a.mso.pageFormat][1]+"pt";l+="; margin:1.0in 1.25in 1.0in 1.25in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}";l+="div.Section1 {page:Section1;}";l+="@page Section2 {size:"+N[a.mso.pageFormat][1]+"pt "+N[a.mso.pageFormat][0]+"pt";l+=";mso-page-orientation:"+a.mso.pageOrientation+";margin:1.25in 1.0in 1.25in 1.0in;mso-header-margin:.5in;mso-footer-margin:.5in;mso-paper-source:0;}"; -l+="div.Section2 {page:Section2;}";l+="br {mso-data-placement:same-cell;}";l+="";l+="";l+="";l+='
';l+=H;l+="
";l+="";l+="";if("string"===a.outputMode)return l;if("base64"===a.outputMode)return K(l);M(l,a.fileName+"."+v,"application/vnd.ms-"+h,"","base64",!1)}else if("png"===a.type)html2canvas(c(A)[0]).then(function(b){b=b.toDataURL();for(var c=atob(b.substring(22)),e=new ArrayBuffer(c.length), -g=new Uint8Array(e),f=0;fJa){a>N.a0[0]&&(ia="a0",ca="l");for(var d in N)N.hasOwnProperty(d)&&N[d][1]>a&&(ia=d,ca="l",N[d][0]>a&&(ca="p"));Ja=a}}});a.jspdf.format=""===ia?"a4":ia;a.jspdf.orientation=""===ca?"w":ca}if(null==g.doc&&(g.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format),g.wScaleFactor=1,g.hScaleFactor=1,"function"===typeof a.jspdf.onDocCreated))a.jspdf.onDocCreated(g.doc);!0===g.outputImages&&(g.images={});"undefined"!==typeof g.images&&(c(A).filter(function(){return I(c(this))}).each(function(){var b= -0;G=[];!1===a.exportHiddenCells&&(J=c(this).find("tr, th, td").filter(":hidden"),V=0a.styles.rowHeight&&(a.styles.rowHeight=f)}a.styles.halign="inherit"===d.headerStyles.halign?"center":d.headerStyles.halign;a.styles.valign=d.headerStyles.valign;"undefined"!==typeof e.style&&!0!==e.style.hidden&&("inherit"===d.headerStyles.halign&&(a.styles.halign=e.style.align),"inherit"===d.styles.fillColor&&(a.styles.fillColor=e.style.bcolor),"inherit"===d.styles.textColor&&(a.styles.textColor=e.style.color),"inherit"===d.styles.fontStyle&&(a.styles.fontStyle=e.style.fstyle))}}); -"function"!==typeof d.createdCell&&(d.createdCell=function(a,b){b=g.teCells[b.row.index+":"+b.column.dataKey];a.styles.halign="inherit"===d.styles.halign?"center":d.styles.halign;a.styles.valign=d.styles.valign;"undefined"!==typeof b&&"undefined"!==typeof b.style&&!0!==b.style.hidden&&("inherit"===d.styles.halign&&(a.styles.halign=b.style.align),"inherit"===d.styles.fillColor&&(a.styles.fillColor=b.style.bcolor),"inherit"===d.styles.textColor&&(a.styles.textColor=b.style.color),"inherit"===d.styles.fontStyle&& -(a.styles.fontStyle=b.style.fstyle))});"function"!==typeof d.drawHeaderCell&&(d.drawHeaderCell=function(a,b){var c=g.columns[b.column.dataKey];return(!0!==c.style.hasOwnProperty("hidden")||!0!==c.style.hidden)&&0<=c.rowIndex?wa(a,b,c):!1});"function"!==typeof d.drawCell&&(d.drawCell=function(a,b){var d=g.teCells[b.row.index+":"+b.column.dataKey];if(!0!==("undefined"!==typeof d&&d.isCanvas))wa(a,b,d)&&(g.doc.rect(a.x,a.y,a.width,a.height,a.styles.fillStyle),"undefined"!==typeof d&&"undefined"!==typeof d.elements&& -d.elements.length?(b=a.height/d.rect.height,b>g.hScaleFactor&&(g.hScaleFactor=b),g.wScaleFactor=a.width/d.rect.width,b=a.textPos.y,za(a,d.elements,g),a.textPos.y=b,Aa(a,d.elements,g)):Aa(a,{},g));else{d=d.elements[0];var e=c(d).attr("data-tableexport-canvas"),f=d.getBoundingClientRect();a.width=f.width*g.wScaleFactor;a.height=f.height*g.hScaleFactor;b.row.height=a.height;ua(a,d,e,g)}return!1});g.headerrows=[];u=y(c(this));c(u).each(function(){b=0;g.headerrows[p]=[];E(this,"th,td",p,u.length,function(a, -c,d){var e=Da(a);e.title=F(a,c,d);e.key=b++;e.rowIndex=p;g.headerrows[p].push(e)});p++});if(0';l+=H;l+="
";l+="";l+="";if("string"===a.outputMode)return l;if("base64"===a.outputMode)return K(l);M(l,a.fileName+"."+v,"application/vnd.ms-"+h,"","base64",!1)}else if("png"===a.type)html2canvas(d(A)[0]).then(function(b){b=b.toDataURL();for(var d=atob(b.substring(22)),e=new ArrayBuffer(d.length), +g=new Uint8Array(e),f=0;fIa){a>N.a0[0]&&(ia="a0",ca="l");for(var c in N)N.hasOwnProperty(c)&&N[c][1]>a&&(ia=c,ca="l",N[c][0]>a&&(ca="p"));Ia=a}}});a.jspdf.format=""===ia?"a4":ia;a.jspdf.orientation=""===ca?"w":ca}if(null==g.doc&&(g.doc=new jsPDF(a.jspdf.orientation,a.jspdf.unit,a.jspdf.format),g.wScaleFactor=1,g.hScaleFactor=1,"function"===typeof a.jspdf.onDocCreated))a.jspdf.onDocCreated(g.doc);!0===g.outputImages&&(g.images={});"undefined"!==typeof g.images&&(d(A).filter(function(){return I(d(this))}).each(function(){var b= +0;G=[];!1===a.exportHiddenCells&&(J=d(this).find("tr, th, td").filter(":hidden"),V=0a.styles.rowHeight&&(a.styles.rowHeight=f)}a.styles.halign="inherit"===c.headerStyles.halign?"center":c.headerStyles.halign;a.styles.valign=c.headerStyles.valign;"undefined"!==typeof e.style&&!0!==e.style.hidden&&("inherit"===c.headerStyles.halign&&(a.styles.halign=e.style.align),"inherit"===c.styles.fillColor&&(a.styles.fillColor=e.style.bcolor),"inherit"===c.styles.textColor&&(a.styles.textColor=e.style.color),"inherit"===c.styles.fontStyle&&(a.styles.fontStyle=e.style.fstyle))}}); +"function"!==typeof c.createdCell&&(c.createdCell=function(a,b){b=g.teCells[b.row.index+":"+b.column.dataKey];a.styles.halign="inherit"===c.styles.halign?"center":c.styles.halign;a.styles.valign=c.styles.valign;"undefined"!==typeof b&&"undefined"!==typeof b.style&&!0!==b.style.hidden&&("inherit"===c.styles.halign&&(a.styles.halign=b.style.align),"inherit"===c.styles.fillColor&&(a.styles.fillColor=b.style.bcolor),"inherit"===c.styles.textColor&&(a.styles.textColor=b.style.color),"inherit"===c.styles.fontStyle&& +(a.styles.fontStyle=b.style.fstyle))});"function"!==typeof c.drawHeaderCell&&(c.drawHeaderCell=function(a,b){var d=g.columns[b.column.dataKey];return(!0!==d.style.hasOwnProperty("hidden")||!0!==d.style.hidden)&&0<=d.rowIndex?wa(a,b,d):!1});"function"!==typeof c.drawCell&&(c.drawCell=function(a,b){var c=g.teCells[b.row.index+":"+b.column.dataKey];if(!0!==("undefined"!==typeof c&&c.isCanvas))wa(a,b,c)&&(g.doc.rect(a.x,a.y,a.width,a.height,a.styles.fillStyle),"undefined"!==typeof c&&"undefined"!==typeof c.elements&& +c.elements.length?(b=a.height/c.rect.height,b>g.hScaleFactor&&(g.hScaleFactor=b),g.wScaleFactor=a.width/c.rect.width,b=a.textPos.y,za(a,c.elements,g),a.textPos.y=b,Aa(a,c.elements,g)):Aa(a,{},g));else{c=c.elements[0];var e=d(c).attr("data-tableexport-canvas"),f=c.getBoundingClientRect();a.width=f.width*g.wScaleFactor;a.height=f.height*g.hScaleFactor;b.row.height=a.height;ua(a,c,e,g)}return!1});g.headerrows=[];u=y(d(this));d(u).each(function(){b=0;g.headerrows[p]=[];E(this,"th,td",p,u.length,function(a, +d,c){var e=Ca(a);e.title=F(a,d,c);e.key=b++;e.rowIndex=p;g.headerrows[p].push(e)});p++});if(0