From 33e19958bf3ff5ea6a6c288c9055a96af16397bb Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 15 Sep 2011 13:15:06 +0000 Subject: [PATCH] Update jquery.tablesorter for r97145: emulate if there is no in the HTML, by walking down the table starting at the first row and moving rows to the as long as all of its cells are s (or the row is empty). Also fix and simplify the sortbottom code, which was incorrectly creating multiple elements if there were multiple sortbottom rows. --- resources/jquery/jquery.tablesorter.js | 48 +++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 387bf51ad4..c17f3f2943 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -218,6 +218,26 @@ } table.tBodies[0].appendChild( fragment ); } + + /** + * Find all header rows in a thead-less table and put them in a tag. + * This only treats a row as a header row if it contains only s (no s) + * and if it is preceded entirely by header rows. The algorithm stops when + * it encounters the first non-header row. + * @param $table jQuery object for a + */ + function emulateTHead( $table ) { + var $thead = $( '' ); + $table.find( 'tr' ).each( function() { + if ( $(this).find( 'td' ).length > 0 ) { + // This row contains a tag + emulateTHead( $table ); + + // Still no thead? Then quit + if ( !table.tHead ) { + return; + } + } + // New config object. table.config = {}; @@ -545,9 +575,11 @@ // Legacy fix of .sortbottoms // Wrap them inside inside a tfoot (because that's what they actually want to be) & - // Move them up one level in the DOM - var sortbottoms = $table.find('tr.sortbottom').wrap(''); - sortbottoms.parents('table').append(sortbottoms.parent()); + // and put the at the end of the
, so it's not a header row + // Stop here + return false; + } + $thead.append( this ); + } ); + $table.prepend( $thead ); + } function buildHeaders( table, msg ) { var maxSeen = 0, @@ -500,17 +520,27 @@ */ construct: function( $tables, settings ) { return $tables.each( function( i, table ) { - - // Quit if no thead or tbody. - if ( !table.tHead || !table.tBodies ) { - return; - } // Declare and cache. var $document, $headers, cache, config, sortOrder, $table = $( table ), shiftDown = 0, firstTime = true; + // Quit if no tbody + if ( !table.tBodies ) { + return; + } + if ( !table.tHead ) { + // No thead found. Look for rows with s and + // move them into a
+ var $sortbottoms = $table.find( 'tr.sortbottom' ); + if ( $sortbottoms.length ) { + $table.append( $( '' ).append( $sortbottoms ) ) + } explodeRowspans( $table ); // try to auto detect column type, and store in tables config -- 2.20.1