summaryrefslogtreecommitdiffstats
path: root/data/js/script.js
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-05-23 17:44:45 +0200
committerFlorian Pritz <bluewind@xinu.at>2013-05-24 00:11:26 +0200
commit2a6a1c63cb21015009fe4fd13f62cdac64e1fe36 (patch)
treea01b7cdf6e8819b5f41df4dae8b31c04d9904e38 /data/js/script.js
parentb7ff91d8e34e1d9f04ad0b153e94441efd312f78 (diff)
upload_history: Allow column sorting (jquery.tablesorter)
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'data/js/script.js')
-rw-r--r--data/js/script.js77
1 files changed, 75 insertions, 2 deletions
diff --git a/data/js/script.js b/data/js/script.js
index ce20e922d..15072b412 100644
--- a/data/js/script.js
+++ b/data/js/script.js
@@ -3,7 +3,6 @@ function fixedEncodeURIComponent (str) {
}
(function($) {
-
$(function() {
$(window).bind('hashchange', function(e) {
@@ -89,6 +88,80 @@ function fixedEncodeURIComponent (str) {
$('.file-upload').bind('change', checkFileUpload);
}
- });
+ if (typeof $.tablesorter !== 'undefined') {
+ // source: https://projects.archlinux.org/archweb.git/tree/sitestatic/archweb.js
+ $.tablesorter.addParser({
+ id: 'filesize',
+ re: /^(\d+(?:\.\d+)?)(bytes?|[KMGTPEZY]i?B|B)$/,
+ is: function(s) {
+ return this.re.test(s);
+ },
+ format: function(s) {
+ var matches = this.re.exec(s);
+ if (!matches) {
+ return 0;
+ }
+ var size = parseFloat(matches[1]),
+ suffix = matches[2];
+
+ switch(suffix) {
+ /* intentional fall-through at each level */
+ case 'YB':
+ case 'YiB':
+ size *= 1024;
+ case 'ZB':
+ case 'ZiB':
+ size *= 1024;
+ case 'EB':
+ case 'EiB':
+ size *= 1024;
+ case 'PB':
+ case 'PiB':
+ size *= 1024;
+ case 'TB':
+ case 'TiB':
+ size *= 1024;
+ case 'GB':
+ case 'GiB':
+ size *= 1024;
+ case 'MB':
+ case 'MiB':
+ size *= 1024;
+ case 'KB':
+ case 'KiB':
+ size *= 1024;
+ }
+ return size;
+ },
+ type: 'numeric'
+ });
+ $.tablesorter.addParser({
+ // set a unique id
+ id: 'mydate',
+ re: /t=([0-9]+)$/,
+ is: function(s) {
+ // return false so this parser is not auto detected
+ return false;
+ },
+ format: function(s) {
+ var matches = this.re.exec(s);
+ if (!matches) {
+ return 0;
+ }
+ //console.log(s, matches);
+ return matches[1];
+ },
+ type: 'numeric'
+ });
+ $("#upload_history:has(tbody tr)").tablesorter({
+ headers: {
+ 0: {sorter: false},
+ 4: {sorter: "mydate"},
+ },
+ sortList: [[4,1]],
+ });
+ }
+
+ });
})(jQuery);