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

40 lines
1000 B
JavaScript
Raw Normal View History

2013-03-26 21:16:13 +00:00
/*! Weekday parser
* Demo: http://jsfiddle.net/Mottie/abkNM/4169/
2013-03-26 21:05:21 +00:00
*/
/*jshint jquery:true */
;(function($){
"use strict";
2013-09-29 19:37:03 +00:00
var ts = $.tablesorter;
ts.dates = $.extend({}, ts.dates, {
2013-03-26 21:05:21 +00:00
// *** modify this array to change match the language ***
weekdayCased : [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
});
2013-09-29 19:37:03 +00:00
ts.dates.weekdayLower = ts.dates.weekdayCased.join(',').toLocaleLowerCase().split(',');
2013-03-26 21:05:21 +00:00
2013-09-29 19:37:03 +00:00
ts.addParser({
2013-03-26 21:05:21 +00:00
id: "weekday",
is: function(){
return false;
},
format: function(s, table) {
if (s) {
var j = -1, c = table.config;
s = c.ignoreCase ? s.toLocaleLowerCase() : s;
$.each(ts.dates[ 'weekday' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
if (j < 0 && s.match(v)) {
j = i;
return false;
}
});
// return s (original string) if there isn't a match
// (non-weekdays will sort separately and empty cells will sort as expected)
return j < 0 ? s : j;
}
return s;
2013-03-26 21:05:21 +00:00
},
type: "numeric"
});
})(jQuery);