From 85375530a97297ebb1574a16ae6a8ebc3395537e Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Sun, 15 Mar 2020 14:31:21 -0500 Subject: [PATCH] fix .cb-legal and .cb-start classes not placed correctly in some corner cases --- js/chess.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/js/chess.js b/js/chess.js index 3aab91e..be18fcb 100644 --- a/js/chess.js +++ b/js/chess.js @@ -554,6 +554,7 @@ function renderBoard(board){ $('#cb_board .cb-piece').attr('style', '').appendTo('#cb_hidden'); $('#cb_board .cb-start').removeClass('cb-start'); $('#cb_board .cb-end').removeClass('cb-end'); + $('#cb_board .cb-legal').removeClass('cb-legal'); $('#cb_phantom').appendTo('#cb_hidden'); for (const side of ['light', 'dark']) { @@ -588,13 +589,14 @@ function renderBoard(board){ } } - if (board.move) { - if (board.move.from === 'phantom') { - $('#cb_' + board.prior.move.to).addClass('cb-start'); - } else { - $('#cb_' + board.move.from).addClass('cb-start'); - } - $('#cb_' + board.move.to).addClass('cb-end'); + const start = movedFrom(board); + if (start) { + $('#cb_' + start).addClass('cb-start'); + } + + const end = movedTo(board); + if (end) { + $('#cb_' + end).addClass('cb-end'); } let msg = '';