| 1 |
|
| 2 |
|
| 3 |
;(function($) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
$.tablesorter.addParser({ |
| 9 |
id: 'duration', |
| 10 |
is: function() { |
| 11 |
return false; |
| 12 |
}, |
| 13 |
format: function(s, table) { |
| 14 |
var i, time, |
| 15 |
c = table.config, |
| 16 |
t = '', |
| 17 |
duration = '', |
| 18 |
len = c.durationLength || 4, |
| 19 |
str = new Array(len + 1).join('0'), |
| 20 |
labels = (c.durationLabels || '(?:years|year|y),(?:days|day|d),(?:hours|hour|h),(?:minutes|minute|min|m),(?:seconds|second|sec|s)').split(/\s*,\s*/), |
| 21 |
llen = labels.length; |
| 22 |
|
| 23 |
if (!c.durationRegex) { |
| 24 |
for (i = 0; i < llen; i++) { |
| 25 |
t += '(?:(\\d+)\\s*' + labels[i] + '\\s*)?'; |
| 26 |
} |
| 27 |
c.durationRegex = new RegExp(t, 'i'); |
| 28 |
} |
| 29 |
|
| 30 |
time = ( c.usNumberFormat ? s.replace(/,/g, '') : s.replace( /(\d)(?:\.|\s*)(\d)/g, '$1$2') ).match(c.durationRegex); |
| 31 |
for (i = 1; i < llen + 1; i++) { |
| 32 |
duration += ( str + ( time[i] || 0 ) ).slice(-len); |
| 33 |
} |
| 34 |
return duration; |
| 35 |
}, |
| 36 |
type: 'text' |
| 37 |
}); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
$.tablesorter.addParser({ |
| 42 |
id: 'countdown', |
| 43 |
is: function () { |
| 44 |
return false; |
| 45 |
}, |
| 46 |
format: function ( text, table ) { |
| 47 |
|
| 48 |
|
| 49 |
var maxDigits = table.config.durationLength || 4, |
| 50 |
|
| 51 |
prefix = new Array( maxDigits + 1 ).join( '0' ), |
| 52 |
|
| 53 |
blocks = text.split( /\s*:\s*/ ), |
| 54 |
len = blocks.length, |
| 55 |
result = []; |
| 56 |
|
| 57 |
|
| 58 |
while ( len ) { |
| 59 |
result.push( ( prefix + ( blocks[ --len ] || 0 ) ).slice( -maxDigits ) ); |
| 60 |
} |
| 61 |
|
| 62 |
return result.length ? result.reverse().join( '' ) : text; |
| 63 |
}, |
| 64 |
type: 'text' |
| 65 |
}); |
| 66 |
|
| 67 |
})(jQuery); |