Вход Регистрация
Файл: assets/plugins/bootstrap-table/extensions/export/bootstrap-table-export.table.min.js
Строк: 659
/*The MIT License (MIT)

 Original work Copyright (c) 2014 https://github.com/kayalshri/
 Modified work Copyright (c) 2015 https://github.com/hhurz/

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.*/

 !function(t){t.fn.extend({tableExport:function(e){function n(e,n,o,a){-1==y.ignoreRow.indexOf(o)&&t(e).filter(function(){return t(this).is(":visible")||"always"==t(this).data("tableexport-display")||"always"==t(this).closest("table").data("tableexport-display")}).find(n).each(function(e){if(("always"==t(this).data("tableexport-display")||"none"!=t(this).css("display")&&"hidden"!=t(this).css("visibility")&&"none"!=t(this).data("tableexport-display"))&&-1==y.ignoreColumn.indexOf(e)&&"function"==typeof a){var n=0;if("undefined"!=typeof w[o]&&w[o].length>0)for(c=0;c<=e;c++)"undefined"!=typeof w[o][c]&&(a(null,o,c),delete w[o][c],e++);if(a(this,o,e),t(this).is("[colspan]"))for(n=t(this).attr("colspan"),c=0;c<n-1;c++)a(null,o,e+c);if(t(this).is("[rowspan]")){var i=parseInt(t(this).attr("rowspan"));for(r=1;r<i;r++)for("undefined"==typeof w[o+r]&&(w[o+r]=[]),w[o+r][e]="",c=1;c<n;c++)w[o+r][e+c]=""}}})}function o(t){if(y.consoleLog===!0&&console.log(t.output()),"string"==y.outputMode)return t.output();if("base64"==y.outputMode)return g(t.output());try{var e=t.output("blob");saveAs(e,y.fileName+".pdf")}catch(n){h(y.fileName+".pdf","data:application/pdf;base64,"+g(t.output()))}}function a(t){return t.replace(/([.*+?^=!:${}()|[]/\])/g,"\$1")}function i(t,e,n){return t.replace(new RegExp(a(e),"g"),n)}function l(t,e,n){var o="";if(null!=t){var r=d(t,e,n),a=null===r||""==r?"":r.toString();r instanceof Date?o=y.csvEnclosure+r.toLocaleString()+y.csvEnclosure:(o=i(a,y.csvEnclosure,y.csvEnclosure+y.csvEnclosure),(o.indexOf(y.csvSeparator)>=0||/[rn ]/g.test(o))&&(o=y.csvEnclosure+o+y.csvEnclosure))}return o}function s(t){return t=t||"0",t=i(t,y.numbers.html.decimalMark,"."),t=i(t,y.numbers.html.thousandsSeparator,""),"number"==typeof t||jQuery.isNumeric(t)!==!1?t:!1}function d(e,n,o){var r="";if(null!=e){var a=t(e);if(y.htmlContent===!0)r=a.html().trim();else if(r=a.text().trim().replace(/u00AD/g,""),y.numbers.html.decimalMark!=y.numbers.output.decimalMark||y.numbers.html.thousandsSeparator!=y.numbers.output.thousandsSeparator){var i=s(r);if(i!==!1){var l=(""+i).split(".");1==l.length&&(l[1]="");var c=l[0].length>3?l[0].length%3:0;r=(0>i?"-":"")+(y.numbers.output.thousandsSeparator?(c?l[0].substr(0,c)+y.numbers.output.thousandsSeparator:"")+l[0].substr(c).replace(/(d{3})(?=d)/g,"$1"+y.numbers.output.thousandsSeparator):l[0])+(l[1].length?y.numbers.output.decimalMark+l[1]:"")}}y.escape===!0&&(r=escape(r)),"function"==typeof y.onCellData&&(r=y.onCellData(a,n,o,r))}return r}function f(t,e,n){return e+"-"+n.toLowerCase()}function u(t,e){try{return window.getComputedStyle?(e=e.replace(/([a-z])([A-Z])/,f),window.getComputedStyle(t,null).getPropertyValue(e)):t.currentStyle?t.currentStyle[e]:t.style[e]}catch(n){}return""}function p(t,e,n){var o=100,r=u(t,e),a=r.match(/d+/);if(null!==a){a=a[0];var i=document.createElement("div");i.style.overflow="hidden",i.style.visibility="hidden",t.parentElement.appendChild(i),i.style.width=o+n;var l=o/i.offsetWidth;return t.parentElement.removeChild(i),a*l}return 0}function h(t,e){var n=document.createElement("a");n&&(document.body.appendChild(n),n.style="display: none",n.download=t,n.href=e,document.createEvent?(null==v&&(v=document.createEvent("MouseEvents")),v.initEvent("click",!0,!1),n.dispatchEvent(v)):document.createEventObject?n.fireEvent("onclick"):"function"==typeof n.onclick&&n.onclick(),document.body.removeChild(n))}function m(t){t=t.replace(/x0dx0a/g,"n");for(var e="",n=0;n<t.length;n++){var o=t.charCodeAt(n);128>o?e+=String.fromCharCode(o):o>127&&2048>o?(e+=String.fromCharCode(o>>6|192),e+=String.fromCharCode(63&o|128)):(e+=String.fromCharCode(o>>12|224),e+=String.fromCharCode(o>>6&63|128),e+=String.fromCharCode(63&o|128))}return e}function g(t){var e,n,o,r,a,i,l,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",c="",d=0;for(t=m(t);d<t.length;)e=t.charCodeAt(d++),n=t.charCodeAt(d++),o=t.charCodeAt(d++),r=e>>2,a=(3&e)<<4|n>>4,i=(15&n)<<2|o>>6,l=63&o,isNaN(n)?i=l=64:isNaN(o)&&(l=64),c=c+s.charAt(r)+s.charAt(a)+s.charAt(i)+s.charAt(l);return c}var y={consoleLog:!1,csvEnclosure:'"',csvSeparator:",",csvUseBOM:!0,displayTableName:!1,escape:!1,excelstyles:["border-bottom","border-top","border-left","border-right"],fileName:"tableExport",htmlContent:!1,ignoreColumn:[],ignoreRow:[],jspdf:{orientation:"p",unit:"pt",format:"a4",margins:{left:20,right:10,top:10,bottom:10},autotable:{padding:2,lineHeight:12,fontSize:8,tableExport:{onAfterAutotable:null,onBeforeAutotable:null,onTable:null}}},numbers:{html:{decimalMark:".",thousandsSeparator:","},output:{decimalMark:".",thousandsSeparator:","}},onCellData:null,outputMode:"file",tbodySelector:"tr",theadSelector:"tr",tableName:"myTableName",type:"csv",worksheetName:"xlsWorksheetName"},b=this,v=null,x=0,w=[],S="";if(t.extend(!0,y,e),"csv"==y.type||"txt"==y.type){var C="";if(x=0,t(b).find("thead").first().find(y.theadSelector).each(function(){S="",n(this,"th,td",x,function(t,e,n){S+=l(t,e,n)+y.csvSeparator}),S=t.trim(S).substring(0,S.length-1),S.length>0&&(C.length>0&&(C+="n"),C+=S),x++}),t(b).find("tbody").first().find(y.tbodySelector).each(function(){S="",n(this,"td",x,function(t,e,n){S+=l(t,e,n)+y.csvSeparator}),S=t.trim(S).substring(0,S.length-1),S.length>0&&(C.length>0&&(C+="n"),C+=S),x++}),C+="n",y.consoleLog===!0&&console.log(C),"string"===y.outputMode)return C;if("base64"===y.outputMode)return g(C);try{var E=new Blob([("csv"==y.type&&y.csvUseBOM?"":"")+C],{type:"text/"+("csv"==y.type?"csv":"plain")+";charset=utf-8"});saveAs(E,y.fileName+"."+y.type)}catch(N){h(y.fileName+"."+y.type,"data:text/"+("csv"==y.type?"csv":"plain")+";charset=utf-8,"+("csv"==y.type&&y.csvUseBOM?"":"")+encodeURIComponent(C))}}else if("sql"==y.type){x=0;var j="INSERT INTO `"+y.tableName+"` (";if(t(b).find("thead").first().find(y.theadSelector).each(function(){n(this,"th,td",x,function(t,e,n){j+="'"+d(t,e,n)+"',"}),x++,j=t.trim(j),j=t.trim(j).substring(0,j.length-1)}),j+=") VALUES ",t(b).find("tbody").first().find(y.tbodySelector).each(function(){S="",n(this,"td",x,function(t,e,n){S+="'"+d(t,e,n)+"',"}),S.length>3&&(j+="("+S,j=t.trim(j).substring(0,j.length-1),j+="),"),x++}),j=t.trim(j).substring(0,j.length-1),j+=";",y.consoleLog===!0&&console.log(j),"string"==y.outputMode)return j;if("base64"==y.outputMode)return g(j);try{var E=new Blob([j],{type:"text/plain;charset=utf-8"});saveAs(E,y.fileName+".sql")}catch(N){h(y.fileName+".sql","data:application/sql;charset=utf-8,"+encodeURIComponent(j))}}else if("json"==y.type){var A=[];t(b).find("thead").first().find(y.theadSelector).each(function(){var t=[];n(this,"th,td",x,function(e,n,o){t.push(d(e,n,o))}),A.push(t)});var k=[];t(b).find("tbody").first().find(y.tbodySelector).each(function(){var t=[];n(this,"td",x,function(e,n,o){t.push(d(e,n,o))}),t.length>0&&(1!=t.length||""!=t[0])&&k.push(t),x++});var M=[];M.push({header:A,data:k});var T=JSON.stringify(M);if(y.consoleLog===!0&&console.log(T),"string"==y.outputMode)return T;var O=g(T);if("base64"==y.outputMode)return O;try{var E=new Blob([T],{type:"application/json;charset=utf-8"});saveAs(E,y.fileName+".json")}catch(N){h(y.fileName+".json","data:application/json;charset=utf-8;base64,"+O)}}else if("xml"===y.type){x=0;var U='<?xml version="1.0" encoding="utf-8"?>';U+="<tabledata><fields>",t(b).find("thead").first().find(y.theadSelector).each(function(){n(this,"th,td",x,function(t,e,n){U+="<field>"+d(t,e,n)+"</field>"}),x++}),U+="</fields><data>";var W=1;if(t(b).find("tbody").first().find(y.tbodySelector).each(function(){var t=1;S="",n(this,"td",x,function(e,n,o){S+="<column-"+t+">"+d(e,n,o)+"</column-"+t+">",t++}),S.length>0&&"<column-1></column-1>"!=S&&(U+='<row id="'+W+'">'+S+"</row>",W++),x++}),U+="</data></tabledata>",y.consoleLog===!0&&console.log(U),"string"==y.outputMode)return U;var O=g(U);if("base64"==y.outputMode)return O;try{var E=new Blob([U],{type:"application/xml;charset=utf-8"});saveAs(E,y.fileName+".xml")}catch(N){h(y.fileName+".xml","data:application/xml;charset=utf-8;base64,"+O)}}else if("excel"==y.type||"doc"==y.type){x=0;var B="<table>";t(b).find("thead").first().find(y.theadSelector).each(function(){S="",n(this,"th,td",x,function(e,n,o){if(null!=e){S+="<td style='";for(var r in y.excelstyles)y.excelstyles.hasOwnProperty(r)&&(S+=y.excelstyles[r]+": "+t(e).css(y.excelstyles[r])+";");S+="'>"+d(e,n,o)+"</td>"}}),S.length>0&&(B+="<tr>"+S+"</tr>"),x++}),t(b).find("tbody").first().find(y.tbodySelector).each(function(){S="",n(this,"td",x,function(e,n,o){if(null!=e){S+="<td style='";for(var r in y.excelstyles)y.excelstyles.hasOwnProperty(r)&&(S+=y.excelstyles[r]+": "+t(e).css(y.excelstyles[r])+";");t(e).is("[colspan]")&&(S+="' colspan='"+t(e).attr("colspan")),t(e).is("[rowspan]")&&(S+="' rowspan='"+t(e).attr("rowspan")),S+="'>"+d(e,n,o)+"</td>"}}),S.length>0&&(B+="<tr>"+S+"</tr>"),x++}),y.displayTableName&&(B+="<tr><td></td></tr><tr><td></td></tr><tr><td>"+d(t("<p>"+y.tableName+"</p>"))+"</td></tr>"),B+="</table>",y.consoleLog===!0&&console.log(B);var F="<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:"+y.type+"' xmlns='http://www.w3.org/TR/REC-html40'>";if(F+='<meta http-equiv="content-type" content="application/vnd.ms-'+y.type+'; charset=UTF-8">',F+='<meta http-equiv="content-type" content="application/',F+="excel"===y.type?"vnd.ms-excel":"msword",F+='; charset=UTF-8">',F+="<head>","excel"===y.type&&(F+="<!--[if gte mso 9]>",F+="<xml>",F+="<x:ExcelWorkbook>",F+="<x:ExcelWorksheets>",F+="<x:ExcelWorksheet>",F+="<x:Name>",F+=y.worksheetName,F+="</x:Name>",F+="<x:WorksheetOptions>",F+="<x:DisplayGridlines/>",F+="</x:WorksheetOptions>",F+="</x:ExcelWorksheet>",F+="</x:ExcelWorksheets>",F+="</x:ExcelWorkbook>",F+="</xml>",F+="<![endif]-->"),F+="</head>",F+="<body>",F+=B,F+="</body>",F+="</html>","string"==y.outputMode)return F;var O=g(F);if("base64"===y.outputMode)return O;var L="excel"===y.type?"xls":"doc";try{var E=new Blob([F],{type:"application/vnd.ms-"+y.type});saveAs(E,y.fileName+"."+L)}catch(N){h(y.fileName+"."+L,"data:application/vnd.ms-"+y.type+";base64,"+O)}}else if("png"==y.type)html2canvas(t(b),{onrendered:function(t){var e=t.toDataURL();e=e.substring(22);for(var n=atob(e),o=new ArrayBuffer(n.length),r=new Uint8Array(o),a=0;a<n.length;a++)r[a]=n.charCodeAt(a);try{var i=new Blob([o],{type:"image/png"});saveAs(i,y.fileName+".png")}catch(l){h(y.fileName+".png","data:image/png;base64,"+e)}}});else if("pdf"==y.type)if(y.jspdf.autotable===!1){var D={dim:{w:p(t(b).first().get(0),"width","mm"),h:p(t(b).first().get(0),"height","mm")},pagesplit:!1},R=new jsPDF(y.jspdf.orientation,y.jspdf.unit,y.jspdf.format);R.addHTML(t(b).first(),y.jspdf.margins.left,y.jspdf.margins.top,D,function(){o(R)})}else{var H=y.jspdf.autotable.tableExport;if("string"==typeof y.jspdf.format&&"bestfit"===y.jspdf.format.toLowerCase()){var P={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]},q="",z="",I=0;t(b).filter(":visible").each(function(){if("none"!=t(this).css("display")){var e=p(t(this).get(0),"width","pt");if(e>I){e>P.a0[0]&&(q="a0",z="l");for(var n in P)P.hasOwnProperty(n)&&P[n][1]>e&&(q=n,z="l",P[n][0]>e&&(z="p"));I=e}}}),y.jspdf.format=""==q?"a4":q,y.jspdf.orientation=""==z?"w":z}H.doc=new jsPDF(y.jspdf.orientation,y.jspdf.unit,y.jspdf.format),t(b).filter(":visible").each(function(){if("none"!=t(this).css("display")){var e,o=0,r={};if(H.columns=[],H.rows=[],H.rowoptions={},"function"==typeof H.onTable&&H.onTable(t(this),y)===!1)return!0;Object.keys(y.jspdf.autotable).forEach(function(t){r[t]=y.jspdf.autotable[t]}),r.margins={},t.extend(!0,r.margins,y.jspdf.margins),"function"!=typeof r.renderHeaderCell&&(r.renderHeaderCell=function(t,e,n,o,r,a,i){var l=i.tableExport.doc,s=0;if(l.setFillColor(52,73,94),l.setTextColor(255,255,255),l.setFontStyle("bold"),l.rect(t,e,n,o,"F"),e+=i.lineHeight/2+l.autoTableTextHeight()/2,"undefined"!=typeof i.tableExport.columns[r]){var c=i.tableExport.columns[r];"undefined"!=typeof c.style&&("right"==c.style.align?s=n-l.getStringUnitWidth(""+a)*l.internal.getFontSize()-i.padding:"center"==c.style.align&&(s=(n-l.getStringUnitWidth(""+a)*l.internal.getFontSize())/2))}s<i.padding&&(s=i.padding),l.text(a,t+s,e)}),"function"!=typeof r.renderCell&&(r.renderCell=function(t,e,n,o,r,a,i,l){var s=l.tableExport.doc,c=0;s.setFillColor(i%2===0?245:255),s.setTextColor(50),s.rect(t,e,n,o,"F"),e+=l.lineHeight/2+s.autoTableTextHeight()/2-2.5;var d=l.tableExport.rowoptions[i+":"+r];"undefined"!=typeof d&&("right"==d.style.align?c=n-s.getStringUnitWidth(""+a)*s.internal.getFontSize()-l.padding:"center"==d.style.align&&(c=(n-s.getStringUnitWidth(""+a)*s.internal.getFontSize())/2)),c<l.padding&&(c=l.padding),s.text(a,t+c,e)}),t(this).find("thead").find(y.theadSelector).each(function(){e=0,n(this,"th,td",o,function(t,n,o){var r=u(t,"text-align");"start"==r&&(r="rtl"==u(t,"direction")?"right":"left");var a={title:d(t,n,o),key:e++,style:{align:r,bcolor:u(t,"background-color")}};H.columns.push(a)}),o++});var a=0;t(this).find("tbody").find(y.tbodySelector).each(function(){var t=[];e=0,n(this,"td",o,function(n,o,r){var i=u(n,"text-align");"start"==i&&(i="rtl"==u(n,"direction")?"right":"left");var l={style:{align:i,bcolor:u(n,"background-color")}};H.rowoptions[a+":"+e++]=l,t.push(d(n,o,r))}),t.length&&(H.rows.push(t),a++),o++}),"function"==typeof H.onBeforeAutotable&&H.onBeforeAutotable(t(this),H.columns,H.rows,r),H.doc.autoTable(H.columns,H.rows,r),"function"==typeof H.onAfterAutotable&&H.onAfterAutotable(t(this),r),y.jspdf.autotable.startY=H.doc.autoTableEndPosY()+r.margins.top}}),o(H.doc),H.columns.length=0,H.rows.length=0,delete H.doc,H.doc=null}return this}})}(jQuery);
Онлайн: 0
Реклама