fix highlight removing when a tile is moved
authorLaurent Mazet <mazet@softndesign.org>
Sun, 28 Jun 2020 14:34:58 +0000 (16:34 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 28 Jun 2020 14:34:58 +0000 (16:34 +0200)
public/trivabble.js

index 94c83274e94e56d18f3ecd35cf103c86f8ad536c..91b82e0bb30e074b33881db67105fe3f12e67164 100644 (file)
     }
 
     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);
+                }
             }
         }
     }