mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
general parser formatting & cleaning
This commit is contained in:
parent
214bce4e95
commit
c1d102c698
@ -5,13 +5,14 @@
|
||||
;(function($){
|
||||
"use strict";
|
||||
|
||||
$.tablesorter.dates = $.extend({}, $.tablesorter.dates, {
|
||||
var ts = $.tablesorter;
|
||||
ts.dates = $.extend({}, ts.dates, {
|
||||
// *** modify this array to change match the language ***
|
||||
monthCased : [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
|
||||
});
|
||||
$.tablesorter.dates.monthLower = $.tablesorter.dates.monthCased.join(',').toLocaleLowerCase().split(',');
|
||||
ts.dates.monthLower = ts.dates.monthCased.join(',').toLocaleLowerCase().split(',');
|
||||
|
||||
$.tablesorter.addParser({
|
||||
ts.addParser({
|
||||
id: "month",
|
||||
is: function(){
|
||||
return false;
|
||||
@ -19,7 +20,7 @@
|
||||
format: function(s, table) {
|
||||
var j = -1, c = table.config;
|
||||
s = c.ignoreCase ? s.toLocaleLowerCase() : s;
|
||||
$.each($.tablesorter.dates[ 'month' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
|
||||
$.each(ts.dates[ 'month' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
|
||||
if (j < 0 && s.match(v)) { j = i; }
|
||||
});
|
||||
// return s (original string) if there isn't a match
|
||||
|
@ -5,21 +5,26 @@
|
||||
;(function($){
|
||||
"use strict";
|
||||
|
||||
var ts = $.tablesorter,
|
||||
|
||||
// Make the date be within +/- range of the 2 digit year
|
||||
// so if the current year is 2020, and the 2 digit year is 80 (2080 - 2020 > 50), it becomes 1980
|
||||
// if the 2 digit year is 50 (2050 - 2020 < 50), then it becomes 2050.
|
||||
var range = 50,
|
||||
range = 50;
|
||||
|
||||
// ************
|
||||
regxxxxyy = /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/,
|
||||
regyyxxxx = /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/,
|
||||
formatDate = function(s, regex, format){
|
||||
ts.dates = $.extend({}, ts.dates, {
|
||||
regxxxxyy: /(\d{1,2})[\/\s](\d{1,2})[\/\s](\d{2})/,
|
||||
regyyxxxx: /(\d{2})[\/\s](\d{1,2})[\/\s](\d{1,2})/
|
||||
});
|
||||
|
||||
ts.formatDate = function(s, regex, format){
|
||||
s = s
|
||||
// replace separators
|
||||
.replace(/\s+/g," ").replace(/[-.,]/g, "/")
|
||||
// reformat xx/xx/xx to mm/dd/19yy;
|
||||
.replace(regex, format);
|
||||
var d = new Date(s), y = d.getFullYear(),
|
||||
var d = new Date(s),
|
||||
y = d.getFullYear(),
|
||||
now = new Date().getFullYear();
|
||||
// if date > 50 years old (set range), add 100 years
|
||||
// this will work when people start using "50" and mean "2050"
|
||||
@ -36,7 +41,7 @@
|
||||
},
|
||||
format: function(s) {
|
||||
// reformat dd/mm/yy to mm/dd/19yy;
|
||||
return formatDate(s, regxxxxyy, "$2/$1/19$3");
|
||||
return ts.formatDate(s, ts.dates.regxxxxyy, "$2/$1/19$3");
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -48,7 +53,7 @@
|
||||
},
|
||||
format: function(s) {
|
||||
// reformat mm/dd/yy to mm/dd/19yy
|
||||
return formatDate(s, regxxxxyy, "$1/$2/19$3");
|
||||
return ts.formatDate(s, ts.dates.regxxxxyy, "$1/$2/19$3");
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
@ -60,7 +65,7 @@
|
||||
},
|
||||
format: function(s) {
|
||||
// reformat yy/mm/dd to mm/dd/19yy
|
||||
return formatDate(s, regyyxxxx, "$2/$3/19$1");
|
||||
return ts.formatDate(s, ts.dates.regyyxxxx, "$2/$3/19$1");
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
|
@ -5,13 +5,14 @@
|
||||
;(function($){
|
||||
"use strict";
|
||||
|
||||
$.tablesorter.dates = $.extend({}, $.tablesorter.dates, {
|
||||
var ts = $.tablesorter;
|
||||
ts.dates = $.extend({}, ts.dates, {
|
||||
// *** modify this array to change match the language ***
|
||||
weekdayCased : [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
|
||||
});
|
||||
$.tablesorter.dates.weekdayLower = $.tablesorter.dates.weekdayCased.join(',').toLocaleLowerCase().split(',');
|
||||
ts.dates.weekdayLower = ts.dates.weekdayCased.join(',').toLocaleLowerCase().split(',');
|
||||
|
||||
$.tablesorter.addParser({
|
||||
ts.addParser({
|
||||
id: "weekday",
|
||||
is: function(){
|
||||
return false;
|
||||
@ -19,7 +20,7 @@
|
||||
format: function(s, table) {
|
||||
var j = -1, c = table.config;
|
||||
s = c.ignoreCase ? s.toLocaleLowerCase() : s;
|
||||
$.each($.tablesorter.dates[ 'weekday' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
|
||||
$.each(ts.dates[ 'weekday' + (c.ignoreCase ? 'Lower' : 'Cased') ], function(i,v){
|
||||
if (j < 0 && s.match(v)) { j = i; }
|
||||
});
|
||||
// return s (original string) if there isn't a match
|
||||
|
@ -14,7 +14,7 @@
|
||||
return false;
|
||||
},
|
||||
format: function(s) {
|
||||
return Date.create ? Date.create(s).getTime() || s : s;
|
||||
return Date.create ? Date.create(s).getTime() || s : new Date(s).getTime() || s;
|
||||
},
|
||||
type: "numeric"
|
||||
});
|
||||
|
@ -7,14 +7,15 @@
|
||||
;(function($){
|
||||
"use strict";
|
||||
|
||||
var symbolRegex = /[\u215b\u215c\u215d\u215e\u00bc\u00bd\u00be]/g,
|
||||
processFractions = function(n, table){
|
||||
var ts = $.tablesorter;
|
||||
ts.symbolRegex = /[\u215b\u215c\u215d\u215e\u00bc\u00bd\u00be]/g;
|
||||
ts.processFractions = function(n, table) {
|
||||
if (n) {
|
||||
var t, p = 0;
|
||||
n = $.trim(n.replace(/\"/,''));
|
||||
// look for a space in the first part of the number: "10 3/4" and save the "10"
|
||||
if (/\s/.test(n)) {
|
||||
p = $.tablesorter.formatFloat(n.split(' ')[0], table);
|
||||
p = ts.formatFloat(n.split(' ')[0], table);
|
||||
// remove stuff to the left of the space
|
||||
n = $.trim(n.substring(n.indexOf(' '), n.length));
|
||||
}
|
||||
@ -24,8 +25,8 @@
|
||||
// turn 3/4 into .75; make sure we don't divide by zero
|
||||
n = p + parseInt(t[0], 10) / parseInt(t[1] || 1, 10);
|
||||
// look for fraction symbols
|
||||
} else if (symbolRegex.test(n)) {
|
||||
n = p + n.replace(symbolRegex, function(m){
|
||||
} else if (ts.symbolRegex.test(n)) {
|
||||
n = p + n.replace(ts.symbolRegex, function(m){
|
||||
return {
|
||||
'\u215b' : '.125', // 1/8
|
||||
'\u215c' : '.375', // 3/8
|
||||
@ -49,12 +50,11 @@
|
||||
},
|
||||
format: function(s, table) {
|
||||
if (s === '') { return ''; }
|
||||
|
||||
// look for feet symbol = '
|
||||
// very generic test to catch 1.1', 1 1/2' and 1½'
|
||||
var d = (/^\s*\S*(\s+\S+)?\s*\'/.test(s)) ? s.split("'") : [0,s],
|
||||
f = processFractions(d[0], table), // feet
|
||||
i = processFractions(d[1], table); // inches
|
||||
f = ts.processFractions(d[0], table), // feet
|
||||
i = ts.processFractions(d[1], table); // inches
|
||||
return (/[\'\"]/).test(s) ? parseFloat(f) + (parseFloat(i)/12 || 0) : parseFloat(f) + parseFloat(i);
|
||||
},
|
||||
type: 'numeric'
|
||||
|
@ -47,7 +47,7 @@
|
||||
b, t,
|
||||
// process number here to get a numerical format (us or eu)
|
||||
n = $.tablesorter.formatFloat(s.replace(/[^\w,. \-()]/g, ""), table),
|
||||
$t = $(table).find('thead').children().children('[data-column="' + cellIndex + '"]'),
|
||||
$t = table.config.$headers.filter('[data-column="' + cellIndex + '"]'),
|
||||
m = $t.data('metric');
|
||||
if (!m) {
|
||||
// stored values
|
||||
|
Loading…
Reference in New Issue
Block a user