spell checker for multiplayer game corrected
authorLaurent Mazet <mazet@softndesign.org>
Sun, 31 May 2020 21:59:03 +0000 (23:59 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Mon, 8 Jun 2020 05:48:36 +0000 (07:48 +0200)
public/trivabble.js

index 205bfea83707264c85e42d5c03ce94e7bb205d64..3d6420111a42d5a785b778fb943293c2e625de9c 100644 (file)
         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) {
                             : 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);
                 }
             }
         }
         }
 
         if (localStorage.trivabbleBoardLang) {
+            document.getElementById("check-spelling").disabled = true;
             document.getElementById("board-lang").value = localStorage.trivabbleBoardLang;
+            downloadDictionnary(localStorage.trivabbleBoardLang);
         }
 
         startGame(localStorage.trivabbleGameNumber, localStorage.trivabbleBoardLang);