Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js |
— | — | @@ -575,6 +575,47 @@ |
576 | 576 | ); |
577 | 577 | // TODO add numbers sorting tests for bug 8115 with a different language |
578 | 578 | |
| 579 | +var fractions = [ |
| 580 | + [ '56' ], |
| 581 | + [ '1 3/8' ], |
| 582 | + [ '4 7/8' ], |
| 583 | + [ '2,000 1/6' ], |
| 584 | + [ '4 1/8' ], |
| 585 | + [ '-4 1/8' ], |
| 586 | + [ '−5 1/8' ], |
| 587 | + [ '56 45/500' ], |
| 588 | + [ '56 100/500' ], |
| 589 | + [ '100 / 500' ] |
| 590 | +]; |
| 591 | +var fractionsAsc = [ |
| 592 | + [ '−5 1/8' ], |
| 593 | + [ '-4 1/8' ], |
| 594 | + [ '100 / 500' ], |
| 595 | + [ '1 3/8' ], |
| 596 | + [ '4 1/8' ], |
| 597 | + [ '4 7/8' ], |
| 598 | + [ '56' ], |
| 599 | + [ '56 45/500' ], |
| 600 | + [ '56 100/500' ], |
| 601 | + [ '2,000 1/6' ] |
| 602 | +]; |
| 603 | + |
| 604 | +tableTest( 'sort fractional numbers in all sorts and forms (ascending)', |
| 605 | + ['Fractional numbers'], fractions, fractionsAsc, |
| 606 | + function( $table ) { |
| 607 | + $table.tablesorter(); |
| 608 | + $table.find( '.headerSort:eq(0)' ).click(); |
| 609 | + } |
| 610 | +); |
| 611 | + |
| 612 | +tableTest( 'sort fractional numbers in all sorts and forms (descending)', |
| 613 | + ['Fractional numbers'], fractions, reversed(fractionsAsc), |
| 614 | + function( $table ) { |
| 615 | + $table.tablesorter(); |
| 616 | + $table.find( '.headerSort:eq(0)' ).click().click(); |
| 617 | + } |
| 618 | +); |
| 619 | + |
579 | 620 | test( 'bug 32888 - Tables inside a tableheader cell', function() { |
580 | 621 | expect(2); |
581 | 622 | |
Index: trunk/phase3/RELEASE-NOTES-1.20 |
— | — | @@ -21,6 +21,7 @@ |
22 | 22 | contentSub, ... The same div often also contains the class mw-content-ltr/rtl. |
23 | 23 | * (bug 34475) Add support for IP/CIDR notation to tablesorter |
24 | 24 | * (bug 27619) Remove preference option to display broken links as link? |
| 25 | +* (bug 15404) Add support for sorting fractions in jquery.tablesorter |
25 | 26 | |
26 | 27 | === Bug fixes in 1.20 === |
27 | 28 | * (bug 30245) Use the correct way to construct a log page title. |
Index: trunk/phase3/resources/jquery/jquery.tablesorter.js |
— | — | @@ -402,12 +402,13 @@ |
403 | 403 | digits.push( $.escapeRE( localised[i] ) ); |
404 | 404 | } |
405 | 405 | } |
406 | | - var digitClass = '[' + digits.join( '', digits ) + ']'; |
| 406 | + ts.digitClass = '[' + digits.join( '', digits ) + ']'; |
407 | 407 | |
408 | 408 | // We allow a trailing percent sign, which we just strip. This works fine |
409 | 409 | // if percents and regular numbers aren't being mixed. |
410 | 410 | ts.numberRegex = new RegExp("^(" + "[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific |
411 | | - "|" + "[-+\u2212]?" + digitClass + "+[\\s\\xa0]*%?" + // Generic localised |
| 411 | + "|" + "[-+\u2212]?" + ts.digitClass + "+[\\s\\xa0]*%?" + // Generic localised |
| 412 | + "|([-+\u2212]?" + ts.digitClass + "+[\\s\\xa0]+)*" + ts.digitClass + "+[\\s\\xa0]*[\\/][\\s\\xa0]*" + ts.digitClass + "+" + // Fractions |
412 | 413 | ")$", "i"); |
413 | 414 | } |
414 | 415 | |
— | — | @@ -502,6 +503,9 @@ |
503 | 504 | ], |
504 | 505 | time: [ |
505 | 506 | new RegExp( /^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/) |
| 507 | + ], |
| 508 | + fractions: [ |
| 509 | + new RegExp( "^(?:([-+\u2212]?" + ts.digitClass + "+)[\\s\\xa0]+)*(" + ts.digitClass + "+)[\\s\\xa0]*[\\/][\\s\\xa0]*(" + ts.digitClass + "+)" ) |
506 | 510 | ] |
507 | 511 | }; |
508 | 512 | } |
— | — | @@ -909,6 +913,19 @@ |
910 | 914 | return $.tablesorter.numberRegex.test( $.trim( s )); |
911 | 915 | }, |
912 | 916 | format: function( s ) { |
| 917 | + var values = ts.rgx.fractions[0].exec($.trim(s)); |
| 918 | + if( values != null ) { |
| 919 | + // A fraction |
| 920 | + var retVal = 0; |
| 921 | + var decimal = $.tablesorter.formatDigit(values[2]) / $.tablesorter.formatDigit(values[3]); |
| 922 | + if( values[1] != undefined ) { |
| 923 | + retVal = $.tablesorter.formatDigit(values[1]); |
| 924 | + } |
| 925 | + if( !isNaN(decimal) && isFinite(decimal) ) { |
| 926 | + retVal += decimal; |
| 927 | + } |
| 928 | + return retVal; |
| 929 | + } |
913 | 930 | return $.tablesorter.formatDigit(s); |
914 | 931 | }, |
915 | 932 | type: 'numeric' |