Debian Codegraph @

js/parsers/parser-date-weekday.js

raw symbols SCIP
1 /*! Parser: weekday - updated 11/22/2015 (v2.24.6) */
2 /* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
3 /*jshint jquery:true */
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 // See http://mottie.github.io/tablesorter/docs/example-widget-grouping.html
12 // for details on how to use CLDR data for a locale to add data for this parser
13 // CLDR returns { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", ... }
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 // set table.config.weekStarts to change weekday start date for your locale
24 // cross-reference of a date on which the week starts on a...
25 // https://github.com/unicode-cldr/cldr-core/blob/master/supplemental/weekData.json
26 // locale agnostic
27 ts.dates.weekStartList = {
28 'sun' : '1995', // Sun 1/1/1995
29 'mon' : '1996', // Mon 1/1/1996
30 'fri' : '1999', // Friday 1/1/1999
31 'sat' : '2000' // Sat 1/1/2000
32 };
33 // do not modify this array; it is used for cross referencing weekdays
34 // locale agnostic
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 // add options to 'config.globalize' for all columns --> globalize : { lang: 'en' }
47 // or per column by using the column index --> globalize : { 0 : { lang: 'fr' } }
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 // useful when a group widget date column is set to "group-date-week"
73 // and you want to only sort on the day of the week ignore the actual date, month and year
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 // use a specific date that started with that weekday so sorting is only going to be
85 // based on the day of the week and not the date, month or year
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);