|
|
|
!function(e){"use strict";var t=e.tablesorter=e.tablesorter||{},l=t.buildTable=function(o,r){e.extend(!0,t.defaults.widgetOptions,l.defaults);var n="TABLE"===o.nodeName?e(o):e("<table>").appendTo(o),i=n[0],d=r.widgetOptions=e.extend(!0,{},l.defaults,r.widgetOptions),s=d.build_processing,a=d.build_type,u=d.build_source||r.data,c=t.debug(r,"build"),b=function(t){var o=e.type(t),n=t instanceof e;if("function"==typeof s&&(t=s(t,d)),r.data=t,n||"string"===o){if(n||/<\s*\/tr\s*>/.test(t))return l.html(i,t,d);try{if(t=e.parseJSON(t||"null"))return l.object(i,t,d)}catch(e){}}return"array"===o||"string"===o||"array"===a||"csv"===a?l.csv(i,t,d):l.object(i,t,d)};if(i.config=r,!t.buildTable.hasOwnProperty(a)&&""!==a)return c&&console.error("Build >> ERROR: Aborting build table widget, incorrect build type"),!1;u instanceof e?b(e.trim(u.html())):u&&(u.hasOwnProperty("url")||"json"===a)?e.ajax(d.build_source).done(function(e){b(e)}).fail(function(e,t){c&&console.error("Build >> ERROR: Aborting build table widget, failed ajax load"),n.html('<tr><td class="error">'+e.status+" "+t+"</td></tr>")}):b(u)};t.defaults.data="",l.defaults={build_type:"",build_source:"",build_processing:null,build_complete:"tablesorter-build-complete",build_headers:{rows:1,classes:[],text:[],widths:[]},build_footers:{rows:1,classes:[],text:[]},build_numbers:{addColumn:!1,sortable:!1},build_csvStartLine:0,build_csvSeparator:",",build_objectRowKey:"rows",build_objectCellKey:"cells",build_objectHeaderKey:"headers",build_objectFooterKey:"footers"},l.build={colgroup:function(t){var l="";return t&&t.length&&(l+="<colgroup>",e.each(t,function(e,t){l+="<col"+(t?' style="width:'+t+'"':"")+">"}),l+="</colgroup>"),l},cell:function(t,l,o,r,n){var i,d,s=n?e("<col>"):"",a=l.build_headers.classes,u=l.build_headers.widths;if(/string|number/.test(typeof t))d=e("<"+o+(a&&a[r]?' class="'+a[r]+'"':"")+">"+t+"</"+o+">"),n&&u&&u[r]&&s.width(u[r]||"");else{d=e("<"+o+">");for(i in t)t.hasOwnProperty(i)&&("text"===i||"html"===i?d[i](t[i]):n&&"width"===i?s.width(t[i]||""):d.attr(i,t[i]))}return[d,s]},header:function(t,l){var o=l.build_headers.text,r=l.build_headers.classes,n="<tr>"+(l.build_numbers.addColumn?"<th"+(l.build_numbers.sortable?"":' class="sorter-false"')+">"+l.build_numbers.addColumn+"</th>":"");return e.each(t,function(e,t){/<\s*\/t(d|h)\s*>/.test(t)?n+=t:n+="<th"+(r&&r[e]?' class="'+r[e]+'"':"")+">"+(o&&o[e]?o[e]:t)+"</th>"}),n+"</tr>"},rows:function(t,l,o,r,n,i){var d=i?"th":"td",s="<tr>"+(r.build_numbers.addColumn?"<"+d+">"+(i?"":n)+"</"+d+">":"");return e.each(t,function(e,t){/<\s*\/t(d|h)\s*>/.test(t)?s+=t:s+="<"+(i?d+(o&&o[e]?' class="'+o[e]+'"':""):d)+">"+(i&&l&&l.length&&l[e]?l[e]:t)+"</"+d+">"}),s+"</tr>"}},l.buildComplete=function(l,o){e(l).triggerHandler(o.build_complete),l.config&&t.debug(l.config,"build")&&console.log("Build >> Table build complete"),t.setup(l,l.config)},l.array=function(e,t,o){return l.csv(e,t,o)},l.csv=function(t,o,r){var n,i,d,s="csv"===r.build_type||"string"==typeof o,a=e(t),u=s?o.replace("\r","").split("\n"):o,c=u.length,b=0,h=!1,p=r.build_headers.rows+(s?r.build_csvStartLine:0),f=r.build_footers.rows,g=0,y="",_=l.build.colgroup(r.build_headers.widths)+"<thead>";e.each(u,function(e,t){e>=c-f&&(h=!0),(!s||e>=r.build_csvStartLine)&&e<p?(i=s?l.splitCSV(t,r.build_csvSeparator):t,g=i.length,_+=l.build.header(i,r)):e>=p&&(e===p&&(_+="</thead><tbody>"),d=s?l.splitCSV(t,r.build_csvSeparator):t,h&&f>0&&(_+=(e===c-f?"</tbody><tfoot>":"")+(e===c?"</tfoot>":"")),d.length>1&&(b++,d.length!==g&&(y+="error on line "+e+": Item count ("+d.length+") does not match header count ("+g+") \n"),n=h?r.build_footers.classes:"",_+=l.build.rows(d,r.build_footers.text,n,r,b,h)))}),_+=f>0?"":"</tbody>",y?a.html(y):(a.html(_),l.buildComplete(t,r))},l.splitCSV=function(t,l){var o,r,n=e.trim(t).split(l=l||",");for(o=n.length-1;o>=0;o--)'"'===n[o].replace(/\"\s+$/,'"').charAt(n[o].length-1)?(r=n[o].replace(/^\s+\"/,'"')).length>1&&'"'===r.charAt(0)?n[o]=n[o].replace(/^\s*"|"\s*$/g,"").replace(/""/g,'"'):o?n.splice(o-1,2,[n[o-1],n[o]].join(l)):n=n.shift().split(l).concat(
|