(bug 39284) Improve the tablesorter for currency.
authorDerk-Jan Hartman <hartman@videolan.org>
Thu, 23 Aug 2012 22:12:12 +0000 (00:12 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Fri, 24 Aug 2012 15:23:48 +0000 (17:23 +0200)
* 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

RELEASE-NOTES-1.20
resources/jquery/jquery.tablesorter.js
tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js

index 20fdcea..92f050e 100644 (file)
@@ -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.
index 21dc3e1..3ef71d5 100644 (file)
                                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):\/\/$/),
index 7d8c1d6..16d8170 100644 (file)
@@ -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 ) );