tablesorter/dist/js/widgets/widget-output.min.js

2 lines
5.0 KiB
JavaScript
Raw Normal View History

2015-05-17 20:32:53 +00:00
/*! Widget: output - updated 5/17/2015 (v2.22.0) */
!function(a){"use strict";var b=a.tablesorter,c=b.output={event:"outputTable",regexQuote:/([\n\t\x09\x0d\x0a]|<[^<]+>)/,regexBR:/(<br([\s\/])?>|\n)/g,regexIMG:/<img[^>]+alt\s*=\s*['"]([^'"]+)['"][^>]*>/i,regexHTML:/<[^<]+>/g,replaceCR:"\r\n",replaceTab:" ",popupTitle:"Output",popupStyle:"width:100%;height:100%;",message:"Your device does not support downloading. Please try again in desktop browser.",init:function(a){a.$table.off(c.event).on(c.event,function(){c.process(a,a.widgetOptions)})},processRow:function(b,d,e,f){var g,h,i,j,k,l,m=b.widgetOptions,n=[],o=m.output_duplicateSpans,p=e&&f&&m.output_headerRows&&a.isFunction(m.output_callbackJSON),q=0;return d.each(function(b){n[b]||(n[b]=[]),q=0,a(this).children().each(function(){if(g=a(this),g.filter("[rowspan]").length)for(j=parseInt(g.attr("rowspan"),10)-1,l=c.formatData(m,g,e),h=1;j>=h;h++)n[b+h]||(n[b+h]=[]),n[b+h][q]=e?l:o?l:"";if(g.filter("[colspan]").length)for(k=parseInt(g.attr("colspan"),10)-1,l=c.formatData(m,g,e),i=1;k>=i;i++)if(g.filter("[rowspan]").length)for(j=parseInt(g.attr("rowspan"),10),h=0;j>h;h++)n[b+h]||(n[b+h]=[]),n[b+h][q+i]=p?m.output_callbackJSON(g,l,q+i)||l+"("+(q+i)+")":e?l:o?l:"";else n[b][q+i]=p?m.output_callbackJSON(g,l,q+i)||l+"("+(q+i)+")":e?l:o?l:"";if(!m.output_hiddenColumns&&"none"!==g.css("display")){for(;"undefined"!=typeof n[b][q];)q++;n[b][q]=n[b][q]||c.formatData(m,g,e),q++}})}),n},ignoreColumns:function(b,c){return a.each(c,function(d,e){c[d]=a.grep(e,function(c,d){return a.inArray(d,b.output_ignoreColumns)<0})}),c},process:function(d,e){var f,g,h,i,j,k,l=window.JSON&&JSON.hasOwnProperty("stringify"),m=0,n=(e.output_separator||",").toLowerCase(),o="json"===n,p="array"===n,q=o||p?",":e.output_separator,r=e.output_saveRows,s=d.$table;e.output_regex=new RegExp("("+(/\\/.test(q)?"\\":"")+q+")"),g=s.find("thead tr:visible").not("."+(b.css.filterRow||"tablesorter-filter-row")),i=c.processRow(d,g,!0,o),h=s.children("tbody").children("tr"),e.output_includeFooter&&(h=h.add(s.children("tfoot").children("tr").clone())),h=/^f/.test(r)?h.not("."+(e.filter_filteredRow||"filtered")):/^v/.test(r)?h.filter(":visible"):/^[.#:\[]/.test(r)?h.filter(r):h,j=c.processRow(d,h),k=i.length,e.output_ignoreColumns.length&&(i=c.ignoreColumns(e,i),j=c.ignoreColumns(e,j)),o?(n=[],a.each(j,function(a,b){n.push(c.row2Hash(i[k>1&&e.output_headerRows?a%k:k-1],b))}),f=l?JSON.stringify(n):n):(n=c.row2CSV(e,e.output_headerRows?i:[i[k>1&&e.output_headerRows?m%k:k-1]],p).concat(c.row2CSV(e,j,p)),f=p&&l?JSON.stringify(n):n.join("\n")),(!a.isFunction(e.output_callback)||e.output_callback(d,f))&&(/p/i.test(e.output_delivery||"")?c.popup(f,e.output_popupStyle,o||p):c.download(e,f))},row2CSV:function(a,b,c){var d,e,f=[],g=b.length;for(e=0;g>e;e++)d=b[e].join("").replace(/\"/g,""),b[e].length>0&&""!==d&&(f[f.length]=c?b[e]:b[e].join(a.output_separator));return f},row2Hash:function(b,c){var d={};return a.each(c,function(a,c){a<b.length&&(d[b[a]]=c)}),d},formatData:function(b,d,e){var f=d.attr(b.output_dataAttrib),g="undefined"!=typeof f?f:d.html(),h=(b.output_separator||",").toLowerCase(),i="json"===h||"array"===h,j=g.replace(/\"/g,b.output_replaceQuote||"“");return j=b.output_trimSpaces?j.replace(c.regexBR,""):j.replace(c.regexBR,c.replaceCR).replace(/\t/g,c.replaceTab),g=j.match(c.regexIMG),b.output_includeHTML||null===g||(j=g[1]),j=b.output_includeHTML&&!e?j:j.replace(c.regexHTML,""),j=b.output_trimSpaces||e?a.trim(j):j,h=i?!1:b.output_wrapQuotes||b.output_regex.test(j)||c.regexQuote.test(j),h?'"'+j+'"':j},popup:function(a,b,d){var e=window.open("",c.popupTitle,b);return e.document.write("<html><head><title>"+c.popupTitle+'</title></head><body><textarea wrap="'+(d?"on":"off")+'" style="'+c.popupStyle+'">'+a+"\n</textarea></body></html>"),e.document.close(),e.focus(),!0},download:function(a,b){var d,e,f,g=window.navigator,h=document.createElement("a");if(/(iP)/g.test(g.userAgent))return alert(c.message),!1;try{f=!!new Blob}catch(i){f=!1}return f?(window.URL=window.URL||window.webkitURL,e=new Blob(["\ufeff",b],{type:a.output_encoding}),g.msSaveBlob?g.msSaveBlob(e,a.output