From 0fffdf3788f056762564be75f1f245fc26e7ad2d Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 1 Jun 2020 00:39:22 +0200 Subject: [PATCH] load dictionnary for new players --- public/trivabble.js | 49 +++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/public/trivabble.js b/public/trivabble.js index 3d64201..96f0923 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -150,6 +150,31 @@ } } + function downloadDictionnary(code) { + if (typeof downloadDictionnary.code === "undefined") { + downloadDictionnary.code = ""; + } else if (downloadDictionnary.code === code) { + return; + } + downloadDictionnary.code = 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 removeElem(elem) { elem.parentNode.removeChild(elem); } @@ -555,6 +580,8 @@ case "boardLang": localStorage.trivabbleBoardLang = value; document.getElementById("board-lang").value = value; + document.getElementById("check-spelling").disabled = true; + downloadDictionnary(value); break; } } @@ -670,24 +697,6 @@ 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) { @@ -712,8 +721,6 @@ ? format(_("You changed the language of the board to {0}"), newLang) : format(_("{0} changed the language of the board to {1}"), msg.sender, newLang) ); - document.getElementById("check-spelling").disabled = true; - downloadDictionnary(msg.specialMsg.newBoardLang); } } } @@ -1820,9 +1827,7 @@ } 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