tablesorter/js/jquery.tablesorter.min.js

7 lines
18 KiB
JavaScript
Raw Normal View History

2012-03-18 14:02:49 +00:00
/*!
* TableSorter 2.3.1 - Client-side table sorting with ease!
* Minified using UglifyJS (http://jscompress.com/)
2011-06-22 23:19:27 +00:00
* Copyright (c) 2007 Christian Bach
*/
!function($){$.extend({tablesorter:new function(){function log(a){if(typeof console!=="undefined"&&typeof console.log!=="undefined"){console.log(a)}else{alert(a)}}function benchmark(a,b){log(a+" ("+((new Date).getTime()-b.getTime())+"ms)")}function getElementText(a,b,c){var d="",e=a.config.textExtraction;if(!b){return""}if(e==="simple"){d=$(b).text()}else{if(typeof e==="function"){d=e(b,a,c)}else if(typeof e==="object"&&e.hasOwnProperty(c)){d=e[c](b,a,c)}else{d=$(b).text()}}return d}function getParserById(a){var b,c=parsers.length;for(b=0;b<c;b++){if(parsers[b].id.toLowerCase()===a.toString().toLowerCase()){return parsers[b]}}return false}function detectParserForColumn(a,b,c,d){var e,f=parsers.length,g=false,h="",i=true;while(h===""&&i){c++;if(b[c]){g=b[c].cells[d];h=$.trim(getElementText(a,g,d));if(a.config.debug){log("Checking if value was empty on row "+c+", column:"+d+": "+h)}}else{i=false}}for(e=1;e<f;e++){if(parsers[e].is(h,a,g)){return parsers[e]}}return parsers[0]}function buildParserCache(a,b){if(a.tBodies.length===0){return}var c=a.config,d=a.tBodies[0].rows,e=$.tablesorter,f,g,h,i,j,k,l,m,n="";if(d[0]){f=[];g=d[0].cells.length;for(h=0;h<g;h++){i=b.filter(':not([colspan])[data-column="'+h+'"]:last');k=c.headers[h];m=getParserById(e.getData(i,k,"sorter"));c.empties[h]=e.getData(i,k,"empty")||c.emptyTo||(c.emptyToBottom?"bottom":"top");c.strings[h]=e.getData(i,k,"string")||c.stringTo||"max";if(!m){m=detectParserForColumn(a,d,-1,h)}if(c.debug){n+="column:"+h+"; parser:"+m.id+"; string:"+c.strings[h]+"; empty: "+c.empties[h]+"\n"}f.push(m)}}if(c.debug){log(n)}return f}function buildRegex(){var a,b="[",c=$.tablesorter,d=c.characterEquivalents;c.characterRegexArray={};for(a in d){if(typeof a==="string"){b+=d[a];c.characterRegexArray[a]=new RegExp("["+d[a]+"]","g")}}c.characterRegex=new RegExp(b+"]")}function buildCache(a){var b=a.tBodies,c=a.config,d,e,f=c.parsers,g,h,i,j,k,l,m;c.cache={};if(c.debug){m=new Date}for(j=0;j<b.length;j++){c.cache[j]={row:[],normalized:[]};if(!$(b[j]).hasClass(c.cssInfoBlock)){d=b[j]&&b[j].rows.length||0;e=b[j].rows[0]&&b[j].rows[0].cells.length||0;for(h=0;h<d;++h){k=$(b[j].rows[h]);l=[];if(k.hasClass(c.cssChildRow)){c.cache[j].row[c.cache[j].row.length-1]=c.cache[j].row[c.cache[j].row.length-1].add(k);continue}c.cache[j].row.push(k);for(i=0;i<e;++i){g=$.trim(getElementText(a,k[0].cells[i],i));l.push(f[i].format(g,a,k[0].cells[i],i))}l.push(c.cache[j].normalized.length);c.cache[j].normalized.push(l)}}}if(c.debug){benchmark("Building cache for "+d+" rows",m)}}function getWidgetById(a){var b,c,d=widgets.length;for(b=0;b<d;b++){c=widgets[b];if(c&&c.hasOwnProperty("id")&&c.id.toLowerCase()===a.toLowerCase()){return c}}}function applyWidget(a,b){var c=a.config.widgets,d,e,f=c.length;for(d=0;d<f;d++){e=getWidgetById(c[d]);if(e){if(b&&e.hasOwnProperty("init")){e.init(a,widgets,e)}else if(!b&&e.hasOwnProperty("format")){e.format(a)}}}}function appendToTable(a){var b=a.config,c=a.tBodies,d=[],e,f,g,h,i,j,k,l,m,n,o;if(b.debug){o=new Date}for(l=0;l<c.length;l++){if(!$(c[l]).hasClass(b.cssInfoBlock)){i=document.createDocumentFragment();e=b.cache[l].row;f=b.cache[l].normalized;g=f.length;h=g?f[0].length-1:0;for(j=0;j<g;j++){n=f[j][h];d.push(e[n]);if(!b.appender||!b.removeRows){m=e[n].length;for(k=0;k<m;k++){i.appendChild(e[n][k])}}}a.tBodies[l].appendChild(i)}}if(b.appender){b.appender(a,d)}if(b.debug){benchmark("Rebuilt table",o)}applyWidget(a);$(a).trigger("sortEnd",a)}function computeTableHeaderCellIndexes(a){var b=[],c={},d=$(a).find("thead:eq(0) tr"),e,f,g,h,i,j,k,l,m,n,o,p;for(e=0;e<d.length;e++){j=d[e].cells;for(f=0;f<j.length;f++){i=j[f];k=i.parentNode.rowIndex;l=k+"-"+i.cellIndex;m=i.rowSpan||1;n=i.colSpan||1;if(typeof b[k]==="undefined"){b[k]=[]}for(g=0;g<b[k].length+1;g++){if(typeof b[k][g]==="undefined"){o=g;break}}c[l]=o;$(i).attr({"data-column":o});for(g=k;g<k+m;g++){if(typeof b[g]==="undefined"){b[g]=[]}p=b[g];for(h=o;h<o+n;h++){p[h]="x"}}}}return c}function formatSortingOrder(a){return/^d/i.test(a)||a===1}function buildHeaders(a){var b=$.metadata?true:false,c=computeTableHeaderCellInd