From 985bff13b71f2a6c5357e2da7e60ee79e41ef868 Mon Sep 17 00:00:00 2001 From: sigmasternchen Date: Mon, 4 Nov 2024 12:02:39 +0100 Subject: [PATCH] feat: Clear move selection when clicking on the source piece --- js/src/board.ext.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/js/src/board.ext.js b/js/src/board.ext.js index 3d329e4..0bb505d 100644 --- a/js/src/board.ext.js +++ b/js/src/board.ext.js @@ -31,13 +31,17 @@ const loadBoard = (board) => { board.querySelectorAll(".piece.hasMoves").forEach(element => { element.addEventListener("click", event => { - clearSelection(); - const moves = element.getAttribute("data-moves").split(";").map(move => ({ - encoded: move, - source: move.split(",")[0].split("-")[2], - target: move.split(",")[1] - })); - enterSelection(moves); + if (board.classList.contains("moveSelection")) { + clearSelection(); + } else { + clearSelection(); + const moves = element.getAttribute("data-moves").split(";").map(move => ({ + encoded: move, + source: move.split(",")[0].split("-")[2], + target: move.split(",")[1] + })); + enterSelection(moves); + } event.stopPropagation(); }); });