2015-11-02 05:44:14 +00:00
|
|
|
/*! Parser: weekday - updated 11/2/2015 (v2.24.1) */
|
2015-03-28 20:03:50 +00:00
|
|
|
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
|
2013-03-26 21:05:21 +00:00
|
|
|
/*jshint jquery:true */
|
|
|
|
;(function($){
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2013-03-26 21:05:21 +00:00
|
|
|
|
2013-09-29 19:37:03 +00:00
|
|
|
var ts = $.tablesorter;
|
2015-11-02 05:44:14 +00:00
|
|
|
ts.dates = $.extend( true, {}, {
|
|
|
|
// 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 { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", ... }
|
|
|
|
weekdays : {
|
|
|
|
'en' : {
|
|
|
|
'sun' : 'Sun',
|
|
|
|
'mon' : 'Mon',
|
|
|
|
'tue' : 'Tue',
|
|
|
|
'wed' : 'Wed',
|
|
|
|
'thu' : 'Thu',
|
|
|
|
'fri' : 'Fri',
|
|
|
|
'sat' : 'Sat'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// set table.config.weekStarts to change weekday start date for your locale
|
|
|
|
// cross-reference of a date on which the week starts on a...
|
|
|
|
// https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/weekData.json
|
|
|
|
weekStartList : {
|
|
|
|
'sun' : '1995', // Sun 1/1/1995
|
|
|
|
'mon' : '1996', // Mon 1/1/1996
|
|
|
|
'fri' : '1999', // Friday 1/1/1999
|
|
|
|
'sat' : '2000' // Sat 1/1/2000
|
|
|
|
},
|
|
|
|
|
|
|
|
// do not modify this array; it is used for cross referencing
|
|
|
|
weekdaysXref : [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ]
|
|
|
|
|
|
|
|
}, ts.dates );
|
2013-03-26 21:05:21 +00:00
|
|
|
|
2013-09-29 19:37:03 +00:00
|
|
|
ts.addParser({
|
2015-07-23 04:29:51 +00:00
|
|
|
id: 'weekday',
|
2015-11-02 05:44:14 +00:00
|
|
|
is: function() {
|
2013-03-26 21:05:21 +00:00
|
|
|
return false;
|
|
|
|
},
|
2015-11-02 05:44:14 +00:00
|
|
|
format: function( str, table, cell, cellIndex ) {
|
|
|
|
if ( str ) {
|
|
|
|
var d, day, num,
|
|
|
|
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 ) || {},
|
|
|
|
days = ts.dates.weekdays[ options.lang || 'en' ],
|
|
|
|
xref = ts.dates.weekdaysXref;
|
|
|
|
if ( c.ignoreCase ) {
|
|
|
|
str = str.toLowerCase();
|
|
|
|
}
|
|
|
|
for ( day in days ) {
|
|
|
|
if ( typeof day === 'string' ) {
|
|
|
|
d = days[ day ];
|
|
|
|
if ( c.ignoreCase ) {
|
|
|
|
d = d.toLowerCase();
|
|
|
|
}
|
|
|
|
if ( str.match( d ) ) {
|
|
|
|
num = $.inArray( day, xref );
|
|
|
|
return num > -1 ? num : str;
|
|
|
|
}
|
2014-09-30 21:20:04 +00:00
|
|
|
}
|
2015-11-02 05:44:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
},
|
|
|
|
type: 'numeric'
|
|
|
|
});
|
|
|
|
|
|
|
|
// useful when a group widget date column is set to "group-date-week"
|
|
|
|
// and you want to only sort on the day of the week ignore the actual date, month and year
|
|
|
|
ts.addParser({
|
|
|
|
id: 'weekday-index',
|
|
|
|
is: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
format: function( str, table ) {
|
|
|
|
if ( str ) {
|
|
|
|
var c = table.config,
|
|
|
|
date = new Date( str );
|
|
|
|
if ( date instanceof Date && isFinite( date ) ) {
|
|
|
|
// use a specific date that started with that weekday so sorting is only going to be
|
|
|
|
// based on the day of the week and not the date, month or year
|
|
|
|
return new Date( '1/' + ( date.getDay() + 1 ) + '/' + ts.dates.weekStartList[ c.weekStarts || 'sun' ] );
|
|
|
|
}
|
2014-09-30 21:20:04 +00:00
|
|
|
}
|
2015-11-02 05:44:14 +00:00
|
|
|
return str;
|
2013-03-26 21:05:21 +00:00
|
|
|
},
|
2015-07-23 04:29:51 +00:00
|
|
|
type: 'numeric'
|
2013-03-26 21:05:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|