]> git.sesse.net Git - remoteglot-book/blobdiff - www/js/book.js
Fix some transposition handling, and add a checkbox to not include them anymore.
[remoteglot-book] / www / js / book.js
index 78dfed815cf8c3c782266ab5e47cf377383a58a0..6017fd9d0d5eb6a91a1238089c080a7af460c819 100644 (file)
@@ -3,6 +3,7 @@
 var board = null;
 var history = [];
 var move_override = 0;
+var includetransp = true;
 
 var entity_map = {
        "&": "&",
@@ -18,9 +19,14 @@ function escape_html(string) {
        });
 }
 
-var get_game = function() {
+var get_game = function(skip_last_move) {
+       var moves_to_drop = 0;
+       if (skip_last_move === true) {
+               moves_to_drop = 1;
+       }
+
        var game = new Chess();
-       for (var i = 0; i < move_override; ++i) {
+       for (var i = 0; i < move_override - moves_to_drop; ++i) {
                game.move(history[i]);
        }
        return game;
@@ -59,8 +65,15 @@ var update = function() {
 
 var fetch_analysis = function() {
        var game = get_game();
+       var fen = game.fen();
+       var prevfen = "";
+       if (move_override > 0) {
+               prevfen = get_game(true).fen();
+       }
        $.ajax({
-               url: "/opening-stats.pl?fen=" + encodeURIComponent(game.fen())
+               url: "/opening-stats.pl?fen=" + encodeURIComponent(fen) +
+                       ";prevfen=" + encodeURIComponent(prevfen) +
+                       ";includetransp=" + (includetransp ? 1 : 0)
        }).done(function(data, textstatus, xhr) {
                show_lines(data, game);
        });
@@ -240,6 +253,12 @@ var show_lines = function(data, game) {
        }
 }
 
+var set_includetransp = function(value) {
+       includetransp = value;
+       update();
+}
+window['set_includetransp'] = set_includetransp;
+
 var make_move = function(move) {
        if (move_override < history.length && history[move_override] == move) {
                // User effectively only moved forward in history.
@@ -303,7 +322,6 @@ var onDrop = function(source, target) {
                history.push(new_history[i].san);
        }
        move_override = history.length;
-       update();
 };
 
 // update the board position after the piece snap 
@@ -311,7 +329,7 @@ var onDrop = function(source, target) {
 var onSnapEnd = function() {
        var game = get_game();
        board.position(game.fen());
-       fetch_analysis();
+       update();
 };
 
 var init = function() {