From 331f0541e14fbdc1abebf45059e98fb22ba1bbd8 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sun, 28 Jun 2020 16:34:58 +0200 Subject: [PATCH] fix highlight removing when a tile is moved --- public/trivabble.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/public/trivabble.js b/public/trivabble.js index 94c8327..91b82e0 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -1562,14 +1562,21 @@ } function highlightWord(word, value, onOff) { - for (let l = 0; l < word.letters.length; l++) { - const index = ((word.row + l * word.incRow) * 15) + word.col + l * word.incCol; - const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0]; - const tile = tilePlaceholder.getElementsByClassName("tile")[0]; - if (onOff) { + if (onOff) { + for (let l = 0; l < word.letters.length; l++) { + const index = ((word.row + l * word.incRow) * 15) + word.col + l * word.incCol; + const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0]; + const tile = tilePlaceholder.getElementsByClassName("tile")[0]; + tile.classList.add(value); - } else { - tile.classList.remove(value); + } + } else { + for (let index = 0; index < 15 * 15; index++) { + const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0]; + const tile = tilePlaceholder.getElementsByClassName("tile")[0]; + if (typeof tile !== "undefined") { + tile.classList.remove(value); + } } } } -- 2.30.2