diff options
author | Evangelos Foutras <foutrelis@gmail.com> | 2011-04-30 14:15:38 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-05-02 17:50:10 +0200 |
commit | 8de1bd0639a8b6117bc35dfe0ad1e6a1ac34f715 (patch) | |
tree | c882ed5fc323a394b396ad69a3df8f5c680452e1 /media | |
parent | a5991a31b92e04059589bf897a593535984384e6 (diff) | |
download | archweb-8de1bd0639a8b6117bc35dfe0ad1e6a1ac34f715.tar.gz archweb-8de1bd0639a8b6117bc35dfe0ad1e6a1ac34f715.tar.xz |
Add filesizeformat filter to sizes in reports/big
We also add a new 'filesize' tablesorter parser that handles all the
suffixes found in django's filesizeformat filter.
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'media')
-rw-r--r-- | media/archweb.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/media/archweb.js b/media/archweb.js index 03358fa..78b1567 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -67,6 +67,33 @@ if (typeof $.tablesorter !== 'undefined') { }, type: 'numeric' }); + $.tablesorter.addParser({ + id: 'filesize', + re: /^(\d+(?:\.\d+)?) (bytes?|KB|MB|GB|TB)$/, + is: function(s) { + return this.re.test(s); + }, + format: function(s) { + var matches = this.re.exec(s); + var size = parseFloat(matches[1]); + var suffix = matches[2]; + + switch(suffix) { + case 'byte': + case 'bytes': + return size; + case 'KB': + return size * 1024; + case 'MB': + return size * 1024 * 1024; + case 'GB': + return size * 1024 * 1024 * 1024; + case 'TB': + return size * 1024 * 1024 * 1024 * 1024; + } + }, + type: 'numeric' + }); } /* news/add.html */ |