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
) {
76 /* Parser utility functions */
78 function getParserById( name
) {
79 var len
= parsers
.length
;
80 for ( var i
= 0; i
< len
; i
++ ) {
81 if ( parsers
[i
].id
.toLowerCase() === name
.toLowerCase() ) {
88 function getElementText( node
) {
89 var $node
= $( node
),
90 // Use data-sort-value attribute.
91 // Use data() instead of attr() so that live value changes
92 // are processed as well (bug 38152).
93 data
= $node
.data( 'sortValue' );
95 if ( data
!== null && data
!== undefined ) {
96 // Cast any numbers or other stuff to a string, methods
97 // like charAt, toLowerCase and split are expected.
98 return String( data
);
104 function getTextFromRowAndCellIndex( rows
, rowIndex
, cellIndex
) {
105 if ( rows
[rowIndex
] && rows
[rowIndex
].cells
[cellIndex
] ) {
106 return $.trim( getElementText( rows
[rowIndex
].cells
[cellIndex
] ) );
112 function detectParserForColumn( table
, rows
, cellIndex
) {
113 var l
= parsers
.length
,
115 // Start with 1 because 0 is the fallback parser
119 needed
= ( rows
.length
> 4 ) ? 5 : rows
.length
;
122 nodeValue
= getTextFromRowAndCellIndex( rows
, rowIndex
, cellIndex
);
123 if ( nodeValue
!== '') {
124 if ( parsers
[i
].is( nodeValue
, table
) ) {
127 if ( concurrent
>= needed
) {
128 // Confirmed the parser for multiple cells, let's return it
132 // Check next parser, reset rows
140 if ( rowIndex
> rows
.length
) {
147 // 0 is always the generic parser (text)
151 function buildParserCache( table
, $headers
) {
152 var rows
= table
.tBodies
[0].rows
,
158 var cells
= rows
[0].cells
,
162 for ( i
= 0; i
< len
; i
++ ) {
164 sortType
= $headers
.eq( i
).data( 'sortType' );
165 if ( sortType
!== undefined ) {
166 parser
= getParserById( sortType
);
169 if ( parser
=== false ) {
170 parser
= detectParserForColumn( table
, rows
, i
);
173 parsers
.push( parser
);
179 /* Other utility functions */
181 function buildCache( table
) {
182 var totalRows
= ( table
.tBodies
[0] && table
.tBodies
[0].rows
.length
) || 0,
183 totalCells
= ( table
.tBodies
[0].rows
[0] && table
.tBodies
[0].rows
[0].cells
.length
) || 0,
184 parsers
= table
.config
.parsers
,
190 for ( var i
= 0; i
< totalRows
; ++i
) {
192 // Add the table data to main data array
193 var $row
= $( table
.tBodies
[0].rows
[i
] ),
196 // if this is a child row, add it to the last row's children and
197 // continue to the next row
198 if ( $row
.hasClass( table
.config
.cssChildRow
) ) {
199 cache
.row
[cache
.row
.length
- 1] = cache
.row
[cache
.row
.length
- 1].add( $row
);
200 // go to the next for loop
204 cache
.row
.push( $row
);
206 for ( var j
= 0; j
< totalCells
; ++j
) {
207 cols
.push( parsers
[j
].format( getElementText( $row
[0].cells
[j
] ), table
, $row
[0].cells
[j
] ) );
210 cols
.push( cache
.normalized
.length
); // add position for rowCache
211 cache
.normalized
.push( cols
);
218 function appendToTable( table
, cache
) {
220 normalized
= cache
.normalized
,
221 totalRows
= normalized
.length
,
222 checkCell
= ( normalized
[0].length
- 1 ),
223 fragment
= document
.createDocumentFragment();
225 for ( var i
= 0; i
< totalRows
; i
++ ) {
226 var pos
= normalized
[i
][checkCell
];
228 var l
= row
[pos
].length
;
230 for ( var j
= 0; j
< l
; j
++ ) {
231 fragment
.appendChild( row
[pos
][j
] );
235 table
.tBodies
[0].appendChild( fragment
);
237 $( table
).trigger( 'sortEnd.tablesorter' );
241 * Find all header rows in a thead-less table and put them in a <thead> tag.
242 * This only treats a row as a header row if it contains only <th>s (no <td>s)
243 * and if it is preceded entirely by header rows. The algorithm stops when
244 * it encounters the first non-header row.
246 * After this, it will look at all rows at the bottom for footer rows
247 * And place these in a tfoot using similar rules.
248 * @param $table jQuery object for a <table>
250 function emulateTHeadAndFoot( $table
) {
251 var $rows
= $table
.find( '> tbody > tr' );
252 if( !$table
.get(0).tHead
) {
253 var $thead
= $( '<thead>' );
254 $rows
.each( function () {
255 if ( $(this).children( 'td' ).length
> 0 ) {
256 // This row contains a <td>, so it's not a header row
260 $thead
.append( this );
262 $table
.find(' > tbody:first').before( $thead
);
264 if( !$table
.get(0).tFoot
) {
265 var $tfoot
= $( '<tfoot>' );
266 var len
= $rows
.length
;
267 for ( var i
= len
-1; i
>= 0; i
-- ) {
268 if( $( $rows
[i
] ).children( 'td' ).length
> 0 ){
271 $tfoot
.prepend( $( $rows
[i
] ));
273 $table
.append( $tfoot
);
277 function buildHeaders( table
, msg
) {
281 $tableHeaders
= $( 'thead:eq(0) > tr', table
);
282 if ( $tableHeaders
.length
> 1 ) {
283 $tableHeaders
.each( function () {
284 if ( this.cells
.length
> maxSeen
) {
285 maxSeen
= this.cells
.length
;
289 $tableHeaders
= $( longest
);
291 $tableHeaders
= $tableHeaders
.children( 'th' ).each( function ( index
) {
292 this.column
= realCellIndex
;
294 var colspan
= this.colspan
;
295 colspan
= colspan
? parseInt( colspan
, 10 ) : 1;
296 realCellIndex
+= colspan
;
301 if ( $( this ).is( '.unsortable' ) ) {
302 this.sortDisabled
= true;
305 if ( !this.sortDisabled
) {
306 var $th
= $( this ).addClass( table
.config
.cssHeader
).attr( 'title', msg
[1] );
309 // add cell to headerList
310 table
.config
.headerList
[index
] = this;
313 return $tableHeaders
;
317 function isValueInArray( v
, a
) {
319 for ( var i
= 0; i
< l
; i
++ ) {
320 if ( a
[i
][0] === v
) {
327 function setHeadersCss( table
, $headers
, list
, css
, msg
) {
328 // Remove all header information and reset titles to default message
329 $headers
.removeClass( css
[0] ).removeClass( css
[1] ).attr( 'title', msg
[1] );
332 $headers
.each( function ( offset
) {
333 if ( !this.sortDisabled
) {
334 h
[this.column
] = $( this );
339 for ( var i
= 0; i
< l
; i
++ ) {
340 h
[ list
[i
][0] ].addClass( css
[ list
[i
][1] ] ).attr( 'title', msg
[ list
[i
][1] ] );
344 function sortText( a
, b
) {
345 return ( (a
< b
) ? -1 : ((a
> b
) ? 1 : 0) );
348 function sortTextDesc( a
, b
) {
349 return ( (b
< a
) ? -1 : ((b
> a
) ? 1 : 0) );
352 function multisort( table
, sortList
, cache
) {
354 var len
= sortList
.length
;
355 for ( var i
= 0; i
< len
; i
++ ) {
356 sortFn
[i
] = ( sortList
[i
][1] ) ? sortTextDesc
: sortText
;
358 cache
.normalized
.sort( function ( array1
, array2
) {
360 for ( var i
= 0; i
< len
; i
++ ) {
361 col
= sortList
[i
][0];
362 ret
= sortFn
[i
].call( this, array1
[col
], array2
[col
] );
367 // Fall back to index number column to ensure stable sort
368 return sortText
.call( this, array1
[array1
.length
- 1], array2
[array2
.length
- 1] );
373 function buildTransformTable() {
374 var digits
= '0123456789,.'.split( '' );
375 var separatorTransformTable
= mw
.config
.get( 'wgSeparatorTransformTable' );
376 var digitTransformTable
= mw
.config
.get( 'wgDigitTransformTable' );
377 if ( separatorTransformTable
=== null || ( separatorTransformTable
[0] === '' && digitTransformTable
[2] === '' ) ) {
378 ts
.transformTable
= false;
380 ts
.transformTable
= {};
382 // Unpack the transform table
383 var ascii
= separatorTransformTable
[0].split( "\t" ).concat( digitTransformTable
[0].split( "\t" ) );
384 var localised
= separatorTransformTable
[1].split( "\t" ).concat( digitTransformTable
[1].split( "\t" ) );
386 // Construct regex for number identification
387 for ( var i
= 0; i
< ascii
.length
; i
++ ) {
388 ts
.transformTable
[localised
[i
]] = ascii
[i
];
389 digits
.push( $.escapeRE( localised
[i
] ) );
392 var digitClass
= '[' + digits
.join( '', digits
) + ']';
394 // We allow a trailing percent sign, which we just strip. This works fine
395 // if percents and regular numbers aren't being mixed.
396 ts
.numberRegex
= new RegExp("^(" + "[-+\u2212]?[0-9][0-9,]*(\\.[0-9,]*)?(E[-+\u2212]?[0-9][0-9,]*)?" + // Fortran-style scientific
397 "|" + "[-+\u2212]?" + digitClass
+ "+[\\s\\xa0]*%?" + // Generic localised
401 function buildDateTable() {
405 for ( var i
= 1; i
< 13; i
++ ) {
406 var name
= mw
.config
.get( 'wgMonthNames' )[i
].toLowerCase();
407 ts
.monthNames
[name
] = i
;
408 regex
.push( $.escapeRE( name
) );
409 name
= mw
.config
.get( 'wgMonthNamesShort' )[i
].toLowerCase().replace( '.', '' );
410 ts
.monthNames
[name
] = i
;
411 regex
.push( $.escapeRE( name
) );
414 // Build piped string
415 regex
= regex
.join( '|' );
418 // Any date formated with . , ' - or /
419 ts
.dateRegex
[0] = new RegExp( /^\s*(\d{1,2})[\,\.\-\/'\s]{1,2}(\d{1,2})[\,\.\-\/'\s]{1,2}(\d{2,4})\s*?/i);
421 // Written Month name, dmy
422 ts
.dateRegex
[1] = new RegExp( '^\\s*(\\d{1,2})[\\,\\.\\-\\/\'\\s]*(' + regex
+ ')' + '[\\,\\.\\-\\/\'\\s]*(\\d{2,4})\\s*$', 'i' );
424 // Written Month name, mdy
425 ts
.dateRegex
[2] = new RegExp( '^\\s*(' + regex
+ ')' + '[\\,\\.\\-\\/\'\\s]*(\\d{1,2})[\\,\\.\\-\\/\'\\s]*(\\d{2,4})\\s*$', 'i' );
429 function explodeRowspans( $table
) {
430 // Split multi row cells into multiple cells with the same content
431 $table
.find( '> tbody > tr > [rowspan]' ).each(function () {
432 var rowSpan
= this.rowSpan
;
434 var cell
= $( this );
435 var next
= cell
.parent().nextAll();
436 for ( var i
= 0; i
< rowSpan
- 1; i
++ ) {
437 var td
= next
.eq( i
).children( 'td' );
439 next
.eq( i
).append( cell
.clone() );
440 } else if ( this.cellIndex
=== 0 ) {
441 td
.eq( this.cellIndex
).before( cell
.clone() );
443 td
.eq( this.cellIndex
- 1 ).after( cell
.clone() );
449 function buildCollationTable() {
450 ts
.collationTable
= mw
.config
.get( 'tableSorterCollation' );
451 ts
.collationRegex
= null;
452 if ( ts
.collationTable
) {
455 // Build array of key names
456 for ( var key
in ts
.collationTable
) {
457 if ( ts
.collationTable
.hasOwnProperty(key
) ) { //to be safe
462 ts
.collationRegex
= new RegExp( '[' + keys
.join( '' ) + ']', 'ig' );
467 function cacheRegexs() {
473 new RegExp( /^\d{1,3}[\.]\d{1,3}[\.]\d{1,3}[\.]\d{1,3}$/)
476 new RegExp( /(^[£$€¥]|[£$€¥]$)/),
477 new RegExp( /[£$€¥]/g)
480 new RegExp( /^(https?|ftp|file):\/\/$/),
481 new RegExp( /(https?|ftp|file):\/\//)
484 new RegExp( /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/)
487 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)))$/)
490 new RegExp( /^(([0-2]?[0-9]:[0-5][0-9])|([0-1]?[0-9]:[0-5][0-9]\s(am|pm)))$/)
496 * Converts sort objects [ { Integer: String }, ... ] to the internally used nested array
497 * structure [ [ Integer , Integer ], ... ]
499 * @param sortObjects {Array} List of sort objects.
500 * @return {Array} List of internal sort definitions.
503 function convertSortList( sortObjects
) {
505 $.each( sortObjects
, function( i
, sortObject
) {
506 $.each ( sortObject
, function( columnIndex
, order
) {
507 var orderIndex
= ( order
=== 'desc' ) ? 1 : 0;
508 sortList
.push( [columnIndex
, orderIndex
] );
519 cssHeader
: 'headerSort',
520 cssAsc
: 'headerSortUp',
521 cssDesc
: 'headerSortDown',
522 cssChildRow
: 'expand-child',
523 sortInitialOrder
: 'asc',
524 sortMultiSortKey
: 'shiftKey',
525 sortLocaleCompare
: false,
529 cancelSelection
: true,
532 selectorHeaders
: 'thead tr:eq(0) th',
540 * @param $tables {jQuery}
541 * @param settings {Object} (optional)
543 construct: function ( $tables
, settings
) {
544 return $tables
.each( function ( i
, table
) {
545 // Declare and cache.
546 var $document
, $headers
, cache
, config
, sortOrder
,
551 if ( !table
.tBodies
) {
554 if ( !table
.tHead
) {
555 // No thead found. Look for rows with <th>s and
556 // move them into a <thead> tag or a <tfoot> tag
557 emulateTHeadAndFoot( $table
);
559 // Still no thead? Then quit
560 if ( !table
.tHead
) {
564 $table
.addClass( "jquery-tablesorter" );
566 // FIXME config should probably not be stored in the plain table node
567 // New config object.
571 config
= $.extend( table
.config
, $.tablesorter
.defaultOptions
, settings
);
573 // Save the settings where they read
574 $.data( table
, 'tablesorter', { config
: config
} );
576 // Get the CSS class names, could be done else where.
577 var sortCSS
= [ config
.cssDesc
, config
.cssAsc
];
578 var sortMsg
= [ mw
.msg( 'sort-descending' ), mw
.msg( 'sort-ascending' ) ];
581 $headers
= buildHeaders( table
, sortMsg
);
583 // Grab and process locale settings
584 buildTransformTable();
586 buildCollationTable();
588 // Precaching regexps can bring 10 fold
589 // performance improvements in some browsers.
592 // Legacy fix of .sortbottoms
593 // Wrap them inside inside a tfoot (because that's what they actually want to be) &
594 // and put the <tfoot> at the end of the <table>
595 var $sortbottoms
= $table
.find( '> tbody > tr.sortbottom' );
596 if ( $sortbottoms
.length
) {
597 var $tfoot
= $table
.children( 'tfoot' );
598 if ( $tfoot
.length
) {
599 $tfoot
.eq(0).prepend( $sortbottoms
);
601 $table
.append( $( '<tfoot>' ).append( $sortbottoms
) );
605 explodeRowspans( $table
);
607 // try to auto detect column type, and store in tables config
608 table
.config
.parsers
= buildParserCache( table
, $headers
);
610 // initially build the cache for the tbody cells (to be able to sort initially)
611 cache
= buildCache( table
);
613 // Apply event handling to headers
614 // this is too big, perhaps break it out?
615 $headers
.filter( ':not(.unsortable)' ).click( function ( e
) {
616 if ( e
.target
.nodeName
.toLowerCase() === 'a' ) {
617 // The user clicked on a link inside a table header
618 // Do nothing and let the default link click action continue
622 // Build the cache for the tbody cells
623 // to share between calculations for this sort action.
624 // Re-calculated each time a sort action is performed due to possiblity
625 // that sort values change. Shouldn't be too expensive, but if it becomes
626 // too slow an event based system should be implemented somehow where
627 // cells get event .change() and bubbles up to the <table> here
628 cache
= buildCache( table
);
630 var totalRows
= ( $table
[0].tBodies
[0] && $table
[0].tBodies
[0].rows
.length
) || 0;
631 if ( !table
.sortDisabled
&& totalRows
> 0 ) {
633 // Cache jQuery object
634 var $cell
= $( this );
636 // Get current column index
639 // Get current column sort order
640 this.order
= this.count
% 2;
643 // User only wants to sort on one column
644 if ( !e
[config
.sortMultiSortKey
] ) {
645 // Flush the sort list
646 config
.sortList
= [];
647 // Add column to sort list
648 config
.sortList
.push( [i
, this.order
] );
650 // Multi column sorting
652 // The user has clicked on an already sorted column.
653 if ( isValueInArray( i
, config
.sortList
) ) {
654 // Reverse the sorting direction for all tables.
655 for ( var j
= 0; j
< config
.sortList
.length
; j
++ ) {
656 var s
= config
.sortList
[j
],
657 o
= config
.headerList
[s
[0]];
665 // Add column to sort list array
666 config
.sortList
.push( [i
, this.order
] );
670 // Set CSS for headers
671 setHeadersCss( $table
[0], $headers
, config
.sortList
, sortCSS
, sortMsg
);
673 $table
[0], multisort( $table
[0], config
.sortList
, cache
)
676 // Stop normal event by returning false
681 } ).mousedown( function () {
682 if ( config
.cancelSelection
) {
683 this.onselectstart = function () {
691 * Sorts the table. If no sorting is specified by passing a list of sort
692 * objects, the table is sorted according to the initial sorting order.
693 * Passing an empty array will reset sorting (basically just reset the headers
694 * making the table appear unsorted).
696 * @param sortList {Array} (optional) List of sort objects.
698 $table
.data( 'tablesorter' ).sort = function( sortList
) {
700 if ( sortList
=== undefined ) {
701 sortList
= config
.sortList
;
702 } else if ( sortList
.length
> 0 ) {
703 sortList
= convertSortList( sortList
);
706 // re-build the cache for the tbody cells
707 cache
= buildCache( table
);
709 // set css for headers
710 setHeadersCss( table
, $headers
, sortList
, sortCSS
, sortMsg
);
712 // sort the table and append it to the dom
713 appendToTable( table
, multisort( table
, sortList
, cache
) );
717 if ( config
.sortList
.length
> 0 ) {
718 explodeRowspans( $table
);
719 config
.sortList
= convertSortList( config
.sortList
);
720 $table
.data( 'tablesorter' ).sort();
726 addParser: function ( parser
) {
727 var l
= parsers
.length
,
729 for ( var i
= 0; i
< l
; i
++ ) {
730 if ( parsers
[i
].id
.toLowerCase() === parser
.id
.toLowerCase() ) {
735 parsers
.push( parser
);
739 formatDigit: function ( s
) {
740 if ( ts
.transformTable
!== false ) {
743 for ( var p
= 0; p
< s
.length
; p
++ ) {
745 if ( c
in ts
.transformTable
) {
746 out
+= ts
.transformTable
[c
];
753 var i
= parseFloat( s
.replace( /[, ]/g, '' ).replace( "\u2212", '-' ) );
754 return ( isNaN(i
)) ? 0 : i
;
757 formatFloat: function ( s
) {
758 var i
= parseFloat(s
);
759 return ( isNaN(i
)) ? 0 : i
;
762 formatInt: function ( s
) {
763 var i
= parseInt( s
, 10 );
764 return ( isNaN(i
)) ? 0 : i
;
767 clearTableBody: function ( table
) {
768 if ( $.browser
.msie
) {
769 var empty = function ( el
) {
770 while ( el
.firstChild
) {
771 el
.removeChild( el
.firstChild
);
774 empty( table
.tBodies
[0] );
776 table
.tBodies
[0].innerHTML
= '';
784 // Register as jQuery prototype method
785 $.fn
.tablesorter = function ( settings
) {
786 return ts
.construct( this, settings
);
789 // Add default parsers
795 format: function ( s
) {
796 s
= $.trim( s
.toLowerCase() );
797 if ( ts
.collationRegex
) {
798 var tsc
= ts
.collationTable
;
799 s
= s
.replace( ts
.collationRegex
, function ( match
) {
800 var r
= tsc
[match
] ? tsc
[match
] : tsc
[match
.toUpperCase()];
801 return r
.toLowerCase();
812 return ts
.rgx
.IPAddress
[0].test(s
);
814 format: function ( s
) {
815 var a
= s
.split( '.' ),
818 for ( var i
= 0; i
< l
; i
++ ) {
820 if ( item
.length
=== 1 ) {
822 } else if ( item
.length
=== 2 ) {
828 return $.tablesorter
.formatFloat(r
);
836 return ts
.rgx
.currency
[0].test(s
);
838 format: function ( s
) {
839 return $.tablesorter
.formatDigit( s
.replace( ts
.rgx
.currency
[1], '' ) );
847 return ts
.rgx
.url
[0].test(s
);
849 format: function ( s
) {
850 return $.trim( s
.replace( ts
.rgx
.url
[1], '' ) );
858 return ts
.rgx
.isoDate
[0].test(s
);
860 format: function ( s
) {
861 return $.tablesorter
.formatFloat((s
!== '') ? new Date(s
.replace(
862 new RegExp( /-/g), '/')).getTime() : '0' );
870 return ts.rgx.usLongDate[0].test(s);
872 format: function ( s ) {
873 return $.tablesorter.formatFloat( new Date(s).getTime() );
881 return ( ts.dateRegex[0].test(s) || ts.dateRegex[1].test(s) || ts.dateRegex[2].test(s ));
883 format: function ( s, table ) {
885 s = $.trim( s.toLowerCase() );
887 if ( ( match = s.match( ts.dateRegex[0] ) ) !== null ) {
888 if ( mw.config.get( 'wgDefaultDateFormat
' ) === 'mdy
' || mw.config.get( 'wgContentLanguage
' ) === 'en
' ) {
889 s = [ match[3], match[1], match[2] ];
890 } else if ( mw.config.get( 'wgDefaultDateFormat
' ) === 'dmy
' ) {
891 s = [ match[3], match[2], match[1] ];
893 } else if ( ( match = s.match( ts.dateRegex[1] ) ) !== null ) {
894 s = [ match[3], '' + ts.monthNames[match[2]], match[1] ];
895 } else if ( ( match = s.match( ts.dateRegex[2] ) ) !== null ) {
896 s = [ match[3], '' + ts.monthNames[match[1]], match[2] ];
898 // Should never get here
903 if ( s[1].length === 1 ) {
906 if ( s[2].length === 1 ) {
911 if ( ( y = parseInt( s[0], 10) ) < 100 ) {
912 // Guestimate years without centuries
919 while ( s[0].length < 4 ) {
922 return parseInt( s.join( '' ), 10 );
930 return ts.rgx.time[0].test(s);
932 format: function ( s ) {
933 return $.tablesorter.formatFloat( new Date( '2000/01/01 ' + s ).getTime() );
940 is: function ( s, table ) {
941 return $.tablesorter.numberRegex.test( $.trim( s ));
943 format: function ( s ) {
944 return $.tablesorter.formatDigit(s);
949 }( jQuery, mediaWiki ) );