TheDJ has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/386858 )
Change subject: [WIP] tablesorter: User Intl.Collator for string sorting ...................................................................... [WIP] tablesorter: User Intl.Collator for string sorting Requires testcases and verification on various browsers. Bug: T72157 Change-Id: I271fcccdbd19c1fe1db39d442d934a6b4382514d --- M resources/src/jquery/jquery.tablesorter.js 1 file changed, 23 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/58/386858/1 diff --git a/resources/src/jquery/jquery.tablesorter.js b/resources/src/jquery/jquery.tablesorter.js index cac103e..a22c20d 100644 --- a/resources/src/jquery/jquery.tablesorter.js +++ b/resources/src/jquery/jquery.tablesorter.js @@ -465,11 +465,11 @@ } } - function sortText( a, b ) { + function sortAsc( a, b ) { return ( ( a < b ) ? -1 : ( ( a > b ) ? 1 : 0 ) ); } - function sortTextDesc( a, b ) { + function sortDesc( a, b ) { return ( ( b < a ) ? -1 : ( ( b > a ) ? 1 : 0 ) ); } @@ -478,19 +478,29 @@ sortFn = []; for ( i = 0; i < sortList.length; i++ ) { - sortFn[ i ] = ( sortList[ i ][ 1 ] ) ? sortTextDesc : sortText; + sortFn[ i ] = ( sortList[ i ][ 1 ] ) ? sortDesc : sortAsc; } cache.normalized.sort( function ( array1, array2 ) { var i, col, ret; for ( i = 0; i < sortList.length; i++ ) { col = sortList[ i ][ 0 ]; - ret = sortFn[ i ].call( this, array1[ col ], array2[ col ] ); + + if ( ts.collator && 'string' === typeof array1[ col ] && 'string' === typeof array2[ col ] ) { + if ( sortList[ i ][ 1 ] ) { + // Desc + ret = ts.collator.compare( array2[ col ], array1[ col ] ); + } else { + ret = ts.collator.compare( array1[ col ], array2[ col ] ); + } + } else { + ret = sortFn[ i ].call( this, array1[ col ], array2[ col ] ); + } if ( ret !== 0 ) { return ret; } } // Fall back to index number column to ensure stable sort - return sortText.call( this, array1[ array1.length - 1 ], array2[ array2.length - 1 ] ); + return sortAsc.call( this, array1[ array1.length - 1 ], array2[ array2.length - 1 ] ); } ); return cache; } @@ -860,6 +870,11 @@ // scripts may call .tablesorter() before they have done the // tableSorterCollation customizations. buildCollationTable(); + if( typeof Intl !== 'undefined' ){ + if ( Intl.Collator.supportedLocalesOf( mw.config.get( 'wgContentLanguage' ), { numeric: true } ).length > 0 ) { + ts.collator = new Intl.Collator( mw.config.get( 'wgContentLanguage' ), { numeric: true } ); + } + } // Legacy fix of .sortbottoms // Wrap them inside a tfoot (because that's what they actually want to be) @@ -1091,10 +1106,10 @@ }, format: function ( s ) { var tsc; - s = $.trim( s.toLowerCase() ); - if ( ts.collationRegex ) { + s = $.trim( s ); + if ( !ts.collator && ts.collationRegex ) { tsc = ts.collationTable; - s = s.replace( ts.collationRegex, function ( match ) { + s = s.toLowerCase().replace( ts.collationRegex, function ( match ) { var r = tsc[ match ] ? tsc[ match ] : tsc[ match.toUpperCase() ]; return r.toLowerCase(); } ); -- To view, visit https://gerrit.wikimedia.org/r/386858 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I271fcccdbd19c1fe1db39d442d934a6b4382514d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: TheDJ <hartman.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits