From: Derk-Jan Hartman Date: Thu, 23 Aug 2012 22:12:12 +0000 (+0200) Subject: (bug 39284) Improve the tablesorter for currency. X-Git-Tag: 1.31.0-rc.0~22607 X-Git-Url: http://git.cyclocoop.org/%24self?a=commitdiff_plain;h=6fe1f2c755dcdcfe82f8245cd78baa69aeb67c1e;p=lhc%2Fweb%2Fwiklou.git (bug 39284) Improve the tablesorter for currency. * Make the detector for currency not trigger on cells starting with "." or "?". * Make it trigger on values ending with a currency symbol. * Add the Yen sign. * Add a basic unit test. Change-Id: I3c1fdf41db04ea0726ba7613fa5e1365f8fb8493 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 20fdceaadb..92f050e68e 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -206,7 +206,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. * (bug 37331) ResourceLoader modules sometimes execute twice in Firefox * (bug 31644) GlobalUsage, CentralAuth and AbuseLog extensions should not use insecure links to foreign wikis in the WikiMap. -* (bug 36073) Avoid duplicate element IDs on File pages +* (bug 36073) Avoid duplicate element IDs on File pages. * (bug 25095) Special:Categories should also include the first relevant item when "from" is filled. * (bug 35526) jquery.tablesorter now uses a stable sort. @@ -215,14 +215,15 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. are returned, like in previous versions. * (bug 36524) "Show" options on Special:RecentChanges and Special:RecentChangesLinked are now remembered between successive clicks. -* (bug 26069) Page title is no longer "Error" for all error pages +* (bug 26069) Page title is no longer "Error" for all error pages. * (bug 39297) Show warning if thumbnail of animated image will not be animated. * (bug 38249) Parser will throw an exception instead of outputting gibberish if PCRE is compiled without support for unicode properties. * (bug 30390) Suggested file name on Special:Upload should not contain illegal characters. -* (bug 27111) Cascading foreign file repos now fetch shared descriptions properly -* EXIF below sea level GPS altitude data is now shown correctly +* (bug 27111) Cascading foreign file repos now fetch shared descriptions properly. +* EXIF below sea level GPS altitude data is now shown correctly. +* (bug 39284) jquery.tablesorter should not consider "."" or "?"" to be a currency. === API changes in 1.20 === * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API. diff --git a/resources/jquery/jquery.tablesorter.js b/resources/jquery/jquery.tablesorter.js index 21dc3e1520..3ef71d573c 100644 --- a/resources/jquery/jquery.tablesorter.js +++ b/resources/jquery/jquery.tablesorter.js @@ -461,8 +461,8 @@ new RegExp( /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/) ], currency: [ - new RegExp( /^[£$€?.]/), - new RegExp( /[£$€]/g) + new RegExp( /(^[£$€¥]|[£$€¥]$)/), + new RegExp( /[£$€¥]/g) ], url: [ new RegExp( /^(https?|ftp|file):\/\/$/), diff --git a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js index 7d8c1d6044..16d8170790 100644 --- a/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js +++ b/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js @@ -1,4 +1,4 @@ -( function ( $ ) { +( function ( $, mw ) { var config = { wgMonthNames: ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'], @@ -345,11 +345,11 @@ var complexMDYDates = [ ]; var complexMDYSorted = [ - ["5.12.1990"], - ["April 21 1991"], - ["04 22 1991"], - ["January, 19 2010"], - ["December 12 '10"] + ['5.12.1990'], + ['April 21 1991'], + ['04 22 1991'], + ['January, 19 2010'], + ['December 12 \'10'] ]; tableTest( @@ -365,6 +365,39 @@ tableTest( } ); +var currencyUnsorted = [ + ['1.02 $'], + ['$ 3.00'], + ['€ 2,99'], + ['$ 1.00'], + ['$3.50'], + ['$ 1.50'], + ['€ 0.99'] +]; + +var currencySorted = [ + ['€ 0.99'], + ['$ 1.00'], + ['1.02 $'], + ['$ 1.50'], + ['$ 3.00'], + ['$3.50'], + // Comma's sort after dots + // Not intentional but test to detect changes + ['€ 2,99'] +]; + +tableTest( + 'Currency parsing I', + ['currency'], + currencyUnsorted, + currencySorted, + function ( $table ) { + $table.tablesorter(); + $table.find( '.headerSort:eq(0)' ).click(); + } +); + var ascendingNameLegacy = ascendingName.slice(0); ascendingNameLegacy[4] = ascendingNameLegacy[5]; ascendingNameLegacy.pop(); @@ -381,6 +414,7 @@ tableTest( } ); + /** FIXME: the diff output is not very readeable. */ QUnit.test( 'bug 32047 - caption must be before thead', function ( assert ) { var $table; @@ -660,4 +694,4 @@ tableTest( } ); -}( jQuery ) ); +}( jQuery, mediaWiki ) );