From: Laurent Mazet Date: Sun, 28 Jun 2020 14:34:58 +0000 (+0200) Subject: fix highlight removing when a tile is moved X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=331f0541e14fbdc1abebf45059e98fb22ba1bbd8;p=trivabble.git fix highlight removing when a tile is moved --- 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); + } } } }