}
/* Look for last letter in line */
- let word = {letters: "", row: row, col: col, incRow: incRow, incCol: incCol};
+ const word = {letters: "", row: row, col: col, incRow: incRow, incCol: incCol};
let letter;
while ((letter = getLetterFromBoard(row, col)) !== "") {
word.letters += letter;
}
function modifyTileClass(word, value, action) {
+
/* action: true for add, false for remove */
+
if (action) {
+
/* only for new words */
for (let l = 0; l < word.letters.length; l++) {
- const index = ((word.row + l * word.incRow) * 15) + word.col + l * word.incCol;
+ 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 {
+
/* tiles on board */
for (let index = 0; index < 15 * 15; index++) {
const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0];
tile.classList.remove(value);
}
}
+
/* tiles on rack */
- for (let tilePlaceholder of rack.getElementsByClassName("tile-placeholder")) {
+ for (const tilePlaceholder of rack.getElementsByClassName("tile-placeholder")) {
const tile = tilePlaceholder.getElementsByClassName("tile")[0];
if (typeof tile !== "undefined") {
tile.classList.remove(value);
}
}
+
/* tile on the move */
if (movingTile !== null) {
movingTile.classList.remove(value);
function checkSpelling() {
- let newWords = searchNewWords();
+ const newWords = searchNewWords();
if (newWords.length === 0) {
myAlert(_("No new word found"));
return;
let words = [];
let badWords = [];
for (const k of Object.keys(newWords)) {
- let currentWord = newWords[k].letters.replace(/ /g, "?");
+ const currentWord = newWords[k].letters.replace(/ /gu, "?");
if (words.indexOf(currentWord) === -1) {
words.push(currentWord);
}
modifyTileClass(newWords[k], "tile-spelling-ok", true);
- const pattern = "^" + newWords[k].letters.replace(/ /g, ".") + "$";
+ const pattern = "^" + newWords[k].letters.replace(/ /gu, ".") + "$";
if (!dictionary.find(function (word) {return word.match(pattern);})) {
if (badWords.indexOf(currentWord) === -1) {
badWords.push(currentWord);
modifyTileClass(newWords[k], "tile-spelling-nok", true);
}
}
- setTimeout(function () {
+ setTimeout(
+ function () {
modifyTileClass(null, "tile-spelling-ok", false);
modifyTileClass(null, "tile-spelling-nok", false);
}, 5000);