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

63 lines
1.5 KiB
JavaScript
Raw Normal View History

/*! Parser: Month - updated 11/22/2015 (v2.24.6) */
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
2013-03-26 21:05:21 +00:00
/*jshint jquery:true */
2018-03-17 20:30:25 +00:00
;(function($) {
'use strict';
2013-03-26 21:05:21 +00:00
2013-09-29 19:37:03 +00:00
var ts = $.tablesorter;
if ( !ts.dates ) { ts.dates = {}; }
if ( !ts.dates.months ) { ts.dates.months = {}; }
ts.dates.months.en = {
// 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" }
1 : 'Jan',
2 : 'Feb',
3 : 'Mar',
4 : 'Apr',
5 : 'May',
6 : 'Jun',
7 : 'Jul',
8 : 'Aug',
9 : 'Sep',
10: 'Oct',
11: 'Nov',
12: 'Dec'
};
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);