]> git.sesse.net Git - remoteglot/commitdiff
Click on book line headings to sort by that heading.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 Dec 2014 00:23:03 +0000 (01:23 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 10 Dec 2014 00:23:06 +0000 (01:23 +0100)
www/js/book.js

index f6b0365993500449cc304a221a71c6ea39bc94a8..8bf4756cb0eb8a9c93f0d0f15f829ee47a9c9f5c 100644 (file)
@@ -55,6 +55,7 @@ var headings = [
        [ "EloVar", TYPE_FLOAT ],
        [ "AWin%", TYPE_RATIO ],
 ];
        [ "EloVar", TYPE_FLOAT ],
        [ "AWin%", TYPE_RATIO ],
 ];
+var sort_by = 1;
 
 var show_lines = function(data, game) {
        var moves = data['moves'];
 
 var show_lines = function(data, game) {
        var moves = data['moves'];
@@ -73,6 +74,12 @@ var show_lines = function(data, game) {
                var th = document.createElement("th");
                headings_tr.append(th);
                $(th).text(headings[i][0]);
                var th = document.createElement("th");
                headings_tr.append(th);
                $(th).text(headings[i][0]);
+               (function(new_sort_by) {
+                       $(th).click(function() {
+                               sort_by = new_sort_by;
+                               show_lines(data, game);
+                       });
+               })(i);
        }
 
        var lines = [];
        }
 
        var lines = [];
@@ -122,6 +129,8 @@ var show_lines = function(data, game) {
                lines.push(line);
        }
 
                lines.push(line);
        }
 
+       lines.sort(function(a, b) { return b[sort_by] - a[sort_by]; });
+
        var tbl = $("#lines");
        tbl.empty();
 
        var tbl = $("#lines");
        tbl.empty();