X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fjquery%2Fjquery.tablesorter.js;h=eaa138b9379e867b89d77cf63eb3bb52b6fb7b36;hp=8efbb1ce8ffd25d350a573d9f8d747b9c30aa99e;hb=f8659ae6ea90d7bc8ce28bfc1caa56153878836f;hpb=d2278d1c2ae98e2c177acdab400614f29ac54591 diff --git a/resources/src/jquery/jquery.tablesorter.js b/resources/src/jquery/jquery.tablesorter.js index 8efbb1ce8f..eaa138b937 100644 --- a/resources/src/jquery/jquery.tablesorter.js +++ b/resources/src/jquery/jquery.tablesorter.js @@ -70,8 +70,8 @@ var i, len = parsers.length; for ( i = 0; i < len; i++ ) { - if ( parsers[i].id.toLowerCase() === name.toLowerCase() ) { - return parsers[i]; + if ( parsers[ i ].id.toLowerCase() === name.toLowerCase() ) { + return parsers[ i ]; } } return false; @@ -105,69 +105,83 @@ } } - function detectParserForColumn( table, rows, cellIndex ) { + function detectParserForColumn( table, rows, column ) { var l = parsers.length, + cellIndex, nodeValue, // Start with 1 because 0 is the fallback parser i = 1, + lastRowIndex = -1, rowIndex = 0, concurrent = 0, + empty = 0, needed = ( rows.length > 4 ) ? 5 : rows.length; while ( i < l ) { - if ( rows[rowIndex] && rows[rowIndex].cells[cellIndex] ) { - nodeValue = $.trim( getElementSortKey( rows[rowIndex].cells[cellIndex] ) ); + if ( rows[ rowIndex ] ) { + if ( rowIndex !== lastRowIndex ) { + lastRowIndex = rowIndex; + cellIndex = $( rows[ rowIndex ] ).data( 'columnToCell' )[ column ]; + nodeValue = $.trim( getElementSortKey( rows[ rowIndex ].cells[ cellIndex ] ) ); + } } else { nodeValue = ''; } if ( nodeValue !== '' ) { - if ( parsers[i].is( nodeValue, table ) ) { + if ( parsers[ i ].is( nodeValue, table ) ) { concurrent++; rowIndex++; if ( concurrent >= needed ) { // Confirmed the parser for multiple cells, let's return it - return parsers[i]; + return parsers[ i ]; } } else { // Check next parser, reset rows i++; rowIndex = 0; concurrent = 0; + empty = 0; } } else { // Empty cell + empty++; rowIndex++; - if ( rowIndex > rows.length ) { - rowIndex = 0; + if ( rowIndex >= rows.length ) { + if ( concurrent >= rows.length - empty ) { + // Confirmed the parser for all filled cells + return parsers[ i ]; + } + // Check next parser, reset rows i++; + rowIndex = 0; + concurrent = 0; + empty = 0; } } } // 0 is always the generic parser (text) - return parsers[0]; + return parsers[ 0 ]; } function buildParserCache( table, $headers ) { - var sortType, cells, len, i, parser, - rows = table.tBodies[0].rows, + var sortType, len, j, parser, + rows = table.tBodies[ 0 ].rows, + config = $( table ).data( 'tablesorter' ).config, parsers = []; - if ( rows[0] ) { - - cells = rows[0].cells; - len = cells.length; - - for ( i = 0; i < len; i++ ) { + if ( rows[ 0 ] ) { + len = config.columns; + for ( j = 0; j < len; j++ ) { parser = false; - sortType = $headers.eq( i ).data( 'sortType' ); + sortType = $headers.eq( config.columnToHeader[ j ] ).data( 'sortType' ); if ( sortType !== undefined ) { parser = getParserById( sortType ); } if ( parser === false ) { - parser = detectParserForColumn( table, rows, i ); + parser = detectParserForColumn( table, rows, j ); } parsers.push( parser ); @@ -180,33 +194,35 @@ function buildCache( table ) { var i, j, $row, cols, - totalRows = ( table.tBodies[0] && table.tBodies[0].rows.length ) || 0, - totalCells = ( table.tBodies[0].rows[0] && table.tBodies[0].rows[0].cells.length ) || 0, + totalRows = ( table.tBodies[ 0 ] && table.tBodies[ 0 ].rows.length ) || 0, config = $( table ).data( 'tablesorter' ).config, parsers = config.parsers, + len = parsers.length, + cellIndex, cache = { row: [], normalized: [] }; - for ( i = 0; i < totalRows; ++i ) { + for ( i = 0; i < totalRows; i++ ) { // Add the table data to main data array - $row = $( table.tBodies[0].rows[i] ); + $row = $( table.tBodies[ 0 ].rows[ i ] ); cols = []; // if this is a child row, add it to the last row's children and // continue to the next row if ( $row.hasClass( config.cssChildRow ) ) { - cache.row[cache.row.length - 1] = cache.row[cache.row.length - 1].add( $row ); + cache.row[ cache.row.length - 1 ] = cache.row[ cache.row.length - 1 ].add( $row ); // go to the next for loop continue; } cache.row.push( $row ); - for ( j = 0; j < totalCells; ++j ) { - cols.push( parsers[j].format( getElementSortKey( $row[0].cells[j] ), table, $row[0].cells[j] ) ); + for ( j = 0; j < len; j++ ) { + cellIndex = $row.data( 'columnToCell' )[ j ]; + cols.push( parsers[ j ].format( getElementSortKey( $row[ 0 ].cells[ cellIndex ] ) ) ); } cols.push( cache.normalized.length ); // add position for rowCache @@ -222,20 +238,20 @@ row = cache.row, normalized = cache.normalized, totalRows = normalized.length, - checkCell = ( normalized[0].length - 1 ), + checkCell = ( normalized[ 0 ].length - 1 ), fragment = document.createDocumentFragment(); for ( i = 0; i < totalRows; i++ ) { - pos = normalized[i][checkCell]; + pos = normalized[ i ][ checkCell ]; - l = row[pos].length; + l = row[ pos ].length; for ( j = 0; j < l; j++ ) { - fragment.appendChild( row[pos][j] ); + fragment.appendChild( row[ pos ][ j ] ); } } - table.tBodies[0].appendChild( fragment ); + table.tBodies[ 0 ].appendChild( fragment ); $( table ).trigger( 'sortEnd.tablesorter' ); } @@ -248,7 +264,8 @@ * * After this, it will look at all rows at the bottom for footer rows * And place these in a tfoot using similar rules. - * @param $table jQuery object for a
' );
+ cellsInRow++;
+ }
+ for ( k = 0; k < $row[ 0 ].cells[ index ].colSpan; k++ ) {
+ columnToCell[ j++ ] = index;
+ }
+ }
+ // Store it in $row
+ $row.data( 'columnToCell', columnToCell );
+ }
+ }
+
function buildCollationTable() {
ts.collationTable = mw.config.get( 'tableSorterCollation' );
ts.collationRegex = null;
@@ -698,7 +764,7 @@
$.each( sortObjects, function ( i, sortObject ) {
$.each( sortObject, function ( columnIndex, order ) {
var orderIndex = ( order === 'desc' ) ? 1 : 0;
- sortList.push( [parseInt( columnIndex, 10 ), orderIndex] );
+ sortList.push( [ parseInt( columnIndex, 10 ), orderIndex ] );
} );
} );
return sortList;
@@ -714,20 +780,21 @@
cssChildRow: 'expand-child',
sortMultiSortKey: 'shiftKey',
unsortableClass: 'unsortable',
- parsers: {},
+ parsers: [],
cancelSelection: true,
sortList: [],
headerList: [],
headerToColumns: [],
- columnToHeader: []
+ columnToHeader: [],
+ columns: 0
},
dateRegex: [],
monthNames: {},
/**
- * @param $tables {jQuery}
- * @param settings {Object} (optional)
+ * @param {jQuery} $tables
+ * @param {Object} [settings]
*/
construct: function ( $tables, settings ) {
return $tables.each( function ( i, table ) {
@@ -797,6 +864,7 @@
}
explodeRowspans( $table );
+ manageColspans( $table );
// Try to auto detect column type, and store in tables config
config.parsers = buildParserCache( table, $headers );
@@ -804,7 +872,7 @@
// Apply event handling to headers
// this is too big, perhaps break it out?
- $headers.not( '.' + config.unsortableClass ).on( 'keypress click', function ( e ) {
+ $headers.on( 'keypress click', function ( e ) {
var cell, $cell, columns, newSortList, i,
totalRows,
j, s, o;
@@ -832,8 +900,8 @@
// cells get event .change() and bubbles up to the |