Made tablesorter work without inline-js

Signed-off-by: Roman Schmerold (BNoiZe) <bnoize@froxlor.org>
This commit is contained in:
Roman Schmerold (BNoiZe)
2014-12-02 17:27:41 +01:00
parent 9627238966
commit 6f5f69db2b
7 changed files with 139 additions and 140 deletions

View File

@@ -0,0 +1,23 @@
$.tablesorter.addParser({
id: 'filesize',
is: function(s) {
return s.match(new RegExp(/[0-9]+(\.[0-9]+)?\ (KiB|B|GiB|MiB|TiB)/));
},
format: function(s) {
var suf = s.match(new RegExp(/(KiB|B|GiB|MiB|TiB)/))[1];
var num = parseFloat(s.match(new RegExp(/^[0-9]+(\.[0-9]+)?/))[0]);
switch (suf) {
case 'B':
return num;
case 'KiB':
return num * 1024;
case 'MiB':
return num * 1024 * 1024;
case 'GiB':
return num * 1024 * 1024 * 1024;
case 'TiB':
return num * 1024 * 1024 * 1024 * 1024;
}
},
type: 'numeric'
});