| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
;(function($) { |
| 5 |
'use strict'; |
| 6 |
|
| 7 |
var ts = $.tablesorter; |
| 8 |
|
| 9 |
if ( !ts.dates ) { ts.dates = {}; } |
| 10 |
if ( !ts.dates.weekdays ) { ts.dates.weekdays = {}; } |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
ts.dates.weekdays.en = { |
| 15 |
'sun' : 'Sun', |
| 16 |
'mon' : 'Mon', |
| 17 |
'tue' : 'Tue', |
| 18 |
'wed' : 'Wed', |
| 19 |
'thu' : 'Thu', |
| 20 |
'fri' : 'Fri', |
| 21 |
'sat' : 'Sat' |
| 22 |
}; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
ts.dates.weekStartList = { |
| 28 |
'sun' : '1995', |
| 29 |
'mon' : '1996', |
| 30 |
'fri' : '1999', |
| 31 |
'sat' : '2000' |
| 32 |
}; |
| 33 |
|
| 34 |
|
| 35 |
ts.dates.weekdaysXref = [ 'sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat' ]; |
| 36 |
|
| 37 |
ts.addParser({ |
| 38 |
id: 'weekday', |
| 39 |
is: function() { |
| 40 |
return false; |
| 41 |
}, |
| 42 |
format: function( str, table, cell, cellIndex ) { |
| 43 |
if ( str ) { |
| 44 |
var d, day, num, |
| 45 |
c = table.config, |
| 46 |
|
| 47 |
|
| 48 |
options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}, |
| 49 |
days = ts.dates.weekdays[ options.lang || 'en' ], |
| 50 |
xref = ts.dates.weekdaysXref; |
| 51 |
if ( c.ignoreCase ) { |
| 52 |
str = str.toLowerCase(); |
| 53 |
} |
| 54 |
for ( day in days ) { |
| 55 |
if ( typeof day === 'string' ) { |
| 56 |
d = days[ day ]; |
| 57 |
if ( c.ignoreCase ) { |
| 58 |
d = d.toLowerCase(); |
| 59 |
} |
| 60 |
if ( str.match( d ) ) { |
| 61 |
num = $.inArray( day, xref ); |
| 62 |
return num > -1 ? num : str; |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
return str; |
| 68 |
}, |
| 69 |
type: 'numeric' |
| 70 |
}); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
ts.addParser({ |
| 75 |
id: 'weekday-index', |
| 76 |
is: function() { |
| 77 |
return false; |
| 78 |
}, |
| 79 |
format: function( str, table ) { |
| 80 |
if ( str ) { |
| 81 |
var c = table.config, |
| 82 |
date = new Date( str ); |
| 83 |
if ( date instanceof Date && isFinite( date ) ) { |
| 84 |
|
| 85 |
|
| 86 |
return new Date( '1/' + ( date.getDay() + 1 ) + '/' + ts.dates.weekStartList[ c.weekStarts || 'sun' ] ); |
| 87 |
} |
| 88 |
} |
| 89 |
return str; |
| 90 |
}, |
| 91 |
type: 'numeric' |
| 92 |
}); |
| 93 |
|
| 94 |
})(jQuery); |