diff --git a/README.markdown b/README.markdown index 55f14f9a..265b8376 100644 --- a/README.markdown +++ b/README.markdown @@ -28,6 +28,10 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt). +#### Version 2.0.15 (2011-08-23) + +* Fixed a problem that caused a javascript error when a table header cell doesn't have a class name. + #### Version 2.0.14 (2011-08-22) * Reverted the changes made in 2.0.13 and added checks to prevent errors. diff --git a/changelog.txt b/changelog.txt index 092d8e1c..37c3cf90 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,10 @@ TableSorter Change Log +Version 2.0.15 (2011-08-23) +============================ + +* Fixed a problem that caused a javascript error when a table header cell doesn't have a class name. + Version 2.0.14 (2011-08-22) ============================ diff --git a/docs/index.html b/docs/index.html index 57ea8a47..d7ee27fb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -36,7 +36,7 @@

Author: Christian Bach
- Version: 2.0.14 (changelog)
+ Version: 2.0.15 (changelog)
Licence: Dual licensed under MIT or GPL licenses. diff --git a/js/jquery.tablesorter.js b/js/jquery.tablesorter.js index 56846e67..d7cc84d1 100644 --- a/js/jquery.tablesorter.js +++ b/js/jquery.tablesorter.js @@ -1,6 +1,6 @@ /* * TableSorter 2.0 - Client-side table sorting with ease! -* Version 2.0.14 +* Version 2.0.15 * @requires jQuery v1.2.3 * * Copyright (c) 2007 Christian Bach @@ -194,20 +194,21 @@ function buildParserCache(table, $headers) { if (table.tBodies.length === 0) { return; } // In the case of empty tables - var rows = table.tBodies[0].rows, list, cells, l, i, p, parsersDebug = ""; + var rows = table.tBodies[0].rows, list, cells, l, h, i, p, parsersDebug = ""; if (rows[0]) { list = []; cells = rows[0].cells; l = cells.length; for (i = 0; i < l; i++) { p = false; - if ($.metadata && ($($headers[i]).metadata() && $($headers[i]).metadata().sorter)) { - p = getParserById($($headers[i]).metadata().sorter); + h = $($headers[i]); + if ($.metadata && (h.metadata() && h.metadata().sorter)) { + p = getParserById(h.metadata().sorter); } else if ((table.config.headers[i] && table.config.headers[i].sorter)) { p = getParserById(table.config.headers[i].sorter); - } else if ($($headers[i]).attr('class').match('sorter-')){ + } else if (h.attr('class') && h.attr('class').match('sorter-')){ // include sorter class name "sorter-text", etc - p = getParserById($($headers[i]).attr('class').match(/sorter-(\w+)/)[1] || ''); + p = getParserById(h.attr('class').match(/sorter-(\w+)/)[1] || ''); } if (!p) { p = detectParserForColumn(table, rows, -1, i); @@ -226,8 +227,9 @@ /* utils */ function buildCache(table) { - var totalRows = (table.tBodies[0] && table.tBodies[0].rows.length) || 0, - totalCells = (table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length) || 0, + var b = table.tBodies[0], + totalRows = (b && b.rows.length) || 0, + totalCells = (b.rows[0] && b.rows[0].cells.length) || 0, parsers = table.config.parsers, cache = { row: [], @@ -239,7 +241,7 @@ } for (i = 0; i < totalRows; ++i) { /** Add the table data to main data array */ - c = $(table.tBodies[0].rows[i]); + c = $(b.rows[i]); cols = []; // if this is a child row, add it to the last row's children and // continue to the next row diff --git a/js/jquery.tablesorter.min.js b/js/jquery.tablesorter.min.js index a287b5ad..79e270fb 100644 --- a/js/jquery.tablesorter.min.js +++ b/js/jquery.tablesorter.min.js @@ -1,7 +1,7 @@ /* * TableSorter 2.0 - Client-side table sorting with ease! -* Version 2.0.14 Minified using Google Closure Compiler (white space only) +* Version 2.0.15 Minified using Google Closure Compiler (white space only) * Copyright (c) 2007 Christian Bach */ -(function($){$.extend({tablesorter:new function(){var parsers=[],widgets=[],tbl;this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:false,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",onRenderHeader:null,selectorHeaders:"thead th", tableClass:"tablesorter",debug:false};function log(s){if(typeof console!=="undefined"&&typeof console.debug!=="undefined")console.log(s);else alert(s)}function benchmark(s,d){log(s+","+((new Date).getTime()-d.getTime())+"ms")}this.benchmark=benchmark;function getElementText(config,node,cellIndex){var text="",te=config.textExtraction;if(!node)return"";if(!config.supportsTextContent)config.supportsTextContent=node.textContent||false;if(te==="simple")if(config.supportsTextContent)text=node.textContent; else if(node.childNodes[0]&&node.childNodes[0].hasChildNodes())text=node.childNodes[0].innerHTML;else text=node.innerHTML;else if(typeof te==="function")text=te(node);else if(typeof te==="object"&&te.hasOwnProperty(cellIndex))text=te[cellIndex](node);else text=$(node).text();return text}function getParserById(name){var i,l=parsers.length;for(i=0;i").each(function(index){this.column=header_index[this.parentNode.rowIndex+"-"+this.cellIndex];this.order=formatSortingOrder(checkHeaderOrder(table,index));this.count=this.order;if(checkHeaderMetadata(this)||checkHeaderOptions(table,index)||$(this).is(".sorter-false"))this.sortDisabled=true;this.lockedOrder=false;lock=checkHeaderLocked(table,index);if(typeof lock!=="undefined"&&lock!==false)this.order=this.lockedOrder=formatSortingOrder(lock); if(!this.sortDisabled){$th=$(this).addClass(table.config.cssHeader);if(table.config.onRenderHeader)table.config.onRenderHeader.apply($th,[index])}table.config.headerList[index]=this});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders)}return $tableHeaders}function checkCellColSpan(table,rows,row){var i,cell,arr=[],r=table.tHead.rows,c=r[row].cells;for(i=0;i1)arr=arr.concat(checkCellColSpan(table,rows,row++));else if(table.tHead.length=== 1||cell.rowSpan>1||!r[row+1])arr.push(cell)}return arr}function isValueInArray(v,a){var i,l=a.length;for(i=0;i");$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($("").css("width",$(this).width()))});$(table).prepend(colgroup)}}function updateHeaderSortCount(table,sortList){var i,s,o,c=table.config,l=sortList.length;for(i=0;ib?1:-1}catch(er){return 0}}function sortTextDesc(a,b){if($.data(tbl[0],"tablesorter").sortLocaleCompare)return b.localeCompare(a);return-sortText(a,b)}function getTextValue(a,mx,d){if(a==="")return(d||0)*Number.MAX_VALUE;if(mx){var i,l=a.length,n=mx+d;for(i=0;i0)$this.trigger("sorton",[config.sortList]);applyWidget(this)})};this.addParser=function(parser){var i,l=parsers.length,a=true;for(i=0;i").each(function(index){this.column=header_index[this.parentNode.rowIndex+"-"+this.cellIndex];this.order=formatSortingOrder(checkHeaderOrder(table,index));this.count=this.order;if(checkHeaderMetadata(this)||checkHeaderOptions(table,index)||$(this).is(".sorter-false"))this.sortDisabled=true;this.lockedOrder=false;lock=checkHeaderLocked(table,index);if(typeof lock!=="undefined"&&lock!==false)this.order=this.lockedOrder=formatSortingOrder(lock);if(!this.sortDisabled){$th=$(this).addClass(table.config.cssHeader); if(table.config.onRenderHeader)table.config.onRenderHeader.apply($th,[index])}table.config.headerList[index]=this});if(table.config.debug){benchmark("Built headers:",time);log($tableHeaders)}return $tableHeaders}function checkCellColSpan(table,rows,row){var i,cell,arr=[],r=table.tHead.rows,c=r[row].cells;for(i=0;i1)arr=arr.concat(checkCellColSpan(table,rows,row++));else if(table.tHead.length===1||cell.rowSpan>1||!r[row+1])arr.push(cell)}return arr}function isValueInArray(v, a){var i,l=a.length;for(i=0;i");$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($("").css("width", $(this).width()))});$(table).prepend(colgroup)}}function updateHeaderSortCount(table,sortList){var i,s,o,c=table.config,l=sortList.length;for(i=0;ib?1:-1}catch(er){return 0}} function sortTextDesc(a,b){if($.data(tbl[0],"tablesorter").sortLocaleCompare)return b.localeCompare(a);return-sortText(a,b)}function getTextValue(a,mx,d){if(a==="")return(d||0)*Number.MAX_VALUE;if(mx){var i,l=a.length,n=mx+d;for(i=0;i0)$this.trigger("sorton",[config.sortList]);applyWidget(this)})};this.addParser=function(parser){var i,l=parsers.length,a=true;for(i=0;i