tablesorter/js/parsers/parser-date-month.js

64 lines
1.5 KiB
JavaScript
Raw Normal View History

/*! Parser: Month - updated 11/2/2015 (v2.24.1) */
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
2013-03-26 21:05:21 +00:00
/*jshint jquery:true */
;(function($){
'use strict';
2013-03-26 21:05:21 +00:00
2013-09-29 19:37:03 +00:00
var ts = $.tablesorter;
ts.dates = $.extend( {}, {
// See http://mottie.github.io/tablesorter/docs/example-widget-grouping.html
// for details on how to use CLDR data for a locale to add data for this parser
// CLDR returns an object { 1: "Jan", 2: "Feb", 3: "Mar", ..., 12: "Dec" }
months : {
'en' : {
1 : 'Jan',
2 : 'Feb',
3 : 'Mar',
4 : 'Apr',
5 : 'May',
6 : 'Jun',
7 : 'Jul',
8 : 'Aug',
9 : 'Sep',
10: 'Oct',
11: 'Nov',
12: 'Dec'
}
}
}, ts.dates );
2013-03-26 21:05:21 +00:00
2013-09-29 19:37:03 +00:00
ts.addParser({
id: 'month',
is: function() {
2013-03-26 21:05:21 +00:00
return false;
},
format: function( str, table, cell, cellIndex ) {
if ( str ) {
var m, month,
c = table.config,
// add options to 'config.globalize' for all columns --> globalize : { lang: 'en' }
// or per column by using the column index --> globalize : { 0 : { lang: 'fr' } }
options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {},
months = ts.dates.months[ options.lang || 'en' ];
if ( c.ignoreCase ) {
str = str.toLowerCase();
}
for ( month in months ) {
if ( typeof month === 'string' ) {
m = months[ month ];
if ( c.ignoreCase ) {
m = m.toLowerCase();
}
if ( str.match( m ) ) {
return parseInt( month, 10 );
}
}
}
}
return str;
2013-03-26 21:05:21 +00:00
},
type: 'numeric'
2013-03-26 21:05:21 +00:00
});
})(jQuery);