Index: trunk/phase3/resources/jquery/jquery.tablesorter.js |
— | — | @@ -218,6 +218,26 @@ |
219 | 219 | } |
220 | 220 | table.tBodies[0].appendChild( fragment ); |
221 | 221 | } |
| 222 | + |
| 223 | + /** |
| 224 | + * Find all header rows in a thead-less table and put them in a <thead> tag. |
| 225 | + * This only treats a row as a header row if it contains only <th>s (no <td>s) |
| 226 | + * and if it is preceded entirely by header rows. The algorithm stops when |
| 227 | + * it encounters the first non-header row. |
| 228 | + * @param $table jQuery object for a <table> |
| 229 | + */ |
| 230 | + function emulateTHead( $table ) { |
| 231 | + var $thead = $( '<thead>' ); |
| 232 | + $table.find( 'tr' ).each( function() { |
| 233 | + if ( $(this).find( 'td' ).length > 0 ) { |
| 234 | + // This row contains a <td>, so it's not a header row |
| 235 | + // Stop here |
| 236 | + return false; |
| 237 | + } |
| 238 | + $thead.append( this ); |
| 239 | + } ); |
| 240 | + $table.prepend( $thead ); |
| 241 | + } |
222 | 242 | |
223 | 243 | function buildHeaders( table, msg ) { |
224 | 244 | var maxSeen = 0, |
— | — | @@ -500,17 +520,27 @@ |
501 | 521 | */ |
502 | 522 | construct: function( $tables, settings ) { |
503 | 523 | return $tables.each( function( i, table ) { |
504 | | - |
505 | | - // Quit if no thead or tbody. |
506 | | - if ( !table.tHead || !table.tBodies ) { |
507 | | - return; |
508 | | - } |
509 | 524 | // Declare and cache. |
510 | 525 | var $document, $headers, cache, config, sortOrder, |
511 | 526 | $table = $( table ), |
512 | 527 | shiftDown = 0, |
513 | 528 | firstTime = true; |
514 | 529 | |
| 530 | + // Quit if no tbody |
| 531 | + if ( !table.tBodies ) { |
| 532 | + return; |
| 533 | + } |
| 534 | + if ( !table.tHead ) { |
| 535 | + // No thead found. Look for rows with <th>s and |
| 536 | + // move them into a <thead> tag |
| 537 | + emulateTHead( $table ); |
| 538 | + |
| 539 | + // Still no thead? Then quit |
| 540 | + if ( !table.tHead ) { |
| 541 | + return; |
| 542 | + } |
| 543 | + } |
| 544 | + |
515 | 545 | // New config object. |
516 | 546 | table.config = {}; |
517 | 547 | |
— | — | @@ -545,9 +575,11 @@ |
546 | 576 | |
547 | 577 | // Legacy fix of .sortbottoms |
548 | 578 | // Wrap them inside inside a tfoot (because that's what they actually want to be) & |
549 | | - // Move them up one level in the DOM |
550 | | - var sortbottoms = $table.find('tr.sortbottom').wrap('<tfoot>'); |
551 | | - sortbottoms.parents('table').append(sortbottoms.parent()); |
| 579 | + // and put the <tfoot> at the end of the <table> |
| 580 | + var $sortbottoms = $table.find( 'tr.sortbottom' ); |
| 581 | + if ( $sortbottoms.length ) { |
| 582 | + $table.append( $( '<tfoot>' ).append( $sortbottoms ) ) |
| 583 | + } |
552 | 584 | |
553 | 585 | explodeRowspans( $table ); |
554 | 586 | // try to auto detect column type, and store in tables config |