2015-03-28 20:03:50 +00:00
|
|
|
/*! Parser: duration & countdown - updated 2/7/2015 (v2.19.0) */
|
2014-09-12 16:08:39 +00:00
|
|
|
/*jshint jquery:true, unused:false */
|
2018-03-17 20:30:25 +00:00
|
|
|
;(function($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2014-09-12 16:08:39 +00:00
|
|
|
|
|
|
|
// If any number > 9999, then set table.config.durationLength = 5
|
|
|
|
// The below regex matches this duration example: 1y 23d 12h 44m 9s
|
|
|
|
$.tablesorter.addParser({
|
2015-02-05 04:06:16 +00:00
|
|
|
id: 'duration',
|
2014-09-12 16:08:39 +00:00
|
|
|
is: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
format: function(s, table) {
|
|
|
|
var i, time,
|
|
|
|
c = table.config,
|
|
|
|
t = '',
|
|
|
|
duration = '',
|
|
|
|
len = c.durationLength || 4,
|
|
|
|
str = new Array(len + 1).join('0'),
|
2014-09-16 00:14:50 +00:00
|
|
|
labels = (c.durationLabels || '(?:years|year|y),(?:days|day|d),(?:hours|hour|h),(?:minutes|minute|min|m),(?:seconds|second|sec|s)').split(/\s*,\s*/),
|
2014-09-12 16:08:39 +00:00
|
|
|
llen = labels.length;
|
2014-09-16 00:14:50 +00:00
|
|
|
// build regex
|
2014-09-12 16:08:39 +00:00
|
|
|
if (!c.durationRegex) {
|
|
|
|
for (i = 0; i < llen; i++) {
|
2014-09-16 00:14:50 +00:00
|
|
|
t += '(?:(\\d+)\\s*' + labels[i] + '\\s*)?';
|
2014-09-12 16:08:39 +00:00
|
|
|
}
|
|
|
|
c.durationRegex = new RegExp(t, 'i');
|
|
|
|
}
|
2014-09-16 00:14:50 +00:00
|
|
|
// remove commas from value
|
|
|
|
time = ( c.usNumberFormat ? s.replace(/,/g, '') : s.replace( /(\d)(?:\.|\s*)(\d)/g, '$1$2') ).match(c.durationRegex);
|
2014-09-12 16:08:39 +00:00
|
|
|
for (i = 1; i < llen + 1; i++) {
|
|
|
|
duration += ( str + ( time[i] || 0 ) ).slice(-len);
|
|
|
|
}
|
|
|
|
return duration;
|
|
|
|
},
|
2015-02-05 04:06:16 +00:00
|
|
|
type: 'text'
|
|
|
|
});
|
|
|
|
|
|
|
|
/*! Countdown parser ( hh:mm:ss ) */
|
2015-02-07 06:46:44 +00:00
|
|
|
/* Added 2/7/2015 (v2.19.0) - see http://stackoverflow.com/a/27023733/145346 */
|
2015-02-05 04:06:16 +00:00
|
|
|
$.tablesorter.addParser({
|
|
|
|
id: 'countdown',
|
|
|
|
is: function () {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
format: function ( text, table ) {
|
|
|
|
// change maxDigits to 4, if values go > 999
|
|
|
|
// or to 5 for values > 9999, etc.
|
|
|
|
var maxDigits = table.config.durationLength || 4,
|
|
|
|
// prefix contains leading zeros that are tacked
|
|
|
|
prefix = new Array( maxDigits + 1 ).join( '0' ),
|
|
|
|
// split time into blocks
|
|
|
|
blocks = text.split( /\s*:\s*/ ),
|
|
|
|
len = blocks.length,
|
|
|
|
result = [];
|
|
|
|
// add values in reverse, so if there is only one block
|
|
|
|
// ( e.g. '10' ), then it would be the time in seconds
|
|
|
|
while ( len ) {
|
|
|
|
result.push( ( prefix + ( blocks[ --len ] || 0 ) ).slice( -maxDigits ) );
|
|
|
|
}
|
|
|
|
// reverse the results and join them
|
|
|
|
return result.length ? result.reverse().join( '' ) : text;
|
|
|
|
},
|
|
|
|
type: 'text'
|
2014-09-12 16:08:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|