mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
6 lines
23 KiB
JavaScript
6 lines
23 KiB
JavaScript
/*!
|
|
* TableSorter 2.8.2 min - Client-side table sorting with ease!
|
|
* Copyright (c) 2007 Christian Bach
|
|
*/
|
|
!function(g){g.extend({tablesorter:new function(){function d(c){"undefined"!==typeof console&&"undefined"!==typeof console.log?console.log(c):alert(c)}function w(c,b){d(c+" ("+((new Date).getTime()-b.getTime())+"ms)")}function r(c,b,a){if(!b)return"";var e=c.config,d=e.textExtraction,j="",j="simple"===d?e.supportsTextContent?b.textContent:g(b).text():"function"===typeof d?d(b,c,a):"object"===typeof d&&d.hasOwnProperty(a)?d[a](b,c,a):e.supportsTextContent?b.textContent:g(b).text();return g.trim(j)} function l(c){var b=c.config,a=b.$tbodies=b.$table.children("tbody:not(."+b.cssInfoBlock+")"),e,t,j,h,k,p,m="";if(0===a.length)return b.debug?d("*Empty table!* Not building a parser cache"):"";a=a[0].rows;if(a[0]){e=[];t=a[0].cells.length;for(j=0;j<t;j++){h=b.$headers.filter(":not([colspan])");h=h.add(b.$headers.filter('[colspan="1"]')).filter('[data-column="'+j+'"]:last');k=b.headers[j];p=f.getParserById(f.getData(h,k,"sorter"));b.empties[j]=f.getData(h,k,"empty")||b.emptyTo||(b.emptyToBottom?"bottom": "top");b.strings[j]=f.getData(h,k,"string")||b.stringTo||"max";if(!p)a:{h=c;k=a;p=-1;for(var g=j,n=void 0,w=f.parsers.length,F=!1,C="",n=!0;""===C&&n;)p++,k[p]?(F=k[p].cells[g],C=r(h,F,g),h.config.debug&&d("Checking if value was empty on row "+p+", column: "+g+': "'+C+'"')):n=!1;for(;0<=--w;)if((n=f.parsers[w])&&"text"!==n.id&&n.is&&n.is(C,h,F)){p=n;break a}p=f.getParserById("text")}b.debug&&(m+="column:"+j+"; parser:"+p.id+"; string:"+b.strings[j]+"; empty: "+b.empties[j]+"\n");e.push(p)}}b.debug&& d(m);b.parsers=e}function s(c){var b=c.tBodies,a=c.config,e,t,j=a.parsers,h,k,p,m,q,n,G,l=[];a.cache={};if(!j)return a.debug?d("*Empty table!* Not building a cache"):"";a.debug&&(G=new Date);a.showProcessing&&f.isProcessing(c,!0);for(m=0;m<b.length;m++)if(a.cache[m]={row:[],normalized:[]},!g(b[m]).hasClass(a.cssInfoBlock)){e=b[m]&&b[m].rows.length||0;t=b[m].rows[0]&&b[m].rows[0].cells.length||0;for(k=0;k<e;++k)if(q=g(b[m].rows[k]),n=[],q.hasClass(a.cssChildRow))a.cache[m].row[a.cache[m].row.length- 1]=a.cache[m].row[a.cache[m].row.length-1].add(q);else{a.cache[m].row.push(q);for(p=0;p<t;++p)if(h=r(c,q[0].cells[p],p),h=j[p].format(h,c,q[0].cells[p],p),n.push(h),"numeric"===(j[p].type||"").toLowerCase())l[p]=Math.max(Math.abs(h),l[p]||0);n.push(a.cache[m].normalized.length);a.cache[m].normalized.push(n)}a.cache[m].colMax=l}a.showProcessing&&f.isProcessing(c);a.debug&&w("Building cache for "+e+" rows",G)}function v(c,b){var a=c.config,e=c.tBodies,d=[],j=a.cache,h,k,p,m,q,n,l,r,C,s,v;if(j[0]){a.debug&& (v=new Date);for(r=0;r<e.length;r++)if(h=g(e[r]),h.length&&!h.hasClass(a.cssInfoBlock)){q=f.processTbody(c,h,!0);h=j[r].row;k=j[r].normalized;m=(p=k.length)?k[0].length-1:0;for(n=0;n<p;n++)if(s=k[n][m],d.push(h[s]),!a.appender||!a.removeRows){C=h[s].length;for(l=0;l<C;l++)q.append(h[s][l])}f.processTbody(c,q,!1)}a.appender&&a.appender(c,d);a.debug&&w("Rebuilt table",v);b||f.applyWidget(c);g(c).trigger("sortEnd",c)}}function z(c){var b=[],a={},e=0,t=g(c).find("thead:eq(0), tfoot").children("tr"),j, h,k,p,m,q,n,l,r,s;for(j=0;j<t.length;j++){m=t[j].cells;for(h=0;h<m.length;h++){p=m[h];q=p.parentNode.rowIndex;n=q+"-"+p.cellIndex;l=p.rowSpan||1;r=p.colSpan||1;"undefined"===typeof b[q]&&(b[q]=[]);for(k=0;k<b[q].length+1;k++)if("undefined"===typeof b[q][k]){s=k;break}a[n]=s;e=Math.max(s,e);g(p).attr({"data-column":s});for(k=q;k<q+l;k++){"undefined"===typeof b[k]&&(b[k]=[]);n=b[k];for(p=s;p<s+r;p++)n[p]="x"}}}c.config.columns=e;var v,u,z,B,A,y,D,x=c.config;x.headerList=[];x.headerContent=[];x.debug&& (D=new Date);B=x.cssIcon?'<i class="'+x.cssIcon+'"></i>':"";x.$headers=g(c).find(x.selectorHeaders).each(function(c){u=g(this);v=x.headers[c];x.headerContent[c]=this.innerHTML;A=x.headerTemplate.replace(/\{content\}/g,this.innerHTML).replace(/\{icon\}/g,B);x.onRenderTemplate&&(z=x.onRenderTemplate.apply(u,[c,A]))&&"string"===typeof z&&(A=z);this.innerHTML='<div class="tablesorter-header-inner">'+A+"</div>";x.onRenderHeader&&x.onRenderHeader.apply(u,[c]);this.column=a[this.parentNode.rowIndex+"-"+ this.cellIndex];var b=f.getData(u,v,"sortInitialOrder")||x.sortInitialOrder;this.order=/^d/i.test(b)||1===b?[1,0,2]:[0,1,2];this.count=-1;this.lockedOrder=!1;y=f.getData(u,v,"lockedOrder")||!1;"undefined"!==typeof y&&!1!==y&&(this.order=this.lockedOrder=/^d/i.test(y)||1===y?[1,1,1]:[0,0,0]);u.addClass(x.cssHeader);x.headerList[c]=this;u.parent().addClass(x.cssHeaderRow)});E(c);x.debug&&(w("Built headers:",D),d(x.$headers))}function A(c,b,a){var e=g(c);e.find(c.config.selectorRemove).remove();l(c); s(c);D(e,b,a)}function E(c){var b,a=c.config;a.$headers.each(function(c,d){b="false"===f.getData(d,a.headers[c],"sorter");d.sortDisabled=b;g(d)[b?"addClass":"removeClass"]("sorter-false")})}function y(c){var b,a,e,d=c.config,j=d.sortList,h=[d.cssAsc,d.cssDesc],k=g(c).find("tfoot tr").children().removeClass(h.join(" "));d.$headers.removeClass(h.join(" "));e=j.length;for(b=0;b<e;b++)if(2!==j[b][1]&&(c=d.$headers.not(".sorter-false").filter('[data-column="'+j[b][0]+'"]'+(1===e?":last":"")),c.length))for(a= 0;a<c.length;a++)c[a].sortDisabled||(c.eq(a).addClass(h[j[b][1]]),k.length&&k.filter('[data-column="'+j[b][0]+'"]').eq(a).addClass(h[j[b][1]]))}function B(c){var b=0,a=c.config,e=a.sortList,d=e.length,j=c.tBodies.length,h,k,f,m,q,n,l,r,s;if(!a.serverSideSorting&&a.cache[0]){a.debug&&(h=new Date);for(f=0;f<j;f++)q=a.cache[f].colMax,s=(n=a.cache[f].normalized)&&n[0]?n[0].length-1:0,n.sort(function(j,h){for(k=0;k<d;k++){m=e[k][0];r=e[k][1];l=/n/i.test(a.parsers&&a.parsers[m]?a.parsers[m].type||"":"")? "Numeric":"Text";l+=0===r?"":"Desc";/Numeric/.test(l)&&a.strings[m]&&(b="boolean"===typeof a.string[a.strings[m]]?(0===r?1:-1)*(a.string[a.strings[m]]?-1:1):a.strings[m]?a.string[a.strings[m]]||0:0);var f=g.tablesorter["sort"+l](c,j[m],h[m],m,q[m],b);if(f)return f}return j[s]-h[s]});a.debug&&w("Sorting on "+e.toString()+" and dir "+r+" time",h)}}function H(c,b){c.trigger("updateComplete");"function"===typeof b&&b(c[0])}function D(c,b,a){!1!==b&&!c[0].isProcessing?c.trigger("sorton",[c[0].config.sortList, function(){H(c,a)}]):H(c,a)}function I(c){var b=c.config,a=g(c),e,d;b.$headers.find("*")[g.fn.addBack?"addBack":"andSelf"]().filter(b.selectorSort).unbind("mousedown.tablesorter mouseup.tablesorter").bind("mousedown.tablesorter mouseup.tablesorter",function(a,e){var k=(this.tagName.match("TH|TD")?g(this):g(this).parents("th, td").filter(":last"))[0];if(1!==(a.which||a.button))return!1;if("mousedown"===a.type)return d=(new Date).getTime(),"INPUT"===a.target.tagName?"":!b.cancelSelection;if(!0!==e&& 250<(new Date).getTime()-d)return!1;b.delayInit&&!b.cache&&s(c);if(!k.sortDisabled){var p,m,q,n=c.config,l=!a[n.sortMultiSortKey],r=g(c);r.trigger("sortStart",c);k.count=a[n.sortResetKey]?2:(k.count+1)%(n.sortReset?3:2);n.sortRestart&&(m=k,n.$headers.each(function(){if(this!==m&&(l||!g(this).is("."+n.cssDesc+",."+n.cssAsc)))this.count=-1}));m=k.column;if(l){n.sortList=[];if(null!==n.sortForce){p=n.sortForce;for(q=0;q<p.length;q++)p[q][0]!==m&&n.sortList.push(p[q])}p=k.order[k.count];if(2>p&&(n.sortList.push([m, p]),1<k.colSpan))for(q=1;q<k.colSpan;q++)n.sortList.push([m+q,p])}else if(n.sortAppend&&1<n.sortList.length&&f.isValueInArray(n.sortAppend[0][0],n.sortList)&&n.sortList.pop(),f.isValueInArray(m,n.sortList))for(q=0;q<n.sortList.length;q++)k=n.sortList[q],p=n.headerList[k[0]],k[0]===m&&(k[1]=p.order[p.count],2===k[1]&&(n.sortList.splice(q,1),p.count=-1));else if(p=k.order[k.count],2>p&&(n.sortList.push([m,p]),1<k.colSpan))for(q=1;q<k.colSpan;q++)n.sortList.push([m+q,p]);if(null!==n.sortAppend){p=n.sortAppend; for(q=0;q<p.length;q++)p[q][0]!==m&&n.sortList.push(p[q])}r.trigger("sortBegin",c);setTimeout(function(){y(c);B(c);v(c)},1)}});b.cancelSelection&&b.$headers.each(function(){this.onselectstart=function(){return!1}});a.unbind("sortReset update updateRows updateCell updateAll addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave ".split(" ").join(".tablesorter ")).bind("sortReset.tablesorter",function(a){a.stopPropagation();b.sortList=[];y(c);B(c);v(c)}).bind("updateAll.tablesorter", function(a,b,e){a.stopPropagation();f.restoreHeaders(c);z(c);I(c);A(c,b,e)}).bind("update.tablesorter updateRows.tablesorter",function(a,b,e){a.stopPropagation();E(c);A(c,b,e)}).bind("updateCell.tablesorter",function(e,d,f,p){e.stopPropagation();a.find(b.selectorRemove).remove();var m,q,n;m=a.find("tbody");e=m.index(g(d).parents("tbody").filter(":last"));var t=g(d).parents("tr").filter(":last");d=g(d)[0];m.length&&0<=e&&(q=m.eq(e).find("tr").index(t),n=d.cellIndex,m=b.cache[e].normalized[q].length- 1,b.cache[e].row[c.config.cache[e].normalized[q][m]]=t,b.cache[e].normalized[q][n]=b.parsers[n].format(r(c,d,n),c,d,n),D(a,f,p))}).bind("addRows.tablesorter",function(d,h,f,g){d.stopPropagation();var m=h.filter("tr").length,t=[],n=h[0].cells.length,w=a.find("tbody").index(h.closest("tbody"));b.parsers||l(c);for(d=0;d<m;d++){for(e=0;e<n;e++)t[e]=b.parsers[e].format(r(c,h[d].cells[e],e),c,h[d].cells[e],e);t.push(b.cache[w].row.length);b.cache[w].row.push([h[d]]);b.cache[w].normalized.push(t);t=[]}D(a, f,g)}).bind("sorton.tablesorter",function(b,e,d,f){b.stopPropagation();a.trigger("sortStart",this);var m,t,n,l=c.config;b=e||l.sortList;l.sortList=[];g.each(b,function(a,c){m=[parseInt(c[0],10),parseInt(c[1],10)];if(n=l.headerList[m[0]])l.sortList.push(m),t=g.inArray(m[1],n.order),n.count=0<=t?t:m[1]%(l.sortReset?3:2)});y(c);B(c);v(c,f);"function"===typeof d&&d(c)}).bind("appendCache.tablesorter",function(a,b,e){a.stopPropagation();v(c,e);"function"===typeof b&&b(c)}).bind("applyWidgetId.tablesorter", function(a,e){a.stopPropagation();f.getWidgetById(e).format(c,b,b.widgetOptions)}).bind("applyWidgets.tablesorter",function(a,b){a.stopPropagation();f.applyWidget(c,b)}).bind("refreshWidgets.tablesorter",function(a,b,e){a.stopPropagation();f.refreshWidgets(c,b,e)}).bind("destroy.tablesorter",function(a,b,e){a.stopPropagation();f.destroy(c,b,e)})}var f=this;f.version="2.8.2";f.parsers=[];f.widgets=[];f.defaults={theme:"default",widthFixed:!1,showProcessing:!1,headerTemplate:"{content}",onRenderTemplate:null, onRenderHeader:null,cancelSelection:!0,dateFormat:"mmddyyyy",sortMultiSortKey:"shiftKey",sortResetKey:"ctrlKey",usNumberFormat:!0,delayInit:!1,serverSideSorting:!1,headers:{},ignoreCase:!0,sortForce:null,sortList:[],sortAppend:null,sortInitialOrder:"asc",sortLocaleCompare:!1,sortReset:!1,sortRestart:!1,emptyTo:"bottom",stringTo:"max",textExtraction:"simple",textSorter:null,widgets:[],widgetOptions:{zebra:["even","odd"]},initWidgets:!0,initialized:null,tableClass:"tablesorter",cssAsc:"tablesorter-headerAsc", cssChildRow:"tablesorter-childRow",cssDesc:"tablesorter-headerDesc",cssHeader:"tablesorter-header",cssHeaderRow:"tablesorter-headerRow",cssIcon:"tablesorter-icon",cssInfoBlock:"tablesorter-infoOnly",cssProcessing:"tablesorter-processing",selectorHeaders:"> thead th, > thead td",selectorSort:"th, td",selectorRemove:".remove-me",debug:!1,headerList:[],empties:{},strings:{},parsers:[]};f.benchmark=w;f.construct=function(c){return this.each(function(){if(!this.tHead||0===this.tBodies.length||!0===this.hasInitialized)return this.config&& this.config.debug?d("stopping initialization! No thead, tbody or tablesorter has already been initialized"):"";var b=g(this),a=this,e,t="",j=g.metadata;a.hasInitialized=!1;a.isProcessing=!0;a.config={};e=g.extend(!0,a.config,f.defaults,c);g.data(a,"tablesorter",e);e.debug&&g.data(a,"startoveralltimer",new Date);e.supportsTextContent="x"===g("<span>x</span>")[0].textContent;e.supportsDataObject=1.4<=parseFloat(g.fn.jquery);e.string={max:1,min:-1,"max+":1,"max-":-1,zero:0,none:0,"null":0,top:!0,bottom:!1}; /tablesorter\-/.test(b.attr("class"))||(t=""!==e.theme?" tablesorter-"+e.theme:"");e.$table=b.addClass(e.tableClass+t);e.$tbodies=b.children("tbody:not(."+e.cssInfoBlock+")");z(a);if(a.config.widthFixed&&0===g(a).find("colgroup").length){var h=g("<colgroup>"),k=g(a).width();g(a.tBodies[0]).find("tr:first").children("td").each(function(){h.append(g("<col>").css("width",parseInt(1E3*(g(this).width()/k),10)/10+"%"))});g(a).prepend(h)}l(a);e.delayInit||s(a);I(a);e.supportsDataObject&&"undefined"!==typeof b.data().sortlist? e.sortList=b.data().sortlist:j&&(b.metadata()&&b.metadata().sortlist)&&(e.sortList=b.metadata().sortlist);f.applyWidget(a,!0);0<e.sortList.length?b.trigger("sorton",[e.sortList,{},!e.initWidgets]):e.initWidgets&&f.applyWidget(a);e.showProcessing&&b.unbind("sortBegin.tablesorter sortEnd.tablesorter").bind("sortBegin.tablesorter sortEnd.tablesorter",function(b){f.isProcessing(a,"sortBegin"===b.type)});a.hasInitialized=!0;a.isProcessing=!1;e.debug&&f.benchmark("Overall initialization time",g.data(a, "startoveralltimer"));b.trigger("tablesorter-initialized",a);"function"===typeof e.initialized&&e.initialized(a)})};f.isProcessing=function(c,b,a){c=g(c);var e=c[0].config;c=a||c.find("."+e.cssHeader);b?(0<e.sortList.length&&(c=c.filter(function(){return this.sortDisabled?!1:f.isValueInArray(parseFloat(g(this).attr("data-column")),e.sortList)})),c.addClass(e.cssProcessing)):c.removeClass(e.cssProcessing)};f.processTbody=function(c,b,a){if(a)return c.isProcessing=!0,b.before('<span class="tablesorter-savemyplace"/>'), a=g.fn.detach?b.detach():b.remove();a=g(c).find("span.tablesorter-savemyplace");b.insertAfter(a);a.remove();c.isProcessing=!1};f.clearTableBody=function(c){g(c)[0].config.$tbodies.empty()};f.restoreHeaders=function(c){var b=c.config;b.$headers.each(function(a){g(this).find(".tablesorter-header-inner").length&&g(this).html(b.headerContent[a])})};f.destroy=function(c,b,a){c=g(c)[0];if(c.hasInitialized){f.refreshWidgets(c,!0,!0);var e=g(c),d=c.config,j=e.find("thead:first"),h=j.find("tr."+d.cssHeaderRow).removeClass(d.cssHeaderRow), k=e.find("tfoot:first > tr").children("th, td");j.find("tr").not(h).remove();e.removeData("tablesorter").unbind("sortReset update updateAll updateRows updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave sortBegin sortEnd ".split(" ").join(".tablesorter "));d.$headers.add(k).removeClass(d.cssHeader+" "+d.cssAsc+" "+d.cssDesc).removeAttr("data-column");h.find(d.selectorSort).unbind("mousedown.tablesorter mouseup.tablesorter");f.restoreHeaders(c); !1!==b&&e.removeClass(d.tableClass+" tablesorter-"+d.theme);c.hasInitialized=!1;"function"===typeof a&&a(c)}};f.regex=[/(^([+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?)?$|^0x[0-9a-f]+$|\d+)/gi,/(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/,/^0x[0-9a-f]+$/i];f.sortText=function(c,b,a,e){if(b===a)return 0;var d=c.config,j=d.string[d.empties[e]||d.emptyTo],h=f.regex;if(""===b&&0!==j)return"boolean"===typeof j?j?-1:1:-j||-1;if(""=== a&&0!==j)return"boolean"===typeof j?j?1:-1:j||1;if("function"===typeof d.textSorter)return d.textSorter(b,a,c,e);c=b.replace(h[0],"\\0$1\\0").replace(/\\0$/,"").replace(/^\\0/,"").split("\\0");e=a.replace(h[0],"\\0$1\\0").replace(/\\0$/,"").replace(/^\\0/,"").split("\\0");b=parseInt(b.match(h[2]),16)||1!==c.length&&b.match(h[1])&&Date.parse(b);if(a=parseInt(a.match(h[2]),16)||b&&a.match(h[1])&&Date.parse(a)||null){if(b<a)return-1;if(b>a)return 1}d=Math.max(c.length,e.length);for(b=0;b<d;b++){a=isNaN(c[b])? c[b]||0:parseFloat(c[b])||0;h=isNaN(e[b])?e[b]||0:parseFloat(e[b])||0;if(isNaN(a)!==isNaN(h))return isNaN(a)?1:-1;typeof a!==typeof h&&(a+="",h+="");if(a<h)return-1;if(a>h)return 1}return 0};f.sortTextDesc=function(c,b,a,e){if(b===a)return 0;var d=c.config,j=d.string[d.empties[e]||d.emptyTo];return""===b&&0!==j?"boolean"===typeof j?j?-1:1:j||1:""===a&&0!==j?"boolean"===typeof j?j?1:-1:-j||-1:"function"===typeof d.textSorter?d.textSorter(a,b,c,e):f.sortText(c,a,b)};f.getTextValue=function(c,b,a){if(b){var e= c?c.length:0,d=b+a;for(b=0;b<e;b++)d+=c.charCodeAt(b);return a*d}return 0};f.sortNumeric=function(c,b,a,e,d,j){if(b===a)return 0;c=c.config;e=c.string[c.empties[e]||c.emptyTo];if(""===b&&0!==e)return"boolean"===typeof e?e?-1:1:-e||-1;if(""===a&&0!==e)return"boolean"===typeof e?e?1:-1:e||1;isNaN(b)&&(b=f.getTextValue(b,d,j));isNaN(a)&&(a=f.getTextValue(a,d,j));return b-a};f.sortNumericDesc=function(c,b,a,d,g,j){if(b===a)return 0;c=c.config;d=c.string[c.empties[d]||c.emptyTo];if(""===b&&0!==d)return"boolean"=== typeof d?d?-1:1:d||1;if(""===a&&0!==d)return"boolean"===typeof d?d?1:-1:-d||-1;isNaN(b)&&(b=f.getTextValue(b,g,j));isNaN(a)&&(a=f.getTextValue(a,g,j));return a-b};f.characterEquivalents={a:"\u00e1\u00e0\u00e2\u00e3\u00e4\u0105\u00e5",A:"\u00c1\u00c0\u00c2\u00c3\u00c4\u0104\u00c5",c:"\u00e7\u0107\u010d",C:"\u00c7\u0106\u010c",e:"\u00e9\u00e8\u00ea\u00eb\u011b\u0119",E:"\u00c9\u00c8\u00ca\u00cb\u011a\u0118",i:"\u00ed\u00ec\u0130\u00ee\u00ef\u0131",I:"\u00cd\u00cc\u0130\u00ce\u00cf",o:"\u00f3\u00f2\u00f4\u00f5\u00f6", O:"\u00d3\u00d2\u00d4\u00d5\u00d6",ss:"\u00df",SS:"\u1e9e",u:"\u00fa\u00f9\u00fb\u00fc\u016f",U:"\u00da\u00d9\u00db\u00dc\u016e"};f.replaceAccents=function(c){var b,a="[",d=f.characterEquivalents;if(!f.characterRegex){f.characterRegexArray={};for(b in d)"string"===typeof b&&(a+=d[b],f.characterRegexArray[b]=RegExp("["+d[b]+"]","g"));f.characterRegex=RegExp(a+"]")}if(f.characterRegex.test(c))for(b in d)"string"===typeof b&&(c=c.replace(f.characterRegexArray[b],b));return c};f.isValueInArray=function(c, b){var a,d=b.length;for(a=0;a<d;a++)if(b[a][0]===c)return!0;return!1};f.addParser=function(c){var b,a=f.parsers.length,d=!0;for(b=0;b<a;b++)f.parsers[b].id.toLowerCase()===c.id.toLowerCase()&&(d=!1);d&&f.parsers.push(c)};f.getParserById=function(c){var b,a=f.parsers.length;for(b=0;b<a;b++)if(f.parsers[b].id.toLowerCase()===c.toString().toLowerCase())return f.parsers[b];return!1};f.addWidget=function(c){f.widgets.push(c)};f.getWidgetById=function(c){var b,a,d=f.widgets.length;for(b=0;b<d;b++)if((a= f.widgets[b])&&a.hasOwnProperty("id")&&a.id.toLowerCase()===c.toLowerCase())return a};f.applyWidget=function(c,b){c=g(c)[0];var a=c.config,d=a.widgetOptions,l=a.widgets.sort().reverse(),j,h,k,p=l.length;h=g.inArray("zebra",a.widgets);0<=h&&(a.widgets.splice(h,1),a.widgets.push("zebra"));a.debug&&(j=new Date);for(h=0;h<p;h++)if(k=f.getWidgetById(l[h]))b?(k.hasOwnProperty("options")&&g.extend(!0,k.options,d),k.hasOwnProperty("init")&&k.init(c,k,a,d)):!b&&k.hasOwnProperty("format")&&k.format(c,a,d,!1); a.debug&&w("Completed "+(!0===b?"initializing":"applying")+" widgets",j)};f.refreshWidgets=function(c,b,a){c=g(c)[0];var e,l=c.config,j=l.widgets,h=f.widgets,k=h.length;for(e=0;e<k;e++)if(h[e]&&h[e].id&&(b||0>g.inArray(h[e].id,j)))l.debug&&d("Refeshing widgets: Removing "+h[e].id),h[e].hasOwnProperty("remove")&&h[e].remove(c,l,l.widgetOptions);!0!==a&&f.applyWidget(c,b)};f.getData=function(c,b,a){var d="";c=g(c);var f,j;if(!c.length)return"";f=g.metadata?c.metadata():!1;j=" "+(c.attr("class")||""); "undefined"!==typeof c.data(a)||"undefined"!==typeof c.data(a.toLowerCase())?d+=c.data(a)||c.data(a.toLowerCase()):f&&"undefined"!==typeof f[a]?d+=f[a]:b&&"undefined"!==typeof b[a]?d+=b[a]:" "!==j&&j.match(" "+a+"-")&&(d=j.match(RegExp("\\s"+a+"-([\\w-]+)"))[1]||"");return g.trim(d)};f.formatFloat=function(c,b){if("string"!==typeof c||""===c)return c;var a;c=(b&&b.config?!1!==b.config.usNumberFormat:"undefined"!==typeof b?b:1)?c.replace(/,/g,""):c.replace(/[\s|\.]/g,"").replace(/,/g,".");/^\s*\([.\d]+\)/.test(c)&& (c=c.replace(/^\s*\(/,"-").replace(/\)/,""));a=parseFloat(c);return isNaN(a)?g.trim(c):a};f.isDigit=function(c){return isNaN(c)?/^[\-+(]?\d+[)]?$/.test(c.toString().replace(/[,.'"\s]/g,"")):!0}}});var l=g.tablesorter;g.fn.extend({tablesorter:l.construct});l.addParser({id:"text",is:function(){return!0},format:function(d,w){var r=w.config;d&&(d=g.trim(r.ignoreCase?d.toLocaleLowerCase():d),d=r.sortLocaleCompare?l.replaceAccents(d):d);return d},type:"text"});l.addParser({id:"digit",is:function(d){return l.isDigit(d)}, format:function(d,g){return d?l.formatFloat(d.replace(/[^\w,. \-()]/g,""),g):d},type:"numeric"});l.addParser({id:"currency",is:function(d){return/^\(?\d+[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]|[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+\)?$/.test((d||"").replace(/[,. ]/g,""))},format:function(d,g){return d?l.formatFloat(d.replace(/[^\w,. \-()]/g,""),g):d},type:"numeric"});l.addParser({id:"ipAddress",is:function(d){return/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(d)},format:function(d,g){var r,u=d?d.split("."): "",s="",v=u.length;for(r=0;r<v;r++)s+=("00"+u[r]).slice(-3);return d?l.formatFloat(s,g):d},type:"numeric"});l.addParser({id:"url",is:function(d){return/^(https?|ftp|file):\/\//.test(d)},format:function(d){return d?g.trim(d.replace(/(https?|ftp|file):\/\//,"")):d},type:"text"});l.addParser({id:"isoDate",is:function(d){return/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/.test(d)},format:function(d,g){return d?l.formatFloat(""!==d?(new Date(d.replace(/-/g,"/"))).getTime()||"":"",g):d},type:"numeric"});l.addParser({id:"percent", is:function(d){return/(\d\s?%|%\s?\d)/.test(d)},format:function(d,g){return d?l.formatFloat(d.replace(/%/g,""),g):d},type:"numeric"});l.addParser({id:"usLongDate",is:function(d){return/^[A-Z]{3,10}\.?\s+\d{1,2},?\s+(\d{4})(\s+\d{1,2}:\d{2}(:\d{2})?(\s+[AP]M)?)?$/i.test(d)||/^\d{1,2}\s+[A-Z]{3,10}\s+\d{4}/i.test(d)},format:function(d,g){return d?l.formatFloat((new Date(d.replace(/(\S)([AP]M)$/i,"$1 $2"))).getTime()||"",g):d},type:"numeric"});l.addParser({id:"shortDate",is:function(d){return/(^\d{1,2}[\/\s]\d{1,2}[\/\s]\d{4})|(^\d{4}[\/\s]\d{1,2}[\/\s]\d{1,2})/.test((d|| "").replace(/\s+/g," ").replace(/[\-.,]/g,"/"))},format:function(d,g,r,u){if(d){r=g.config;var s=r.headerList[u],v=s.shortDateFormat;"undefined"===typeof v&&(v=s.shortDateFormat=l.getData(s,r.headers[u],"dateFormat")||r.dateFormat);d=d.replace(/\s+/g," ").replace(/[\-.,]/g,"/");"mmddyyyy"===v?d=d.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,"$3/$1/$2"):"ddmmyyyy"===v?d=d.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,"$3/$2/$1"):"yyyymmdd"===v&&(d=d.replace(/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/, "$1/$2/$3"))}return d?l.formatFloat((new Date(d)).getTime()||"",g):d},type:"numeric"});l.addParser({id:"time",is:function(d){return/^(([0-2]?\d:[0-5]\d)|([0-1]?\d:[0-5]\d\s?([AP]M)))$/i.test(d)},format:function(d,g){return d?l.formatFloat((new Date("2000/01/01 "+d.replace(/(\S)([AP]M)$/i,"$1 $2"))).getTime()||"",g):d},type:"numeric"});l.addParser({id:"metadata",is:function(){return!1},format:function(d,l,r){d=l.config;d=!d.parserMetadataName?"sortValue":d.parserMetadataName;return g(r).metadata()[d]}, type:"numeric"});l.addWidget({id:"zebra",format:function(d,w,r){var u,s,v,z,A,E,y=RegExp(w.cssChildRow,"i"),B=w.$tbodies;w.debug&&(A=new Date);for(d=0;d<B.length;d++)u=B.eq(d),E=u.children("tr").length,1<E&&(v=0,u=u.children("tr:visible"),u.each(function(){s=g(this);y.test(this.className)||v++;z=0===v%2;s.removeClass(r.zebra[z?1:0]).addClass(r.zebra[z?0:1])}));w.debug&&l.benchmark("Applying Zebra widget",A)},remove:function(d,l,r){var u;l=l.$tbodies;var s=(r.zebra||["even","odd"]).join(" ");for(r= 0;r<l.length;r++)u=g.tablesorter.processTbody(d,l.eq(r),!0),u.children().removeClass(s),g.tablesorter.processTbody(d,u,!1)}})}(jQuery);
|