Parsers: globalization tweaks & new parser

Make month & weekday Globalize ready.
globalization parser now caches the Globalize object in a "Globalize" option
Add "weekday-index" parser
Update demos
This commit is contained in:
Rob Garrison 2015-11-01 23:44:14 -06:00
parent dbcd306ff2
commit 4fc923ec78
9 changed files with 288 additions and 76 deletions

View File

@ -1,9 +1,11 @@
/*! Parser: Month - updated 10/26/2014 (v2.18.0) */ /*! Parser: Month - updated 11/2/2015 (v2.24.1) */
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */ /* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
/*jshint jquery:true */ /*jshint jquery:true */
!function(a){"use strict";var b=a.tablesorter;b.dates=a.extend({},b.dates,{ !function(a){"use strict";var b=a.tablesorter;b.dates=a.extend({},{
// *** modify this array to match the desired language *** // See http://mottie.github.io/tablesorter/docs/example-widget-grouping.html
monthCased:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}),b.dates.monthLower=b.dates.monthCased.join(",").toLocaleLowerCase().split(","),b.addParser({id:"month",is:function(){return!1},format:function(c,d){if(c){var e=-1,f=d.config,g=f.ignoreCase?c.toLocaleLowerCase():c; // for details on how to use CLDR data for a locale to add data for this parser
// return s (original string) if there isn't a match // CLDR returns an object { 1: "Jan", 2: "Feb", 3: "Mar", ..., 12: "Dec" }
// (non-weekdays will sort separately and empty cells will sort as expected) months:{en:{1:"Jan",2:"Feb",3:"Mar",4:"Apr",5:"May",6:"Jun",7:"Jul",8:"Aug",9:"Sep",10:"Oct",11:"Nov",12:"Dec"}}},b.dates),b.addParser({id:"month",is:function(){return!1},format:function(a,c,d,e){if(a){var f,g,h=c.config,
return a.each(b.dates["month"+(f.ignoreCase?"Lower":"Cased")],function(a,b){return 0>e&&g.match(b)?(e=a,!1):void 0}),0>e?c:e}return c},type:"numeric"})}(jQuery); // add options to 'config.globalize' for all columns --> globalize : { lang: 'en' }
// or per column by using the column index --> globalize : { 0 : { lang: 'fr' } }
i=h.globalize&&(h.globalize[e]||h.globalize)||{},j=b.dates.months[i.lang||"en"];h.ignoreCase&&(a=a.toLowerCase());for(g in j)if("string"==typeof g&&(f=j[g],h.ignoreCase&&(f=f.toLowerCase()),a.match(f)))return parseInt(g,10)}return a},type:"numeric"})}(jQuery);

View File

@ -1,9 +1,26 @@
/*! Parser: weekday - updated 10/26/2014 (v2.18.0) */ /*! Parser: weekday - updated 11/2/2015 (v2.24.1) */
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */ /* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
/*jshint jquery:true */ /*jshint jquery:true */
!function(a){"use strict";var b=a.tablesorter;b.dates=a.extend({},b.dates,{ !function(a){"use strict";var b=a.tablesorter;b.dates=a.extend(!0,{},{
// *** modify this array to change match the language *** // See http://mottie.github.io/tablesorter/docs/example-widget-grouping.html
weekdayCased:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]}),b.dates.weekdayLower=b.dates.weekdayCased.join(",").toLocaleLowerCase().split(","),b.addParser({id:"weekday",is:function(){return!1},format:function(c,d){if(c){var e=-1,f=d.config; // for details on how to use CLDR data for a locale to add data for this parser
// return s (original string) if there isn't a match // CLDR returns { sun: "Sun", mon: "Mon", tue: "Tue", wed: "Wed", thu: "Thu", ... }
// (non-weekdays will sort separately and empty cells will sort as expected) weekdays:{en:{sun:"Sun",mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat"}},
return c=f.ignoreCase?c.toLocaleLowerCase():c,a.each(b.dates["weekday"+(f.ignoreCase?"Lower":"Cased")],function(a,b){return 0>e&&c.match(b)?(e=a,!1):void 0}),0>e?c:e}return c},type:"numeric"})}(jQuery); // 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"},
// do not modify this array; it is used for cross referencing
weekdaysXref:["sun","mon","tue","wed","thu","fri","sat"]},b.dates),b.addParser({id:"weekday",is:function(){return!1},format:function(c,d,e,f){if(c){var g,h,i,j=d.config,
// add options to 'config.globalize' for all columns --> globalize : { lang: 'en' }
// or per column by using the column index --> globalize : { 0 : { lang: 'fr' } }
k=j.globalize&&(j.globalize[f]||j.globalize)||{},l=b.dates.weekdays[k.lang||"en"],m=b.dates.weekdaysXref;j.ignoreCase&&(c=c.toLowerCase());for(h in l)if("string"==typeof h&&(g=l[h],j.ignoreCase&&(g=g.toLowerCase()),c.match(g)))return i=a.inArray(h,m),i>-1?i:c}return c},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
b.addParser({id:"weekday-index",is:function(){return!1},format:function(a,c){if(a){var d=c.config,e=new Date(a);if(e instanceof Date&&isFinite(e))
// 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/"+(e.getDay()+1)+"/"+b.dates.weekStartList[d.weekStarts||"sun"])}return a},type:"numeric"})}(jQuery);

View File

@ -1,4 +1,4 @@
/*! Parser: jQuery Globalize - updated 10/31/2015 (v2.24.0) */ /*! Parser: jQuery Globalize - updated 11/2/2015 (v2.24.1) */
/* Extract localized data using jQuery's Globalize parsers; set /* Extract localized data using jQuery's Globalize parsers; set
Globalize.locale( 'xx' ) in the globalize settings */ Globalize.locale( 'xx' ) in the globalize settings */
/*jshint jquery:true, newcap: false */ /*jshint jquery:true, newcap: false */
@ -7,8 +7,16 @@
a.tablesorter.addParser({id:"globalize-date",is:function(){return!1},format:function(a,b,c,d){var e,f,g=b.config, a.tablesorter.addParser({id:"globalize-date",is:function(){return!1},format:function(a,b,c,d){var e,f,g=b.config,
// add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' } // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' }
// or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
h=g.globalize&&(g.globalize[d]||g.globalize)||{};return Globalize&&(e="object"==typeof h.lang?h.lang:Globalize(h.lang||"en")),f=e&&e.dateParser?e.dateParser(h)(a):a?new Date(a):a,f instanceof Date&&isFinite(f)?f.getTime():a},type:"numeric"}),/*! jQuery Globalize number parser (https://github.com/jquery/globalize#number-module) */ h=g.globalize&&(g.globalize[d]||g.globalize)||{};
// initialized Globalize object
// Globalize initialized from "lang" option
// cache the object
return Globalize&&(e="object"==typeof h.Globalize?h.Globalize:Globalize(h.lang||"en"),h.Globalize||(h.Globalize=e)),f=e&&e.dateParser?e.dateParser(h)(a):a?new Date(a):a,f instanceof Date&&isFinite(f)?f.getTime():a},type:"numeric"}),/*! jQuery Globalize number parser (https://github.com/jquery/globalize#number-module) */
a.tablesorter.addParser({id:"globalize-number",is:function(){return!1},format:function(b,c,d,e){var f,g,h=c.config, a.tablesorter.addParser({id:"globalize-number",is:function(){return!1},format:function(b,c,d,e){var f,g,h=c.config,
// add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' } // add options to 'config.globalize' for all columns --> globalize : { skeleton: 'GyMMMd' }
// or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
i=h.globalize&&(h.globalize[e]||h.globalize)||{};return Globalize&&(f="object"==typeof i.lang?i.lang:Globalize(i.lang||"en")),g=f&&f.numberParser?f.numberParser(i)(b):b?a.tablesorter.formatFloat((b||"").replace(/[^\w,. \-()]/g,""),c):b,b&&"number"==typeof g?g:b},type:"numeric"})}(jQuery); i=h.globalize&&(h.globalize[e]||h.globalize)||{};
// initialized Globalize object
// Globalize initialized from "lang" option
// cache the object
return Globalize&&(f="object"==typeof i.Globalize?i.Globalize:Globalize(i.lang||"en"),i.Globalize||(i.Globalize=f)),g=f&&f.numberParser?f.numberParser(i)(b):b?a.tablesorter.formatFloat((b||"").replace(/[^\w,. \-()]/g,""),c):b,b&&"number"==typeof g?g:b},type:"numeric"})}(jQuery);

View File

@ -13,7 +13,7 @@
<script src="js/prettify.js"></script> <script src="js/prettify.js"></script>
<script src="js/docs.js"></script> <script src="js/docs.js"></script>
<style> <style>
th { width: 20%; } th { width: 14%; }
</style> </style>
<link href="../css/theme.blue.css" rel="stylesheet"> <link href="../css/theme.blue.css" rel="stylesheet">
@ -30,9 +30,53 @@
<script id="js">$(function() { <script id="js">$(function() {
// 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", ... }
// or copy the data directly as it is shown here:
// ************************
// French localization modified from days "abbreviated" format
// https://github.com/unicode-cldr/cldr-dates-modern/blob/master/main/fr/ca-gregorian.json
// It does *not* include the periods
$.tablesorter.dates.weekdays.fr = {
"sun" : "Dim",
"mon" : "Lun",
"tue" : "Mar",
"wed" : "Mer",
"thu" : "Jeu",
"fri" : "Ven",
"sat" : "Sam"
};
// CLDR returns an object { 1: "Jan", 2: "Feb", 3: "Mar", ..., 12: "Dec" }
// French localization modified from months "abbreviated" format
// https://github.com/unicode-cldr/cldr-dates-modern/blob/master/main/fr/ca-gregorian.json
// It does *not* include the periods
$.tablesorter.dates.months.fr = {
"1" : "Janv",
"2" : "Févr",
"3" : "Mars",
"4" : "Avr",
"5" : "Mai",
"6" : "Juin",
"7" : "Juil",
"8" : "Août",
"9" : "Sept",
"10" : "Oct",
"11" : "Nov",
"12" : "Déc"
};
// call the tablesorter plugin // call the tablesorter plugin
$("table").tablesorter({ $("table").tablesorter({
theme : 'blue', theme : 'blue',
// option used by weekday, month & globalize parsers (v2.24.1)
globalize : {
// columns that use French data
2 : { lang: 'fr' },
4 : { lang: 'fr' }
},
widgets : ["zebra"], widgets : ["zebra"],
// date range used by the two-digit year parser (added v2.14.0) // date range used by the two-digit year parser (added v2.14.0)
dateRange : 30 dateRange : 30
@ -52,6 +96,12 @@
<p class="tip"> <p class="tip">
<em>NOTE!</em> <em>NOTE!</em>
<ul> <ul>
<li>In <span class="version">v2.24.1</span>,
<ul>
<li>Updated weekday &amp; month parsers to better integrate with <a href="https://github.com/jquery/globalize">jQuery Globalize</a>.</li>
<li>This demo now includes a column for French named weekdays &amp; months.</li>
</ul>
</li>
<li>Parse Dates with these parsers <li>Parse Dates with these parsers
<ul> <ul>
<li>The "Date" column is using the <a href="http://sugarjs.com/dates#comparing_dates">sugar</a> library to parse dates. Make sure to include the sugar library and the sugar-date-parser.</li> <li>The "Date" column is using the <a href="http://sugarjs.com/dates#comparing_dates">sugar</a> library to parse dates. Make sure to include the sugar library and the sugar-date-parser.</li>
@ -79,22 +129,24 @@
<tr> <tr>
<th class="sorter-sugar">Date</th> <th class="sorter-sugar">Date</th>
<th class="sorter-weekday">Weekday</th> <th class="sorter-weekday">Weekday</th>
<th class="sorter-weekday">Weekday (French)</th>
<th class="sorter-month">Month</th> <th class="sorter-month">Month</th>
<th class="sorter-month">Month (French)</th>
<th class="sorter-mmddyy">MM/DD/YY</th> <!-- "sorter-ddmmyy" also available --> <th class="sorter-mmddyy">MM/DD/YY</th> <!-- "sorter-ddmmyy" also available -->
<th class="sorter-time">Time</th> <th class="sorter-time">Time</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr><td>next friday</td><td>Friday</td><td>Aug</td><td>02/1/16</td><td>12:00 PM</td></tr> <tr><td>next friday</td><td>Friday</td><td>Vendredi</td><td>Aug</td><td>Août</td><td>02/1/16</td><td>12:00 PM</td></tr>
<tr><td>today</td><td>Thurs</td><td>September</td><td>1/2/16</td><td>00:00</td></tr> <tr><td>today</td><td>Sunday</td><td>Dim</td><td>September</td><td>Septembre</td><td>1/2/16</td><td>00:00</td></tr>
<tr><td>last Tuesday</td><td>Fri</td><td>Mar</td><td>11/1/15</td><td>18:00</td></tr> <tr><td>last Tuesday</td><td>Fri</td><td>Ven</td><td>Mar</td><td>Mars</td><td>11/1/15</td><td>18:00</td></tr>
<tr><td>the day after tomorrow</td><td>Wed</td><td>July</td><td>01/1/16</td><td>13:00</td></tr> <tr><td>the day after tomorrow</td><td>Wed</td><td>Mer</td><td>July</td><td>Juillet</td><td>01/1/16</td><td>13:00</td></tr>
<tr><td>2010-05-25T12:30:40.299+01:00</td><td>Monday</td><td>Jan</td><td>1/11/15</td><td>1:30 PM</td></tr> <tr><td>2010-05-25T12:30:40.299+01:00</td><td>Monday</td><td>Lun</td><td>Jan</td><td>Janvier</td><td>1/11/15</td><td>1:30 PM</td></tr>
<tr><td>May 25th of next year</td><td>Tues</td><td>Nov</td><td>1/1/15</td><td>14:00</td></tr> <tr><td>May 25th of next year</td><td>Tues</td><td>Mardi</td><td>Nov</td><td>Novembre</td><td>1/1/15</td><td>14:00</td></tr>
<tr><td>25 May 2010</td><td>Tuesday</td><td>November</td><td>3/1/15</td><td>1:58 PM</td></tr> <tr><td>25 May 2010</td><td>Tuesday</td><td>Mar</td><td>November</td><td>Nov</td><td>3/1/15</td><td>1:58 PM</td></tr>
<tr><td>the last day of March</td><td>Mon</td><td>December</td><td>1/15/15</td><td>2:10 PM</td></tr> <tr><td>the last day of March</td><td>Sat</td><td>Sam</td><td>December</td><td>Décembre</td><td>1/15/15</td><td>2:10 PM</td></tr>
<tr><td>last month</td><td>Wednesday</td><td>April</td><td>11/11/16</td><td>13:50</td></tr> <tr><td>last month</td><td>Wednesday</td><td>Mercredi</td><td>April</td><td>Avr</td><td>11/11/16</td><td>13:50</td></tr>
<tr><td>one day before yesterday</td><td>Thursday</td><td>Feb</td><td>5/1/15</td><td>4:00 AM</td></tr> <tr><td>one day before yesterday</td><td>Thursday</td><td>Jeudi</td><td>Feb</td><td>Février</td><td>5/1/15</td><td>4:00 AM</td></tr>
</tbody> </tbody>
</table></div> </table></div>

View File

@ -15,6 +15,7 @@
<!-- Tablesorter: required --> <!-- Tablesorter: required -->
<link rel="stylesheet" href="../css/theme.blue.css"> <link rel="stylesheet" href="../css/theme.blue.css">
<style>th { width: 25%; }</style>
<script src="../js/jquery.tablesorter.js"></script> <script src="../js/jquery.tablesorter.js"></script>
<script src="../js/parsers/parser-globalize.js"></script> <script src="../js/parsers/parser-globalize.js"></script>
@ -38,8 +39,9 @@
widthFixed: true, widthFixed: true,
// globalize options // globalize options
globalize: { globalize: {
1: { lang : en }, // in v2.24.1, use Globalize to cache the object; lang should only contain the string
3: { lang : en, raw: 'MMM d, y G' } 1: { lang : 'en', Globalize : en },
3: { lang : 'en', Globalize : en, raw: 'MMM d, y G' }
}, },
headers: { headers: {
1: { sorter: 'globalize-number' }, 1: { sorter: 'globalize-number' },
@ -254,8 +256,15 @@ var data = {
<p class="tip"> <p class="tip">
<em>NOTE!</em> <em>NOTE!</em>
<ul> <ul>
<li>In <span class="version updated">v2.24.1</span>,
<ul>
<li>An internal change made it necessary to change the <code>lang</code> option to only hold a string of the set language.</li>
<li>To cache the Globalize object, save it as a <code>Globalize</code> option (see code example below).</li>
</ul>
</li>
<li><a href="https://github.com/jquery/globalize">jQuery Globalize</a> supports the parsing of locale specific data, including <a href="https://github.com/jquery/globalize/blob/master/doc/api/number/number-parser.md">numerous number formats</a> (including Arabic, Chinese &amp; Japanese) and <a href="https://github.com/jquery/globalize/blob/master/doc/api/date/date-parser.md">custom date formats</a>.</li> <li><a href="https://github.com/jquery/globalize">jQuery Globalize</a> supports the parsing of locale specific data, including <a href="https://github.com/jquery/globalize/blob/master/doc/api/number/number-parser.md">numerous number formats</a> (including Arabic, Chinese &amp; Japanese) and <a href="https://github.com/jquery/globalize/blob/master/doc/api/date/date-parser.md">custom date formats</a>.</li>
<li>This is a very basic example using English only. For more details on how to set up Globalize, see the <a href="example-widget-grouping.html#globalization">Grouping widget documentation about Globalization</a>.</li> <li>This is a very basic example using English only. For another example, see the <a href="example-parsers-dates.html">weekday &amp; month parsers</a>.</li>
<li>For more details on how to set up Globalize, see the <a href="example-widget-grouping.html#globalization">Grouping widget documentation about Globalization</a>.</li>
</ul> </ul>
<p> <p>

View File

@ -516,14 +516,14 @@
<h4 id="custom-parsers">Custom Parsers</h4> <h4 id="custom-parsers">Custom Parsers</h4>
<ul> <ul>
<li><a href="example-parsers-duration.html">Countdown parser</a> (<span class="version">v2.19.0</span>).</li> <li><a href="example-parsers-duration.html">Countdown parser</a> (<span class="version">v2.19.0</span>).</li>
<li><a href="example-parsers-dates.html">Date parsers</a> (<span class="version">v2.8</span>; <span class="version updated">v2.18.0</span>; includes weekday, month, two-digit year &amp; <a href="http://sugarjs.com/dates">sugar.js</a> date parsers).</li> <li><a href="example-parsers-dates.html">Date parsers</a> (<span class="version">v2.8</span>; <span class="version updated">v2.24.1</span>; includes weekday, month, two-digit year &amp; <a href="http://sugarjs.com/dates">sugar.js</a> date parsers).</li>
<li><a href="example-parsers-date-range.html">Date range parsers</a> (<span class="version">v2.21.0</span>); if filters, include the <a href="example-widget-filter-custom-search2.html">insideRange</a> filter search type.</li> <li><a href="example-parsers-date-range.html">Date range parsers</a> (<span class="version">v2.21.0</span>); if filters, include the <a href="example-widget-filter-custom-search2.html">insideRange</a> filter search type.</li>
<li><a href="example-parsers-duration.html">Duration parser</a> (<span class="version">v2.17.8</span>).</li> <li><a href="example-parsers-duration.html">Duration parser</a> (<span class="version">v2.17.8</span>).</li>
<li><a href="example-parsers-feet-inch-fraction.html">Feet-inch-fraction parser</a> (<span class="version">v2.8</span>).</li> <li><a href="example-parsers-feet-inch-fraction.html">Feet-inch-fraction parser</a> (<span class="version">v2.8</span>).</li>
<li><a href="example-parsers-file-type.html">File type parser</a> (<span class="version">v2.13</span>).</li> <li><a href="example-parsers-file-type.html">File type parser</a> (<span class="version">v2.13</span>).</li>
<li><a href="example-parsers-ignore-articles.html">Ignore leading articles parser</a> (Ignore &quot;A&quot;, &quot;An&quot; and &quot;The&quot; in titles) (<span class="version">v2.8</span>).</li> <li><a href="example-parsers-ignore-articles.html">Ignore leading articles parser</a> (Ignore &quot;A&quot;, &quot;An&quot; and &quot;The&quot; in titles) (<span class="version">v2.8</span>).</li>
<li><a href="example-widget-grouping.html">Input/select parsers</a> (used by Grouping rows widget) (<span class="version">v2.8</span>; <span class="version updated">v2.24.0</span>).</li> <li><a href="example-widget-grouping.html">Input/select parsers</a> (used by Grouping rows widget) (<span class="version">v2.8</span>; <span class="version updated">v2.24.0</span>).</li>
<li><a href="example-parsers-globalize.html">jQuery Globalize</a> (number &amp; date parsers; <span class="version">v2.22.0</span>; <span class="version updated">v2.24.0</span>).</li> <li><a href="example-parsers-globalize.html">jQuery Globalize</a> (number &amp; date parsers; <span class="version">v2.22.0</span>; <span class="version updated">v2.24.1</span>).</li>
<li><a href="example-parsers-metric.html">Metric parser</a> (<span class="version">v2.8</span>).</li> <li><a href="example-parsers-metric.html">Metric parser</a> (<span class="version">v2.8</span>).</li>
<li><a href="example-parsers-named-numbers.html">Named Numbers parser</a> (<span class="version">v2.18.0</span>; <span class="version updated">v2.22.0</span>).</li> <li><a href="example-parsers-named-numbers.html">Named Numbers parser</a> (<span class="version">v2.18.0</span>; <span class="version updated">v2.22.0</span>).</li>
<li><a href="example-parsers-ip-address.html">Network (IPv4, IPv6 and MAC address parser</a> (<span class="version">v2.12</span>; <span class="version updated">v2.22.0</span>).</li> <li><a href="example-parsers-ip-address.html">Network (IPv4, IPv6 and MAC address parser</a> (<span class="version">v2.12</span>; <span class="version updated">v2.22.0</span>).</li>
@ -935,6 +935,31 @@
<td><a href="example-option-sort-empty.html">Example</a></td> <td><a href="example-option-sort-empty.html">Example</a></td>
</tr> </tr>
<tr id="globalize">
<td><a href="#" class="permalink">globalize</a></td>
<td>object</td>
<td>null</td>
<td>
This option is used by parsers to localize the language (<span class="version">v2.24.0</span>; <span class="version updated">v2.24.1</span>).
<div class="collapsible"><br>
This option is meant to be used with the <a href="https://github.com/jquery/globalize">jQuery Globalize</a> library along with CLDR data.
<p>See the <a href="example-widget-grouping.html#globalization">Globalization</a> section in the group widget demo for details on how to set it up.</p>
<p>Currently, the globalize, month &amp; weekday parsers utilize this option.</p>
<pre class="prettyprint lang-js">$(function(){
$('table').tablesorter({
// globalize : { lang: 'en' } // for ALL columns
// or, per column by using the column index
globalize : {
0 : { lang: 'fr', Globalize : Globalize('fr'), raw: 'MMM d, y G' },
2 : { lang: 'fr' }
}
});
});</pre>
</div>
</td>
<td><a href="example-parsers-globalize.html">2</a> <a href="example-parsers-dates.html">2</a></td>
</tr>
<tr id="headers"> <tr id="headers">
<td><a href="#" class="permalink">headers</a></td> <td><a href="#" class="permalink">headers</a></td>
<td>Object</td> <td>Object</td>

View File

@ -1,36 +1,61 @@
/*! Parser: Month - updated 10/26/2014 (v2.18.0) */ /*! Parser: Month - updated 11/2/2015 (v2.24.1) */
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */ /* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
/*jshint jquery:true */ /*jshint jquery:true */
;(function($){ ;(function($){
'use strict'; 'use strict';
var ts = $.tablesorter; var ts = $.tablesorter;
ts.dates = $.extend({}, ts.dates, { ts.dates = $.extend( {}, {
// *** modify this array to match the desired language *** // See http://mottie.github.io/tablesorter/docs/example-widget-grouping.html
monthCased : [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] // 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" }
ts.dates.monthLower = ts.dates.monthCased.join(',').toLocaleLowerCase().split(','); months : {
'en' : {
1 : 'Jan',
2 : 'Feb',
3 : 'Mar',
4 : 'Apr',
5 : 'May',
6 : 'Jun',
7 : 'Jul',
8 : 'Aug',
9 : 'Sep',
10: 'Oct',
11: 'Nov',
12: 'Dec'
}
}
}, ts.dates );
ts.addParser({ ts.addParser({
id: 'month', id: 'month',
is: function(){ is: function() {
return false; return false;
}, },
format: function(s, table) { format: function( str, table, cell, cellIndex ) {
if (s) { if ( str ) {
var j = -1, c = table.config, var m, month,
n = c.ignoreCase ? s.toLocaleLowerCase() : s; c = table.config,
$.each(ts.dates[ 'month' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i, v){ // add options to 'config.globalize' for all columns --> globalize : { lang: 'en' }
if (j < 0 && n.match(v)) { // or per column by using the column index --> globalize : { 0 : { lang: 'fr' } }
j = i; options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {},
return false; months = ts.dates.months[ options.lang || 'en' ];
if ( c.ignoreCase ) {
str = str.toLowerCase();
} }
}); for ( month in months ) {
// return s (original string) if there isn't a match if ( typeof month === 'string' ) {
// (non-weekdays will sort separately and empty cells will sort as expected) m = months[ month ];
return j < 0 ? s : j; if ( c.ignoreCase ) {
m = m.toLowerCase();
} }
return s; if ( str.match( m ) ) {
return parseInt( month, 10 );
}
}
}
}
return str;
}, },
type: 'numeric' type: 'numeric'
}); });

View File

@ -1,36 +1,94 @@
/*! Parser: weekday - updated 10/26/2014 (v2.18.0) */ /*! Parser: weekday - updated 11/2/2015 (v2.24.1) */
/* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */ /* Demo: http://jsfiddle.net/Mottie/abkNM/4169/ */
/*jshint jquery:true */ /*jshint jquery:true */
;(function($){ ;(function($){
'use strict'; 'use strict';
var ts = $.tablesorter; var ts = $.tablesorter;
ts.dates = $.extend({}, ts.dates, { ts.dates = $.extend( true, {}, {
// *** modify this array to change match the language *** // See http://mottie.github.io/tablesorter/docs/example-widget-grouping.html
weekdayCased : [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ] // 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", ... }
ts.dates.weekdayLower = ts.dates.weekdayCased.join(',').toLocaleLowerCase().split(','); 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 );
ts.addParser({ ts.addParser({
id: 'weekday', id: 'weekday',
is: function(){ is: function() {
return false; return false;
}, },
format: function(s, table) { format: function( str, table, cell, cellIndex ) {
if (s) { if ( str ) {
var j = -1, c = table.config; var d, day, num,
s = c.ignoreCase ? s.toLocaleLowerCase() : s; c = table.config,
$.each(ts.dates[ 'weekday' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i, v){ // add options to 'config.globalize' for all columns --> globalize : { lang: 'en' }
if (j < 0 && s.match(v)) { // or per column by using the column index --> globalize : { 0 : { lang: 'fr' } }
j = i; options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {},
return false; 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;
}
}
}
}
return str;
},
type: 'numeric'
}); });
// return s (original string) if there isn't a match
// (non-weekdays will sort separately and empty cells will sort as expected) // useful when a group widget date column is set to "group-date-week"
return j < 0 ? s : j; // 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' ] );
} }
return s; }
return str;
}, },
type: 'numeric' type: 'numeric'
}); });

View File

@ -1,4 +1,4 @@
/*! Parser: jQuery Globalize - updated 10/31/2015 (v2.24.0) */ /*! Parser: jQuery Globalize - updated 11/2/2015 (v2.24.1) */
/* Extract localized data using jQuery's Globalize parsers; set /* Extract localized data using jQuery's Globalize parsers; set
Globalize.locale( 'xx' ) in the globalize settings */ Globalize.locale( 'xx' ) in the globalize settings */
/*jshint jquery:true, newcap: false */ /*jshint jquery:true, newcap: false */
@ -19,7 +19,15 @@
// or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}; options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {};
if ( Globalize ) { if ( Globalize ) {
globalize = typeof options.lang === 'object' ? options.lang : Globalize( options.lang || 'en' ); globalize = typeof options.Globalize === 'object' ?
// initialized Globalize object
options.Globalize :
// Globalize initialized from "lang" option
Globalize( options.lang || 'en' );
if ( !options.Globalize ) {
// cache the object
options.Globalize = globalize;
}
} }
date = globalize && globalize.dateParser ? globalize.dateParser( options )( str ) : date = globalize && globalize.dateParser ? globalize.dateParser( options )( str ) :
str ? new Date( str ) : str; str ? new Date( str ) : str;
@ -41,7 +49,15 @@
// or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } } // or per column by using the column index --> globalize : { 0 : { datetime: 'medium' } }
options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {}; options = c.globalize && ( c.globalize[ cellIndex ] || c.globalize ) || {};
if ( Globalize ) { if ( Globalize ) {
globalize = typeof options.lang === 'object' ? options.lang : Globalize( options.lang || 'en' ); globalize = typeof options.Globalize === 'object' ?
// initialized Globalize object
options.Globalize :
// Globalize initialized from "lang" option
Globalize( options.lang || 'en' );
if ( !options.Globalize ) {
// cache the object
options.Globalize = globalize;
}
} }
num = globalize && globalize.numberParser ? globalize.numberParser( options )( str ) : num = globalize && globalize.numberParser ? globalize.numberParser( options )( str ) :
str ? $.tablesorter.formatFloat( ( str || '' ).replace( /[^\w,. \-()]/g, '' ), table ) : str; str ? $.tablesorter.formatFloat( ( str || '' ).replace( /[^\w,. \-()]/g, '' ), table ) : str;