2 * TableSorter for MediaWiki
4 * Written 2011 Leo Koppelkamm
5 * Based on tablesorter.com plugin, written (c) 2007 Christian Bach.
7 * Dual licensed under the MIT and GPL licenses:
8 * http://www.opensource.org/licenses/mit-license.php
9 * http://www.gnu.org/licenses/gpl.html
11 * Depends on mw.config (wgDigitTransformTable, wgMonthNames, wgMonthNamesShort,
12 * wgDefaultDateFormat, wgContentLanguage)
13 * Uses 'tableSorterCollation' in mw.config (if available)
17 * @description Create a sortable table with multi-column sorting capabilitys
19 * @example $( 'table' ).tablesorter();
20 * @desc Create a simple tablesorter interface.
22 * @example $( 'table' ).tablesorter( { sortList: [ { 0: 'desc' }, { 1: 'asc' } ] } );
23 * @desc Create a tablesorter interface initially sorting on the first and second column.
25 * @option String cssHeader ( optional ) A string of the class name to be appended
26 * to sortable tr elements in the thead of the table. Default value:
29 * @option String cssAsc ( optional ) A string of the class name to be appended to
30 * sortable tr elements in the thead on a ascending sort. Default value:
33 * @option String cssDesc ( optional ) A string of the class name to be appended
34 * to sortable tr elements in the thead on a descending sort. Default
35 * value: "headerSortDown"
37 * @option String sortInitialOrder ( optional ) A string of the inital sorting
38 * order can be asc or desc. Default value: "asc"
40 * @option String sortMultisortKey ( optional ) A string of the multi-column sort
41 * key. Default value: "shiftKey"
43 * @option Boolean sortLocaleCompare ( optional ) Boolean flag indicating whatever
44 * to use String.localeCampare method or not. Set to false.
46 * @option Boolean cancelSelection ( optional ) Boolean flag indicating if
47 * tablesorter should cancel selection of the table headers text.
50 * @option Array sortList ( optional ) An array containing objects specifying sorting.
51 * By passing more than one object, multi-sorting will be applied. Object structure:
52 * { <Integer column index>: <String 'asc' or 'desc'> }
55 * @option Boolean debug ( optional ) Boolean flag indicating if tablesorter
56 * should display debuging information usefull for development.
58 * @event sortEnd.tablesorter: Triggered as soon as any sorting has been applied.
64 * @cat Plugins/Tablesorter
66 * @author Christian Bach/christian.bach@polyester.se
69 ( function ( $, mw
) {
70 /*jshint onevar:false */
77 /* Parser utility functions */
79 function getParserById( name
) {
80 var len
= parsers
.length
;
81 for ( var i
= 0; i
< len
; i
++ ) {
82 if ( parsers
[i
].id
.toLowerCase() === name
.toLowerCase() ) {
89 function getElementSortKey( node
) {
90 var $node
= $( node
),
91 // Use data-sort-value attribute.
92 // Use data() instead of attr() so that live value changes
93 // are processed as well (bug 38152).
94 data
= $node
.data( 'sortValue' );
96 if ( data
!== null && data
!== undefined ) {
97 // Cast any numbers or other stuff to a string, methods
98 // like charAt, toLowerCase and split are expected.
99 return String( data
);
101 if ( node
.tagName
.toLowerCase() === 'img' ) {
102 return $node
.attr( 'alt' ) || ''; // handle undefined alt
104 return $.map( $.makeArray( node
.childNodes
), function( elem
) {
105 // 1 is for document.ELEMENT_NODE (the constant is undefined on old browsers)
106 if ( elem
.nodeType
=== 1 ) {
107 return getElementSortKey( elem
);
109 return $.text( elem
);
116 function getTextFromRowAndCellIndex( rows
, rowIndex
, cellIndex
) {
117 if ( rows
[rowIndex
] && rows
[rowIndex
].cells
[cellIndex
] ) {
118 return $.trim( getElementSortKey( rows
[rowIndex
].cells
[cellIndex
] ) );
124 function detectParserForColumn( table
, rows
, cellIndex
) {
125 var l
= parsers
.length
,
127 // Start with 1 because 0 is the fallback parser
131 needed
= ( rows
.length
> 4 ) ? 5 : rows
.length
;
134 nodeValue
= getTextFromRowAndCellIndex( rows
, rowIndex
, cellIndex
);
135 if ( nodeValue
!== '') {
136 if ( parsers
[i
].is( nodeValue
, table
) ) {
139 if ( concurrent
>= needed
) {
140 // Confirmed the parser for multiple cells, let's return it
144 // Check next parser, reset rows
152 if ( rowIndex
> rows
.length
) {
159 // 0 is always the generic parser (text)
163 function buildParserCache( table
, $headers
) {
164 var rows
= table
.tBodies
[0].rows
,
170 var cells
= rows
[0].cells
,
174 for ( i
= 0; i
< len
; i
++ ) {
176 sortType
= $headers
.eq( i
).data( 'sortType' );
177 if ( sortType
!== undefined ) {
178 parser
= getParserById( sortType
);
181 if ( parser
=== false ) {
182 parser
= detectParserForColumn( table
, rows
, i
);
185 parsers
.push( parser
);
191 /* Other utility functions */
193 function buildCache( table
) {
194 var totalRows
= ( table
.tBodies
[0] && table
.tBodies
[0].rows
.length
) || 0,
195 totalCells
= ( table
.tBodies
[0].rows
[0] && table
.tBodies
[0].rows
[0].cells
.length
) || 0,
196 parsers
= table
.config
.parsers
,
202 for ( var i
= 0; i
< totalRows
; ++i
) {
204 // Add the table data to main data array
205 var $row
= $( table
.tBodies
[0].rows
[i
] ),
208 // if this is a child row, add it to the last row's children and
209 // continue to the next row
210 if ( $row
.hasClass( table
.config
.cssChildRow
) ) {
211 cache
.row
[cache
.row
.length
- 1] = cache
.row
[cache
.row
.length
- 1].add( $row
);
212 // go to the next for loop
216 cache
.row
.push( $row
);
218 for ( var j
= 0; j
< totalCells
; ++j
) {
219 cols
.push( parsers
[j
].format( getElementSortKey( $row
[0].cells
[j
] ), table
, $row
[0].cells
[j
] ) );
222 cols
.push( cache
.normalized
.length
); // add position for rowCache
223 cache
.normalized
.push( cols
);
230 function appendToTable( table
, cache
) {
232 normalized
= cache
.normalized
,
233 totalRows
= normalized
.length
,
234 checkCell
= ( normalized
[0].length
- 1 ),
235 fragment
= document
.createDocumentFragment();
237 for ( var i
= 0; i
< totalRows
; i
++ ) {
238 var pos
= normalized
[i
][checkCell
];
240 var l
= row
[pos
].length
;
242 for ( var j
= 0; j
< l
; j
++ ) {
243 fragment
.appendChild( row
[pos
][j
] );
247 table
.tBodies
[0].appendChild( fragment
);
249 $( table
).trigger( 'sortEnd.tablesorter' );
253 * Find all header rows in a thead-less table and put them in a <thead> tag.
254 * This only treats a row as a header row if it contains only <th>s (no <td>s)
255 * and if it is preceded entirely by header rows. The algorithm stops when
256 * it encounters the first non-header row.
258 * After this, it will look at all rows at the bottom for footer rows
259 * And place these in a tfoot using similar rules.
260 * @param $table jQuery object for a <table>
262 function emulateTHeadAndFoot( $table
) {
263 var $rows
= $table
.find( '> tbody > tr' );
264 if( !$table
.get(0).tHead
) {
265 var $thead
= $( '<thead>' );
266 $rows
.each( function () {
267 if ( $(this).children( 'td' ).length
> 0 ) {
268 // This row contains a <td>, so it's not a header row
272 $thead
.append( this );
274 $table
.find(' > tbody:first').before( $thead
);
276 if( !$table
.get(0).tFoot
) {
277 var $tfoot
= $( '<tfoot>' );
278 var len
= $rows
.length
;
279 for ( var i
= len
-1; i
>= 0; i
-- ) {
280 if( $( $rows
[i
] ).children( 'td' ).length
> 0 ){
283 $tfoot
.prepend( $( $rows
[i
] ));
285 $table
.append( $tfoot
);
289 function buildHeaders( table
, msg
) {
293 $tableHeaders
= $( 'thead:eq(0) > tr', table
);
294 if ( $tableHeaders
.length
> 1 ) {
295 $tableHeaders
.each( function () {
296 if ( this.cells
.length
> maxSeen
) {
297 maxSeen
= this.cells
.length
;
301 $tableHeaders
= $( longest
);
303 $tableHeaders
= $tableHeaders
.children( 'th' ).each( function ( index
) {
304 this.column
= realCellIndex
;
306 var colspan
= this.colspan
;
307 colspan
= colspan
? parseInt( colspan
, 10 ) : 1;
308 realCellIndex
+= colspan
;
313 if ( $( this ).is( '.unsortable' ) ) {
314 this.sortDisabled
= true;
317 if ( !this.sortDisabled
) {
318 $( this ).addClass( table
.config
.cssHeader
).attr( 'title', msg
[1] );
321 // add cell to headerList
322 table
.config
.headerList
[index
] = this;
325 return $tableHeaders
;
329 function isValueInArray( v
, a
) {
331 for ( var i
= 0; i
< l
; i
++ ) {
332 if ( a
[i
][0] === v
) {
339 function setHeadersCss( table
, $headers
, list
, css
, msg
, columnToHeader
) {
340 // Remove all header information and reset titles to default message
341 $headers
.removeClass( css
[0] ).removeClass( css
[1] ).attr( 'title', msg
[1] );
343 for ( var i
= 0; i
< list
.length
; i
++ ) {
344 $headers
.eq( columnToHeader
[ list
[i
][0] ] )
345 .addClass( css
[ list
[i
][1] ] )
346 .attr( 'title', msg
[ list
[i
][1] ] );
350 function sortText( a
, b
) {
351 return ( (a
< b
) ? -1 : ((a
> b
) ? 1 : 0) );
354 function sortTextDesc( a
, b
) {
355 return ( (b
< a
) ? -1 : ((b
> a
) ? 1 : 0) );
358 function multisort( table
, sortList
, cache
) {
360 var len
= sortList
.length
;
361 for ( var i
= 0; i
< len
; i
++ ) {
362 sortFn
[i
] = ( sortList
[i
][1] ) ? sortTextDesc
: sortText
;
364 cache
.normalized
.sort( function ( array1
, array2
) {
366 for ( var i
= 0; i
< len
; i
++ ) {
367 col
= sortList
[i
][0];
368 ret
= sortFn
[i
].call( this, array1
[col
], array2
[col
] );
373 // Fall back to index number column to ensure stable sort
374 return sortText
.call( this, array1
[array1
.length
- 1], array2
[array2
.length
- 1] );
379 function buildTransformTable() {
380 var digits
= '0123456789,.'.split( '' );
381 var separatorTransformTable
= mw
.config
.get( 'wgSeparatorTransformTable' );
382 var digitTransformTable
= mw
.config
.get( 'wgDigitTransformTable' );
383 if ( separatorTransformTable
=== null || ( separatorTransformTable
[0] === '' && digitTransformTable
[2] === '' ) ) {
384 ts
.transformTable
= false;
386 ts
.transformTable
= {};
388 // Unpack the transform table
389 var ascii
= separatorTransformTable
[0].split( '\t' ).concat( digitTransformTable
[0].split( '\t' ) );
390 var localised
= separatorTransformTable
[1].split( '\t' ).concat( digitTransformTable
[1].split( '\t' ) );
392 // Construct regex for number identification
393 for ( var i
= 0; i
< ascii
.length
; i
++ ) {
394 ts
.transformTable
[localised
[i
]] = ascii
[i
];
395 digits
.push( $.escapeRE( localised
[i
] ) );
398 var digitClass
= '[' + digits
.join( '', digits
) + ']';
400 // We allow a trailing percent sign, which we just strip. This works fine
401 // if percents and regular numbers aren't being mixed.
402 ts
.numberRegex
= new RegExp('^(' + '[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?' + // Fortran-style scientific
403 '|' + '[-+\u2212]?' + digitClass
+ '+[\\s\\xa0]*%?' + // Generic localised
407 function buildDateTable() {
411 for ( var i
= 1; i
< 13; i
++ ) {
412 var name
= mw
.config
.get( 'wgMonthNames' )[i
].toLowerCase();
413 ts
.monthNames
[name
] = i
;
414 regex
.push( $.escapeRE( name
) );
415 name
= mw
.config
.get( 'wgMonthNamesShort' )[i
].toLowerCase().replace( '.', '' );
416 ts
.monthNames
[name
] = i
;
417 regex
.push( $.escapeRE( name
) );
420 // Build piped string
421 regex
= regex
.join( '|' );
424 // Any date formated with . , ' - or /
425 ts
.dateRegex
[0] = new RegExp( /^\s*(\d{1,2})[\,\.\-\/'\s]{1,2}(\d{1,2})[\,\.\-\/'\s]{1,2}(\d{2,4})\s*?/i);
427 // Written Month name, dmy
428 ts
.dateRegex
[1] = new RegExp( '^\\s*(\\d{1,2})[\\,\\.\\-\\/\'\\s]*(' + regex
+ ')' + '[\\,\\.\\-\\/\'\\s]*(\\d{2,4})\\s*$', 'i' );
430 // Written Month name, mdy
431 ts
.dateRegex
[2] = new RegExp( '^\\s*(' + regex
+ ')' + '[\\,\\.\\-\\/\'\\s]*(\\d{1,2})[\\,\\.\\-\\/\'\\s]*(\\d{2,4})\\s*$', 'i' );
435 function explodeRowspans( $table
) {
436 // Split multi row cells into multiple cells with the same content
437 $table
.find( '> tbody > tr > [rowspan]' ).each(function () {
438 var rowSpan
= this.rowSpan
;
440 var cell
= $( this );
441 var next
= cell
.parent().nextAll();
442 for ( var i
= 0; i
< rowSpan
- 1; i
++ ) {
443 var td
= next
.eq( i
).children( 'td' );
445 next
.eq( i
).append( cell
.clone() );
446 } else if ( this.cellIndex
=== 0 ) {
447 td
.eq( this.cellIndex
).before( cell
.clone() );
449 td
.eq( this.cellIndex
- 1 ).after( cell
.clone() );
455 function buildCollationTable() {
456 ts
.collationTable
= mw
.config
.get( 'tableSorterCollation' );
457 ts
.collationRegex
= null;
458 if ( ts
.collationTable
) {
461 // Build array of key names
462 for ( var key
in ts
.collationTable
) {
463 if ( ts
.collationTable
.hasOwnProperty(key
) ) { //to be safe
468 ts
.collationRegex
= new RegExp( '[' + keys
.join( '' ) + ']', 'ig' );
473 function cacheRegexs() {
479 new RegExp( /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/)
482 new RegExp( /(^[£$€¥]|[£$€¥]$)/),
483 new RegExp( /[£$€¥]/g)
486 new RegExp( /^(https?|ftp|file):\/\/$/),
487 new RegExp( /(https?|ftp|file):\/\//)
490 new RegExp( /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/)
493 new RegExp( /^[A-Za-z]{3,10}\.? [0-9]{1,2}, ([0-9]{4}|'?[0-9]{2}) (([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(AM|PM)))$/)
496 new RegExp( /^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/)
502 * Converts sort objects [ { Integer: String }, ... ] to the internally used nested array
503 * structure [ [ Integer , Integer ], ... ]
505 * @param sortObjects {Array} List of sort objects.
506 * @return {Array} List of internal sort definitions.
509 function convertSortList( sortObjects
) {
511 $.each( sortObjects
, function( i
, sortObject
) {
512 $.each ( sortObject
, function( columnIndex
, order
) {
513 var orderIndex
= ( order
=== 'desc' ) ? 1 : 0;
514 sortList
.push( [columnIndex
, orderIndex
] );
525 cssHeader
: 'headerSort',
526 cssAsc
: 'headerSortUp',
527 cssDesc
: 'headerSortDown',
528 cssChildRow
: 'expand-child',
529 sortInitialOrder
: 'asc',
530 sortMultiSortKey
: 'shiftKey',
531 sortLocaleCompare
: false,
535 cancelSelection
: true,
538 selectorHeaders
: 'thead tr:eq(0) th',
546 * @param $tables {jQuery}
547 * @param settings {Object} (optional)
549 construct: function ( $tables
, settings
) {
550 return $tables
.each( function ( i
, table
) {
551 // Declare and cache.
552 var $headers
, cache
, config
,
553 headerToColumns
, columnToHeader
, colspanOffset
,
558 if ( !table
.tBodies
) {
561 if ( !table
.tHead
) {
562 // No thead found. Look for rows with <th>s and
563 // move them into a <thead> tag or a <tfoot> tag
564 emulateTHeadAndFoot( $table
);
566 // Still no thead? Then quit
567 if ( !table
.tHead
) {
571 $table
.addClass( 'jquery-tablesorter' );
573 // FIXME config should probably not be stored in the plain table node
574 // New config object.
578 config
= $.extend( table
.config
, $.tablesorter
.defaultOptions
, settings
);
580 // Save the settings where they read
581 $.data( table
, 'tablesorter', { config
: config
} );
583 // Get the CSS class names, could be done else where.
584 var sortCSS
= [ config
.cssDesc
, config
.cssAsc
];
585 var sortMsg
= [ mw
.msg( 'sort-descending' ), mw
.msg( 'sort-ascending' ) ];
588 $headers
= buildHeaders( table
, sortMsg
);
590 // Grab and process locale settings
591 buildTransformTable();
593 buildCollationTable();
595 // Precaching regexps can bring 10 fold
596 // performance improvements in some browsers.
599 function setupForFirstSort() {
602 // Legacy fix of .sortbottoms
603 // Wrap them inside inside a tfoot (because that's what they actually want to be) &
604 // and put the <tfoot> at the end of the <table>
605 var $sortbottoms
= $table
.find( '> tbody > tr.sortbottom' );
606 if ( $sortbottoms
.length
) {
607 var $tfoot
= $table
.children( 'tfoot' );
608 if ( $tfoot
.length
) {
609 $tfoot
.eq(0).prepend( $sortbottoms
);
611 $table
.append( $( '<tfoot>' ).append( $sortbottoms
) );
615 explodeRowspans( $table
);
617 // try to auto detect column type, and store in tables config
618 table
.config
.parsers
= buildParserCache( table
, $headers
);
621 // as each header can span over multiple columns (using colspan=N),
622 // we have to bidirectionally map headers to their columns and columns to their headers
623 headerToColumns
= [];
626 $headers
.each( function ( headerIndex
) {
628 for ( var i
= 0; i
< this.colSpan
; i
++ ) {
629 columnToHeader
[ colspanOffset
+ i
] = headerIndex
;
630 columns
.push( colspanOffset
+ i
);
633 headerToColumns
[ headerIndex
] = columns
;
634 colspanOffset
+= this.colSpan
;
637 // Apply event handling to headers
638 // this is too big, perhaps break it out?
639 $headers
.filter( ':not(.unsortable)' ).click( function ( e
) {
640 if ( e
.target
.nodeName
.toLowerCase() === 'a' ) {
641 // The user clicked on a link inside a table header
642 // Do nothing and let the default link click action continue
650 // Build the cache for the tbody cells
651 // to share between calculations for this sort action.
652 // Re-calculated each time a sort action is performed due to possiblity
653 // that sort values change. Shouldn't be too expensive, but if it becomes
654 // too slow an event based system should be implemented somehow where
655 // cells get event .change() and bubbles up to the <table> here
656 cache
= buildCache( table
);
658 var totalRows
= ( $table
[0].tBodies
[0] && $table
[0].tBodies
[0].rows
.length
) || 0;
659 if ( !table
.sortDisabled
&& totalRows
> 0 ) {
660 // Get current column sort order
661 this.order
= this.count
% 2;
665 // Get current column index
666 var columns
= headerToColumns
[this.column
];
667 var newSortList
= $.map( columns
, function (c
) {
668 // jQuery "helpfully" flattens the arrays...
669 return [[c
, cell
.order
]];
671 // Index of first column belonging to this header
674 if ( !e
[config
.sortMultiSortKey
] ) {
675 // User only wants to sort on one column set
676 // Flush the sort list and add new columns
677 config
.sortList
= newSortList
;
679 // Multi column sorting
680 // It is not possible for one column to belong to multiple headers,
681 // so this is okay - we don't need to check for every value in the columns array
682 if ( isValueInArray( i
, config
.sortList
) ) {
683 // The user has clicked on an already sorted column.
684 // Reverse the sorting direction for all tables.
685 for ( var j
= 0; j
< config
.sortList
.length
; j
++ ) {
686 var s
= config
.sortList
[j
],
687 o
= config
.headerList
[s
[0]];
688 if ( isValueInArray( s
[0], newSortList
) ) {
695 // Add columns to sort list array
696 config
.sortList
= config
.sortList
.concat( newSortList
);
700 // Set CSS for headers
701 setHeadersCss( $table
[0], $headers
, config
.sortList
, sortCSS
, sortMsg
, columnToHeader
);
703 $table
[0], multisort( $table
[0], config
.sortList
, cache
)
706 // Stop normal event by returning false
711 } ).mousedown( function () {
712 if ( config
.cancelSelection
) {
713 this.onselectstart = function () {
721 * Sorts the table. If no sorting is specified by passing a list of sort
722 * objects, the table is sorted according to the initial sorting order.
723 * Passing an empty array will reset sorting (basically just reset the headers
724 * making the table appear unsorted).
726 * @param sortList {Array} (optional) List of sort objects.
728 $table
.data( 'tablesorter' ).sort = function( sortList
) {
734 if ( sortList
=== undefined ) {
735 sortList
= config
.sortList
;
736 } else if ( sortList
.length
> 0 ) {
737 sortList
= convertSortList( sortList
);
740 // re-build the cache for the tbody cells
741 cache
= buildCache( table
);
743 // set css for headers
744 setHeadersCss( table
, $headers
, sortList
, sortCSS
, sortMsg
, columnToHeader
);
746 // sort the table and append it to the dom
747 appendToTable( table
, multisort( table
, sortList
, cache
) );
751 if ( config
.sortList
.length
> 0 ) {
753 config
.sortList
= convertSortList( config
.sortList
);
754 $table
.data( 'tablesorter' ).sort();
760 addParser: function ( parser
) {
761 var l
= parsers
.length
,
763 for ( var i
= 0; i
< l
; i
++ ) {
764 if ( parsers
[i
].id
.toLowerCase() === parser
.id
.toLowerCase() ) {
769 parsers
.push( parser
);
773 formatDigit: function ( s
) {
775 if ( ts
.transformTable
!== false ) {
777 for ( p
= 0; p
< s
.length
; p
++ ) {
779 if ( c
in ts
.transformTable
) {
780 out
+= ts
.transformTable
[c
];
787 i
= parseFloat( s
.replace( /[, ]/g, '' ).replace( '\u2212', '-' ) );
788 return isNaN( i
) ? 0 : i
;
791 formatFloat: function ( s
) {
792 var i
= parseFloat(s
);
793 return isNaN( i
) ? 0 : i
;
796 formatInt: function ( s
) {
797 var i
= parseInt( s
, 10 );
798 return isNaN( i
) ? 0 : i
;
801 clearTableBody: function ( table
) {
802 $( table
.tBodies
[0] ).empty();
809 // Register as jQuery prototype method
810 $.fn
.tablesorter = function ( settings
) {
811 return ts
.construct( this, settings
);
814 // Add default parsers
820 format: function ( s
) {
821 s
= $.trim( s
.toLowerCase() );
822 if ( ts
.collationRegex
) {
823 var tsc
= ts
.collationTable
;
824 s
= s
.replace( ts
.collationRegex
, function ( match
) {
825 var r
= tsc
[match
] ? tsc
[match
] : tsc
[match
.toUpperCase()];
826 return r
.toLowerCase();
837 return ts
.rgx
.IPAddress
[0].test(s
);
839 format: function ( s
) {
840 var a
= s
.split( '.' ),
843 for ( var i
= 0; i
< l
; i
++ ) {
845 if ( item
.length
=== 1 ) {
847 } else if ( item
.length
=== 2 ) {
853 return $.tablesorter
.formatFloat(r
);
861 return ts
.rgx
.currency
[0].test(s
);
863 format: function ( s
) {
864 return $.tablesorter
.formatDigit( s
.replace( ts
.rgx
.currency
[1], '' ) );
872 return ts
.rgx
.url
[0].test(s
);
874 format: function ( s
) {
875 return $.trim( s
.replace( ts
.rgx
.url
[1], '' ) );
883 return ts
.rgx
.isoDate
[0].test(s
);
885 format: function ( s
) {
886 return $.tablesorter
.formatFloat((s
!== '') ? new Date(s
.replace(
887 new RegExp( /-/g), '/')).getTime() : '0' );
895 return ts.rgx.usLongDate[0].test(s);
897 format: function ( s ) {
898 return $.tablesorter.formatFloat( new Date(s).getTime() );
906 return ( ts.dateRegex[0].test(s) || ts.dateRegex[1].test(s) || ts.dateRegex[2].test(s ));
908 format: function ( s ) {
910 s = $.trim( s.toLowerCase() );
912 if ( ( match = s.match( ts.dateRegex[0] ) ) !== null ) {
913 if ( mw.config.get( 'wgDefaultDateFormat
' ) === 'mdy
' || mw.config.get( 'wgContentLanguage
' ) === 'en
' ) {
914 s = [ match[3], match[1], match[2] ];
915 } else if ( mw.config.get( 'wgDefaultDateFormat
' ) === 'dmy
' ) {
916 s = [ match[3], match[2], match[1] ];
918 // If we get here, we don't know which order the dd
-dd
-dddd
919 // date is in. So return something not entirely invalid.
922 } else if ( ( match
= s
.match( ts
.dateRegex
[1] ) ) !== null ) {
923 s
= [ match
[3], '' + ts
.monthNames
[match
[2]], match
[1] ];
924 } else if ( ( match
= s
.match( ts
.dateRegex
[2] ) ) !== null ) {
925 s
= [ match
[3], '' + ts
.monthNames
[match
[1]], match
[2] ];
927 // Should never get here
932 if ( s
[1].length
=== 1 ) {
935 if ( s
[2].length
=== 1 ) {
940 if ( ( y
= parseInt( s
[0], 10) ) < 100 ) {
941 // Guestimate years without centuries
948 while ( s
[0].length
< 4 ) {
951 return parseInt( s
.join( '' ), 10 );
959 return ts
.rgx
.time
[0].test(s
);
961 format: function ( s
) {
962 return $.tablesorter
.formatFloat( new Date( '2000/01/01 ' + s
).getTime() );
970 return $.tablesorter
.numberRegex
.test( $.trim( s
));
972 format: function ( s
) {
973 return $.tablesorter
.formatDigit(s
);
978 }( jQuery
, mediaWiki
) );