]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - js/jquery.tablesorter.min.js
Add plain API format
[Github/YOURLS.git] / js / jquery.tablesorter.min.js
1 /*!
2 * TableSorter 2.7.6 min - Client-side table sorting with ease!
3 * Copyright (c) 2007 Christian Bach
4 *
5 * https://github.com/Mottie/tablesorter/
6 * Dual licensed under the MIT and GPL licenses.
7 */
8 !function(j){j.extend({tablesorter:new function(){function e(d){"undefined"!==typeof console&&"undefined"!==typeof console.log?console.log(d):alert(d)}function v(d,c){e(d+" ("+((new Date).getTime()-c.getTime())+"ms)")}function p(d,c,a){if(!c)return"";var b=d.config,g=b.textExtraction,f="",f="simple"===g?b.supportsTextContent?c.textContent:j(c).text():"function"===typeof g?g(c,d,a):"object"===typeof g&&g.hasOwnProperty(a)?g[a](c,d,a):b.supportsTextContent?c.textContent:j(c).text();return j.trim(f)} function h(d){var c=d.config,a=c.$tbodies=c.$table.children("tbody:not(."+c.cssInfoBlock+")"),b,q,f,l,j,n,k="";if(0===a.length)return c.debug?e("*Empty table!* Not building a parser cache"):"";a=a[0].rows;if(a[0]){b=[];q=a[0].cells.length;for(f=0;f<q;f++){l=c.$headers.filter(":not([colspan])");l=l.add(c.$headers.filter('[colspan="1"]')).filter('[data-column="'+f+'"]:last');j=c.headers[f];n=g.getParserById(g.getData(l,j,"sorter"));c.empties[f]=g.getData(l,j,"empty")||c.emptyTo||(c.emptyToBottom?"bottom": "top");c.strings[f]=g.getData(l,j,"string")||c.stringTo||"max";if(!n)a:{l=d;j=a;n=-1;for(var v=f,x=void 0,t=g.parsers.length,y=!1,m="",x=!0;""===m&&x;)n++,j[n]?(y=j[n].cells[v],m=p(l,y,v),l.config.debug&&e("Checking if value was empty on row "+n+", column: "+v+": "+m)):x=!1;for(x=1;x<t;x++)if(g.parsers[x].is&&g.parsers[x].is(m,l,y)){n=g.parsers[x];break a}n=g.parsers[0]}c.debug&&(k+="column:"+f+"; parser:"+n.id+"; string:"+c.strings[f]+"; empty: "+c.empties[f]+"\n");b.push(n)}}c.debug&&e(k);return b} function s(d){var c=d.tBodies,a=d.config,b,q,f=a.parsers,l,u,n,k,h,x,t,m=[];a.cache={};if(!f)return a.debug?e("*Empty table!* Not building a cache"):"";a.debug&&(t=new Date);a.showProcessing&&g.isProcessing(d,!0);for(k=0;k<c.length;k++)if(a.cache[k]={row:[],normalized:[]},!j(c[k]).hasClass(a.cssInfoBlock)){b=c[k]&&c[k].rows.length||0;q=c[k].rows[0]&&c[k].rows[0].cells.length||0;for(u=0;u<b;++u)if(h=j(c[k].rows[u]),x=[],h.hasClass(a.cssChildRow))a.cache[k].row[a.cache[k].row.length-1]=a.cache[k].row[a.cache[k].row.length- 1].add(h);else{a.cache[k].row.push(h);for(n=0;n<q;++n)if(l=p(d,h[0].cells[n],n),l=f[n].format(l,d,h[0].cells[n],n),x.push(l),"numeric"===(f[n].type||"").toLowerCase())m[n]=Math.max(Math.abs(l),m[n]||0);x.push(a.cache[k].normalized.length);a.cache[k].normalized.push(x)}a.cache[k].colMax=m}a.showProcessing&&g.isProcessing(d);a.debug&&v("Building cache for "+b+" rows",t)}function m(d,c){var a=d.config,b=d.tBodies,q=[],f=a.cache,e,u,n,k,h,p,m,y,s,r,E;if(f[0]){a.debug&&(E=new Date);for(y=0;y<b.length;y++)if(e= j(b[y]),!e.hasClass(a.cssInfoBlock)){h=g.processTbody(d,e,!0);e=f[y].row;u=f[y].normalized;k=(n=u.length)?u[0].length-1:0;for(p=0;p<n;p++)if(r=u[p][k],q.push(e[r]),!a.appender||!a.removeRows){s=e[r].length;for(m=0;m<s;m++)h.append(e[r][m])}g.processTbody(d,h,!1)}a.appender&&a.appender(d,q);a.debug&&v("Rebuilt table",E);c||g.applyWidget(d);j(d).trigger("sortEnd",d)}}function F(d){var c,a,b,g=d.config,f=g.sortList,e=[g.cssAsc,g.cssDesc],h=j(d).find("tfoot tr").children().removeClass(e.join(" "));g.$headers.removeClass(e.join(" ")); b=f.length;for(c=0;c<b;c++)if(2!==f[c][1]&&(d=g.$headers.not(".sorter-false").filter('[data-column="'+f[c][0]+'"]'+(1===b?":last":"")),d.length))for(a=0;a<d.length;a++)d[a].sortDisabled||(d.eq(a).addClass(e[f[c][1]]),h.length&&h.filter('[data-column="'+f[c][0]+'"]').eq(a).addClass(e[f[c][1]]))}function G(d){var c=0,a=d.config,b=a.sortList,g=b.length,f=d.tBodies.length,e,h,n,k,p,m,t,r,s;if(!a.serverSideSorting&&a.cache[0]){a.debug&&(e=new Date);for(n=0;n<f;n++)p=a.cache[n].colMax,s=(m=a.cache[n].normalized)&& m[0]?m[0].length-1:0,m.sort(function(f,e){for(h=0;h<g;h++){k=b[h][0];r=b[h][1];t=/n/i.test(a.parsers&&a.parsers[k]?a.parsers[k].type||"":"")?"Numeric":"Text";t+=0===r?"":"Desc";/Numeric/.test(t)&&a.strings[k]&&(c="boolean"===typeof a.string[a.strings[k]]?(0===r?1:-1)*(a.string[a.strings[k]]?-1:1):a.strings[k]?a.string[a.strings[k]]||0:0);var l=j.tablesorter["sort"+t](d,f[k],e[k],k,p[k],c);if(l)return l}return f[s]-e[s]});a.debug&&v("Sorting on "+b.toString()+" and dir "+r+" time",e)}}function C(d, c){d.trigger("updateComplete");"function"===typeof c&&c(d[0])}function I(d,c,a){!1!==c?d.trigger("sorton",[d[0].config.sortList,function(){C(d,a)}]):C(d,a)}var g=this;g.version="2.7.6";g.parsers=[];g.widgets=[];g.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:[]};g.benchmark=v;g.construct=function(d){return this.each(function(){if(!this.tHead||0===this.tBodies.length||!0===this.hasInitialized)return this.config&&this.config.debug?e("stopping initialization! No thead, tbody or tablesorter has already been initialized"):"";var c=j(this),a=this,b,q,f,l="",u,n,k,C,x=j.metadata; a.hasInitialized=!1;a.config={};b=j.extend(!0,a.config,g.defaults,d);j.data(a,"tablesorter",b);b.debug&&j.data(a,"startoveralltimer",new Date);b.supportsTextContent="x"===j("<span>x</span>")[0].textContent;b.supportsDataObject=1.4<=parseFloat(j.fn.jquery);b.string={max:1,min:-1,"max+":1,"max-":-1,zero:0,none:0,"null":0,top:!0,bottom:!1};/tablesorter\-/.test(c.attr("class"))||(l=""!==b.theme?" tablesorter-"+b.theme:"");b.$table=c.addClass(b.tableClass+l);b.$tbodies=c.children("tbody:not(."+b.cssInfoBlock+ ")");var t=[],y={},Q=0,V=j(a).find("thead:eq(0), tfoot").children("tr"),E,L,z,A,R,D,M,W,X,H;for(E=0;E<V.length;E++){R=V[E].cells;for(L=0;L<R.length;L++){A=R[L];D=A.parentNode.rowIndex;M=D+"-"+A.cellIndex;W=A.rowSpan||1;X=A.colSpan||1;"undefined"===typeof t[D]&&(t[D]=[]);for(z=0;z<t[D].length+1;z++)if("undefined"===typeof t[D][z]){H=z;break}y[M]=H;Q=Math.max(H,Q);j(A).attr({"data-column":H});for(z=D;z<D+W;z++){"undefined"===typeof t[z]&&(t[z]=[]);M=t[z];for(A=H;A<H+X;A++)M[A]="x"}}}a.config.columns= Q;var N,B,S,Y,O,J,K,w=a.config;w.headerList=[];w.headerContent=[];w.debug&&(K=new Date);Y=w.cssIcon?'<i class="'+w.cssIcon+'"></i>':"";t=j(a).find(w.selectorHeaders).each(function(a){B=j(this);N=w.headers[a];w.headerContent[a]=this.innerHTML;O=w.headerTemplate.replace(/\{content\}/g,this.innerHTML).replace(/\{icon\}/g,Y);w.onRenderTemplate&&(S=w.onRenderTemplate.apply(B,[a,O]))&&"string"===typeof S&&(O=S);this.innerHTML='<div class="tablesorter-header-inner">'+O+"</div>";w.onRenderHeader&&w.onRenderHeader.apply(B, [a]);this.column=y[this.parentNode.rowIndex+"-"+this.cellIndex];var b=g.getData(B,N,"sortInitialOrder")||w.sortInitialOrder;this.order=/^d/i.test(b)||1===b?[1,0,2]:[0,1,2];this.count=-1;"false"===g.getData(B,N,"sorter")?(this.sortDisabled=!0,B.addClass("sorter-false")):B.removeClass("sorter-false");this.lockedOrder=!1;J=g.getData(B,N,"lockedOrder")||!1;"undefined"!==typeof J&&!1!==J&&(this.order=this.lockedOrder=/^d/i.test(J)||1===J?[1,1,1]:[0,0,0]);B.addClass((this.sortDisabled?"sorter-false ":" ")+ w.cssHeader);w.headerList[a]=this;B.parent().addClass(w.cssHeaderRow)});a.config.debug&&(v("Built headers:",K),e(t));b.$headers=t;var T,P=a.config,U=j("<colgroup>");K=P.$table.find("colgroup");var Z=P.$table.width();j("tr:first td",a.tBodies[0]).each(function(){T=j("<col>");P.widthFixed&&T.css("width",parseInt(1E3*(j(this).width()/Z),10)/10+"%");U.append(T)});K.length?K.html(U.html()):P.$table.prepend(U);b.parsers=h(a);b.delayInit||s(a);b.$headers.find("*").andSelf().filter(b.selectorSort).unbind("mousedown.tablesorter mouseup.tablesorter").bind("mousedown.tablesorter mouseup.tablesorter", function(d,e){var h=(this.tagName.match("TH|TD")?j(this):j(this).parents("th, td").filter(":last"))[0];if(1!==(d.which||d.button))return!1;if("mousedown"===d.type)return C=(new Date).getTime(),"INPUT"===d.target.tagName?"":!b.cancelSelection;if(!0!==e&&250<(new Date).getTime()-C)return!1;b.delayInit&&!b.cache&&s(a);if(!h.sortDisabled){c.trigger("sortStart",a);l=!d[b.sortMultiSortKey];h.count=d[b.sortResetKey]?2:(h.count+1)%(b.sortReset?3:2);b.sortRestart&&(q=h,b.$headers.each(function(){if(this!== q&&(l||!j(this).is("."+b.cssDesc+",."+b.cssAsc)))this.count=-1}));q=h.column;if(l){b.sortList=[];if(null!==b.sortForce){u=b.sortForce;for(f=0;f<u.length;f++)u[f][0]!==q&&b.sortList.push(u[f])}k=h.order[h.count];if(2>k&&(b.sortList.push([q,k]),1<h.colSpan))for(f=1;f<h.colSpan;f++)b.sortList.push([q+f,k])}else if(b.sortAppend&&1<b.sortList.length&&g.isValueInArray(b.sortAppend[0][0],b.sortList)&&b.sortList.pop(),g.isValueInArray(q,b.sortList))for(f=0;f<b.sortList.length;f++)n=b.sortList[f],k=b.headerList[n[0]], n[0]===q&&(n[1]=k.order[k.count],2===n[1]&&(b.sortList.splice(f,1),k.count=-1));else if(k=h.order[h.count],2>k&&(b.sortList.push([q,k]),1<h.colSpan))for(f=1;f<h.colSpan;f++)b.sortList.push([q+f,k]);if(null!==b.sortAppend){u=b.sortAppend;for(f=0;f<u.length;f++)u[f][0]!==q&&b.sortList.push(u[f])}c.trigger("sortBegin",a);setTimeout(function(){F(a);G(a);m(a)},1)}});b.cancelSelection&&b.$headers.each(function(){this.onselectstart=function(){return!1}});c.unbind("sortReset update updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave").bind("sortReset", function(){b.sortList=[];F(a);G(a);m(a)}).bind("update updateRows",function(d,f,g){j(b.selectorRemove,a).remove();b.parsers=h(a);s(a);I(c,f,g)}).bind("updateCell",function(d,f,g,e){var q,h,l;q=c.find("tbody");d=q.index(j(f).parents("tbody").filter(":last"));var k=j(f).parents("tr").filter(":last");f=j(f)[0];q.length&&0<=d&&(h=q.eq(d).find("tr").index(k),l=f.cellIndex,q=a.config.cache[d].normalized[h].length-1,a.config.cache[d].row[a.config.cache[d].normalized[h][q]]=k,a.config.cache[d].normalized[h][l]= b.parsers[l].format(p(a,f,l),a,f,l),I(c,g,e))}).bind("addRows",function(d,g,e,q){var l=g.filter("tr").length,j=[],k=g[0].cells.length,n=c.find("tbody").index(g.closest("tbody"));b.parsers||(b.parsers=h(a));for(d=0;d<l;d++){for(f=0;f<k;f++)j[f]=b.parsers[f].format(p(a,g[d].cells[f],f),a,g[d].cells[f],f);j.push(b.cache[n].row.length);b.cache[n].row.push([g[d]]);b.cache[n].normalized.push(j);j=[]}I(c,e,q)}).bind("sorton",function(b,d,f,g){c.trigger("sortStart",this);var e,q,h,l=a.config;b=d||l.sortList; l.sortList=[];j.each(b,function(a,b){e=[parseInt(b[0],10),parseInt(b[1],10)];if(h=l.headerList[e[0]])l.sortList.push(e),q=j.inArray(e[1],h.order),h.count=0<=q?q:e[1]%(l.sortReset?3:2)});F(a);G(a);m(a,g);"function"===typeof f&&f(a)}).bind("appendCache",function(b,c,d){m(a,d);"function"===typeof c&&c(a)}).bind("applyWidgetId",function(c,d){g.getWidgetById(d).format(a,b,b.widgetOptions)}).bind("applyWidgets",function(b,c){g.applyWidget(a,c)}).bind("refreshWidgets",function(b,c,d){g.refreshWidgets(a, c,d)}).bind("destroy",function(b,c,d){g.destroy(a,c,d)});b.supportsDataObject&&"undefined"!==typeof c.data().sortlist?b.sortList=c.data().sortlist:x&&(c.metadata()&&c.metadata().sortlist)&&(b.sortList=c.metadata().sortlist);g.applyWidget(a,!0);0<b.sortList.length?c.trigger("sorton",[b.sortList,{},!b.initWidgets]):b.initWidgets&&g.applyWidget(a);b.showProcessing&&c.unbind("sortBegin sortEnd").bind("sortBegin sortEnd",function(b){g.isProcessing(a,"sortBegin"===b.type)});a.hasInitialized=!0;b.debug&& g.benchmark("Overall initialization time",j.data(a,"startoveralltimer"));c.trigger("tablesorter-initialized",a);"function"===typeof b.initialized&&b.initialized(a)})};g.isProcessing=function(d,c,a){var b=d.config;d=a||j(d).find("."+b.cssHeader);c?(0<b.sortList.length&&(d=d.filter(function(){return this.sortDisabled?!1:g.isValueInArray(parseFloat(j(this).attr("data-column")),b.sortList)})),d.addClass(b.cssProcessing)):d.removeClass(b.cssProcessing)};g.processTbody=function(d,c,a){if(a)return c.before('<span class="tablesorter-savemyplace"/>'), d=j.fn.detach?c.detach():c.remove();d=j(d).find("span.tablesorter-savemyplace");c.insertAfter(d);d.remove()};g.clearTableBody=function(d){d.config.$tbodies.empty()};g.destroy=function(d,c,a){if(d.hasInitialized){g.refreshWidgets(d,!0,!0);var b=j(d),e=d.config,f=b.find("thead:first"),l=f.find("tr."+e.cssHeaderRow).removeClass(e.cssHeaderRow),h=b.find("tfoot:first > tr").children("th, td");f.find("tr").not(l).remove();b.removeData("tablesorter").unbind("sortReset update updateCell addRows sorton appendCache applyWidgetId applyWidgets refreshWidgets destroy mouseup mouseleave"); e.$headers.add(h).removeClass(e.cssHeader+" "+e.cssAsc+" "+e.cssDesc).removeAttr("data-column");l.find(e.selectorSort).unbind("mousedown.tablesorter mouseup.tablesorter");l.children().each(function(a){j(this).html(e.headerContent[a])});!1!==c&&b.removeClass(e.tableClass+" tablesorter-"+e.theme);d.hasInitialized=!1;"function"===typeof a&&a(d)}};g.regex=[/(^-?[0-9]+(\.?[0-9]*)[df]?e?[0-9]?$|^0x[0-9a-f]+$|[0-9]+)/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];g.sortText=function(d,c,a,b){if(c===a)return 0;var e=d.config,f=e.string[e.empties[b]||e.emptyTo],h=g.regex;if(""===c&&0!==f)return"boolean"===typeof f?f?-1:1:-f||-1;if(""===a&&0!==f)return"boolean"===typeof f?f?1:-1:f||1;if("function"===typeof e.textSorter)return e.textSorter(c,a,d,b);d=c.replace(h[0],"\\0$1\\0").replace(/\\0$/,"").replace(/^\\0/,"").split("\\0");b=a.replace(h[0],"\\0$1\\0").replace(/\\0$/,"").replace(/^\\0/,"").split("\\0");c=parseInt(c.match(h[2]),16)||1!==d.length&& c.match(h[1])&&Date.parse(c);if(a=parseInt(a.match(h[2]),16)||c&&a.match(h[1])&&Date.parse(a)||null){if(c<a)return-1;if(c>a)return 1}e=Math.max(d.length,b.length);for(c=0;c<e;c++){a=isNaN(d[c])?d[c]||0:parseFloat(d[c])||0;h=isNaN(b[c])?b[c]||0:parseFloat(b[c])||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};g.sortTextDesc=function(d,c,a,b){if(c===a)return 0;var e=d.config,f=e.string[e.empties[b]||e.emptyTo];return""===c&& 0!==f?"boolean"===typeof f?f?-1:1:f||1:""===a&&0!==f?"boolean"===typeof f?f?1:-1:-f||-1:"function"===typeof e.textSorter?e.textSorter(a,c,d,b):g.sortText(d,a,c)};g.getTextValue=function(d,c,a){if(c){var b=d.length,e=c+a;for(c=0;c<b;c++)e+=d.charCodeAt(c);return a*e}return 0};g.sortNumeric=function(d,c,a,b,e,f){if(c===a)return 0;d=d.config;b=d.string[d.empties[b]||d.emptyTo];if(""===c&&0!==b)return"boolean"===typeof b?b?-1:1:-b||-1;if(""===a&&0!==b)return"boolean"===typeof b?b?1:-1:b||1;isNaN(c)&& (c=g.getTextValue(c,e,f));isNaN(a)&&(a=g.getTextValue(a,e,f));return c-a};g.sortNumericDesc=function(d,c,a,b,e,f){if(c===a)return 0;d=d.config;b=d.string[d.empties[b]||d.emptyTo];if(""===c&&0!==b)return"boolean"===typeof b?b?-1:1:b||1;if(""===a&&0!==b)return"boolean"===typeof b?b?1:-1:-b||-1;isNaN(c)&&(c=g.getTextValue(c,e,f));isNaN(a)&&(a=g.getTextValue(a,e,f));return a-c};g.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"};g.replaceAccents=function(d){var c,a="[",b=g.characterEquivalents;if(!g.characterRegex){g.characterRegexArray={};for(c in b)"string"===typeof c&&(a+=b[c],g.characterRegexArray[c]= RegExp("["+b[c]+"]","g"));g.characterRegex=RegExp(a+"]")}if(g.characterRegex.test(d))for(c in b)"string"===typeof c&&(d=d.replace(g.characterRegexArray[c],c));return d};g.isValueInArray=function(d,c){var a,b=c.length;for(a=0;a<b;a++)if(c[a][0]===d)return!0;return!1};g.addParser=function(d){var c,a=g.parsers.length,b=!0;for(c=0;c<a;c++)g.parsers[c].id.toLowerCase()===d.id.toLowerCase()&&(b=!1);b&&g.parsers.push(d)};g.getParserById=function(d){var c,a=g.parsers.length;for(c=0;c<a;c++)if(g.parsers[c].id.toLowerCase()=== d.toString().toLowerCase())return g.parsers[c];return!1};g.addWidget=function(d){g.widgets.push(d)};g.getWidgetById=function(d){var c,a,b=g.widgets.length;for(c=0;c<b;c++)if((a=g.widgets[c])&&a.hasOwnProperty("id")&&a.id.toLowerCase()===d.toLowerCase())return a};g.applyWidget=function(d,c){var a=d.config,b=a.widgetOptions,e=a.widgets.sort().reverse(),f,h,m,n=e.length;h=j.inArray("zebra",a.widgets);0<=h&&(a.widgets.splice(h,1),a.widgets.push("zebra"));a.debug&&(f=new Date);for(h=0;h<n;h++)(m=g.getWidgetById(e[h]))&& (!0===c&&m.hasOwnProperty("init")?m.init(d,m,a,b):!c&&m.hasOwnProperty("format")&&m.format(d,a,b));a.debug&&v("Completed "+(!0===c?"initializing":"applying")+" widgets",f)};g.refreshWidgets=function(d,c,a){var b,h=d.config,f=h.widgets,l=g.widgets,m=l.length;for(b=0;b<m;b++)if(l[b]&&l[b].id&&(c||0>j.inArray(l[b].id,f)))h.debug&&e("Refeshing widgets: Removing "+l[b].id),l[b].hasOwnProperty("remove")&&l[b].remove(d,h,h.widgetOptions);!0!==a&&g.applyWidget(d,c)};g.getData=function(d,c,a){var b="";d=j(d); var e,f;if(!d.length)return"";e=j.metadata?d.metadata():!1;f=" "+(d.attr("class")||"");"undefined"!==typeof d.data(a)||"undefined"!==typeof d.data(a.toLowerCase())?b+=d.data(a)||d.data(a.toLowerCase()):e&&"undefined"!==typeof e[a]?b+=e[a]:c&&"undefined"!==typeof c[a]?b+=c[a]:" "!==f&&f.match(" "+a+"-")&&(b=f.match(RegExp(" "+a+"-(\\w+)"))[1]||"");return j.trim(b)};g.formatFloat=function(d,c){if("string"!==typeof d||""===d)return d;var a;d=(c&&c.config?!1!==c.config.usNumberFormat:"undefined"!==typeof c? c:1)?d.replace(/,/g,""):d.replace(/[\s|\.]/g,"").replace(/,/g,".");/^\s*\([.\d]+\)/.test(d)&&(d=d.replace(/^\s*\(/,"-").replace(/\)/,""));a=parseFloat(d);return isNaN(a)?j.trim(d):a};g.isDigit=function(d){return isNaN(d)?/^[\-+(]?\d+[)]?$/.test(d.toString().replace(/[,.'"\s]/g,"")):!0}}});var h=j.tablesorter;j.fn.extend({tablesorter:h.construct});h.addParser({id:"text",is:function(){return!0},format:function(e,v){var p=v.config;e=j.trim(p.ignoreCase?e.toLocaleLowerCase():e);return p.sortLocaleCompare? h.replaceAccents(e):e},type:"text"});h.addParser({id:"currency",is:function(e){return/^\(?\d+[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]|[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+\)?$/.test(e)},format:function(e,j){return h.formatFloat(e.replace(/[^\w,. \-()]/g,""),j)},type:"numeric"});h.addParser({id:"ipAddress",is:function(e){return/^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/.test(e)},format:function(e,j){var p,r=e.split("."),s="",m=r.length;for(p=0;p<m;p++)s+=("00"+r[p]).slice(-3);return h.formatFloat(s,j)}, type:"numeric"});h.addParser({id:"url",is:function(e){return/^(https?|ftp|file):\/\//.test(e)},format:function(e){return j.trim(e.replace(/(https?|ftp|file):\/\//,""))},type:"text"});h.addParser({id:"isoDate",is:function(e){return/^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}/.test(e)},format:function(e,j){return h.formatFloat(""!==e?(new Date(e.replace(/-/g,"/"))).getTime()||"":"",j)},type:"numeric"});h.addParser({id:"percent",is:function(e){return/(\d\s?%|%\s?\d)/.test(e)},format:function(e,j){return h.formatFloat(e.replace(/%/g, ""),j)},type:"numeric"});h.addParser({id:"usLongDate",is:function(e){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(e)||/^\d{1,2}\s+[A-Z]{3,10}\s+\d{4}/i.test(e)},format:function(e,j){return h.formatFloat((new Date(e.replace(/(\S)([AP]M)$/i,"$1 $2"))).getTime()||"",j)},type:"numeric"});h.addParser({id:"shortDate",is:function(e){return/^(\d{1,2}|\d{4})[\/\-\,\.\s+]\d{1,2}[\/\-\.\,\s+](\d{1,2}|\d{4})$/.test(e)},format:function(e,j,p,r){p=j.config;var s=p.headerList[r], m=s.shortDateFormat;"undefined"===typeof m&&(m=s.shortDateFormat=h.getData(s,p.headers[r],"dateFormat")||p.dateFormat);e=e.replace(/\s+/g," ").replace(/[\-|\.|\,]/g,"/");"mmddyyyy"===m?e=e.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,"$3/$1/$2"):"ddmmyyyy"===m?e=e.replace(/(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{4})/,"$3/$2/$1"):"yyyymmdd"===m&&(e=e.replace(/(\d{4})[\/\s](\d{1,2})[\/\s](\d{1,2})/,"$1/$2/$3"));return h.formatFloat((new Date(e)).getTime()||"",j)},type:"numeric"});h.addParser({id:"time", is:function(e){return/^(([0-2]?\d:[0-5]\d)|([0-1]?\d:[0-5]\d\s?([AP]M)))$/i.test(e)},format:function(e,j){return h.formatFloat((new Date("2000/01/01 "+e.replace(/(\S)([AP]M)$/i,"$1 $2"))).getTime()||"",j)},type:"numeric"});h.addParser({id:"digit",is:function(e){return h.isDigit(e)},format:function(e,j){return h.formatFloat(e.replace(/[^\w,. \-()]/g,""),j)},type:"numeric"});h.addParser({id:"metadata",is:function(){return!1},format:function(e,h,p){e=h.config;e=!e.parserMetadataName?"sortValue":e.parserMetadataName; return j(p).metadata()[e]},type:"numeric"});h.addWidget({id:"zebra",format:function(e,v,p){var r,s,m,F,G,C,I=RegExp(v.cssChildRow,"i"),g=v.$tbodies;v.debug&&(G=new Date);for(e=0;e<g.length;e++)r=g.eq(e),C=r.children("tr").length,1<C&&(m=0,r=r.children("tr:visible"),r.each(function(){s=j(this);I.test(this.className)||m++;F=0===m%2;s.removeClass(p.zebra[F?1:0]).addClass(p.zebra[F?0:1])}));v.debug&&h.benchmark("Applying Zebra widget",G)},remove:function(e,h){var p,r,s=h.$tbodies,m=(h.widgetOptions.zebra|| ["even","odd"]).join(" ");for(p=0;p<s.length;p++)r=j.tablesorter.processTbody(e,s.eq(p),!0),r.children().removeClass(m),j.tablesorter.processTbody(e,r,!1)}})}(jQuery);
9
10 var yourls_defaultsort = 2; // default column to sort on (overwrite this inline in page)
11 var yourls_defaultorder = 1; // default order ('asc':0, 'desc':1) to sort on (overwrite this inline in page)
12
13 // Initialise the table to sort
14 $(document).ready(function(){
15         if ($("#main_table").tablesorter && $("#main_table tr#nourl_found").css('display') == 'none') {
16                 var order = {'keyword':0, 'url':1, 'timestamp':2, 'ip':3, 'clicks':4};
17                 var order_by = {'asc':0, 'desc':1};
18                 var sort_by = order[query_string('sort_by')];
19                 var sort_order = order_by[query_string('sort_order')];
20                 if( sort_by == undefined ) {
21                         sort_by = yourls_defaultsort;
22                         sort_order = yourls_defaultorder;
23                 }
24                 
25                 $("#main_table").tablesorter({
26                         textExtraction: {
27                                 1: function(node, table, cellIndex){return $(node).find("small a").text();} // Sort column "URL" by URL, not by whole cell content
28                         },
29                         sortList:[[ sort_by, sort_order ]], 
30                         headers: { 5: {sorter: false} }, // no sorter on column "Actions"
31                         widgets: ['zebra'], // prettify, see tr.normal-row and tr.alt-row in tablesorter.css
32                         widgetOptions : { zebra : [ "normal-row", "alt-row" ] }
33                 });
34         }
35 });
36
37 // Get query string
38 function query_string( key ) {
39         default_="";
40         key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
41         var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
42         var qs = regex.exec(window.location.href);
43         if(qs == null)
44                 return yourls_defaultsort;
45         else
46                 return qs[1];
47 }