]> git.sesse.net Git - remoteglot-book/blobdiff - www/js/book.js
Load and display the root PGN.
[remoteglot-book] / www / js / book.js
index 8bf4756cb0eb8a9c93f0d0f15f829ee47a9c9f5c..ab5e4112e04a28ebf740234609f807e732d59ec9 100644 (file)
@@ -56,10 +56,12 @@ var headings = [
        [ "AWin%", TYPE_RATIO ],
 ];
 var sort_by = 1;
+var direction = 1;
 
 var show_lines = function(data, game) {
        var moves = data['moves'];
        $('#numviewers').text(data['opening']);
+       $('#rootgame').text(data['root_pgn']);
        var total_num = 0;
        for (var i = 0; i < moves.length; ++i) {
                var move = moves[i];
@@ -76,7 +78,12 @@ var show_lines = function(data, game) {
                $(th).text(headings[i][0]);
                (function(new_sort_by) {
                        $(th).click(function() {
-                               sort_by = new_sort_by;
+                               if (sort_by == new_sort_by) {
+                                       direction = -direction;
+                               } else {
+                                       sort_by = new_sort_by;
+                                       direction = 1;
+                               }
                                show_lines(data, game);
                        });
                })(i);
@@ -129,7 +136,7 @@ var show_lines = function(data, game) {
                lines.push(line);
        }
 
-       lines.sort(function(a, b) { return b[sort_by] - a[sort_by]; });
+       lines.sort(function(a, b) { return direction * ( b[sort_by] - a[sort_by]); });
 
        var tbl = $("#lines");
        tbl.empty();