tablesorter/js/jquery.tablesorter.min.js

7 lines
19 KiB
JavaScript
Raw Normal View History

2012-03-18 14:02:49 +00:00
/*!
2012-05-19 20:46:14 +00:00
* TableSorter 2.3.3 - 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
*/
2012-05-19 20:46:14 +00:00
!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 $.trim(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=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){var c=a.config,d=$(a.tBodies).filter(":not(."+c.cssInfoBlock+")"),e=$.tablesorter,f,g,h,i,j,k,l,m,n,o="";if(d.length===0){return}f=d[0].rows;if(f[0]){g=[];h=f[0].cells.length;for(i=0;i<h;i++){j=b.filter(':not([colspan])[data-column="'+i+'"]:last');l=c.headers[i];n=getParserById(e.getData(j,l,"sorter"));c.empties[i]=e.getData(j,l,"empty")||c.emptyTo||(c.emptyToBottom?"bottom":"top");c.strings[i]=e.getData(j,l,"string")||c.stringTo||"max";if(!n){n=detectParserForColumn(a,f,-1,i)}if(c.debug){o+="column:"+i+"; parser:"+n.id+"; string:"+c.strings[i]+"; empty: "+c.empties[i]+"\n"}g.push(n)}}if(c.debug){log(o)}return g}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=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=b.cache,j,k,l,m,n,o,p;if(b.debug){p=new Date}for(m=0;m<c.length;m++){if(!$(c[m]).hasClass(b.cssInfoBlock)){j=document.createDocumentFragment();e=i[m].row;f=i[m].normalized;g=f.length;h=g?f[0].length-1:0;for(k=0;k<g;k++){o=f[k][h];d.push(e[o]);if(!b.appender||!b.removeRows){n=e[o].length;for(l=0;l<n;l++){j.appendChild(e[o][l])}}}a.tBodies[m].appendChild(j)}}if(b.appender){b.appender(a,d)}if(b.debug){benchmark("Rebuilt table",p)}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,