From 32a0bfe976b8e986d90dd811833135aadcaa3cdf Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sun, 31 May 2020 23:59:03 +0200 Subject: [PATCH] spell checker for multiplayer game corrected --- public/trivabble.js | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/public/trivabble.js b/public/trivabble.js index 205bfea..3d64201 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -670,6 +670,24 @@ return content; } + function downloadDictionnary(code) { + const file = new XMLHttpRequest(); + file.overrideMimeType("application/json"); + file.open("GET", "dict/" + code + ".json", true); + file.onreadystatechange = function () { + if ((file.readyState === 4) && (file.status == "200")) { + try { + dictionnary = JSON.parse(file.responseText); + document.getElementById("check-spelling").disabled = false; + } catch (e) { + console.error(e); + } + } + }; + file.send(null); + return; + } + function handleChatMessage(msg) { if (msg.specialMsg) { switch (msg.specialMsg.type) { @@ -695,23 +713,7 @@ : format(_("{0} changed the language of the board to {1}"), msg.sender, newLang) ); document.getElementById("check-spelling").disabled = true; - const code = document.getElementById("board-lang").value; - const file = new XMLHttpRequest(); - file.overrideMimeType("application/json"); - file.open("GET", "dict/" + code + ".json", true); - file.onreadystatechange = function () { - if ((file.readyState === 4) && (file.status == "200")) { - try { - dictionnary = JSON.parse(file.responseText); - - document.getElementById("check-spelling").disabled = false; - } catch (e) { - console.error(e); - } - } - }; - file.send(null); - return; + downloadDictionnary(msg.specialMsg.newBoardLang); } } } @@ -1818,7 +1820,9 @@ } if (localStorage.trivabbleBoardLang) { + document.getElementById("check-spelling").disabled = true; document.getElementById("board-lang").value = localStorage.trivabbleBoardLang; + downloadDictionnary(localStorage.trivabbleBoardLang); } startGame(localStorage.trivabbleGameNumber, localStorage.trivabbleBoardLang); -- 2.30.2