From: Laurent Mazet Date: Fri, 14 Aug 2020 08:54:16 +0000 (+0200) Subject: add spell checker enabler into configuration window X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=8d927835d3ed62d9681a227bbe2348f9c349f47a;p=trivabble.git add spell checker enabler into configuration window --- diff --git a/public/index.html b/public/index.html index 4611093..22d6993 100644 --- a/public/index.html +++ b/public/index.html @@ -53,6 +53,7 @@

+

@@ -77,7 +78,6 @@

Who's turn? Click on the Turn button!

- diff --git a/public/trivabble.css b/public/trivabble.css index 09129f0..da4138a 100644 --- a/public/trivabble.css +++ b/public/trivabble.css @@ -520,3 +520,7 @@ td.blink { transform: scale(1.0); transition: visibility 0s linear 0s, opacity 0.25s 0s, transform 0.25s; } + +.alert { + z-index: 2; +} diff --git a/public/trivabble.js b/public/trivabble.js index 9163a60..e7d2011 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -42,6 +42,7 @@ setConf("ENABLE_EVENT_SOURCE", true); setConf("MAX_WEBSOCKET_ERRORS", 1); setConf("APP_PATH", ""); + setConf("ENABLE_SPELL_CHECKER", false); const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) { return s; @@ -150,32 +151,40 @@ } } - function downloadDictionary(code) { - if (localStorage.spellChecker) { - document.getElementById("enable-spell-checker").style.display = "none"; + function checkSpellCheckerState(code) { + if (code !== null) { + localStorage.spellChecker = code; + } + if (localStorage.spellChecker !== "false") { + document.getElementById("enable-spell-checker").checked = true; document.getElementById("check-spelling").style.display = "block"; } else { - document.getElementById("enable-spell-checker").style.display = "block"; + document.getElementById("enable-spell-checker").checked = false; document.getElementById("check-spelling").style.display = "none"; } + } - /* static variable */ - if (downloadDictionary.code === code) { + function downloadDictionary(code) { + if (localStorage.spellChecker === code) { return; } - downloadDictionary.code = code; const file = new XMLHttpRequest(); file.overrideMimeType("application/dictionary"); file.open("GET", "dict/" + code + ".dict", true); file.onreadystatechange = function () { - if ((file.readyState === 4) && (file.status == "200")) { - try { - dictionary = file.responseText.split("\n"); - document.getElementById("enable-spell-checker").style.display = "none"; - document.getElementById("check-spelling").style.display = "block"; - } catch (e) { - myAlert(_("Incorrect dictionary file.")); + if (file.readyState === 4) { + if (file.status == "200") { + try { + dictionary = file.responseText.split("\n"); + checkSpellCheckerState(code); + } catch (e) { + myAlert(_("Incorrect dictionary file.")); + checkSpellCheckerState("false"); + } + } else { + myAlert(_("Can't load dictionary file.")); + checkSpellCheckerState("false"); } } }; @@ -183,16 +192,18 @@ } function enableSpellChecker() { - myConfirm( - _("Spell checking requires Trivabble to download a dictionary. This dictionary is based on Aspell. Do you confirm?"), - function () { - localStorage.spellChecker = true; - downloadDictionary(localStorage.trivabbleBoardLang); - }, - function () { - localStorage.spellChecker = false; - downloadDictionary(localStorage.trivabbleBoardLang); - }); + if (document.getElementById("enable-spell-checker").checked) { + myConfirm( + _("Spell checking requires Trivabble to download a dictionary. This dictionary is based on Aspell. Do you confirm?"), + function () { + downloadDictionary(localStorage.trivabbleBoardLang); + }, + function () { + checkSpellCheckerState("false"); + }); + } else { + checkSpellCheckerState("false"); + } } function removeElem(elem) { @@ -600,7 +611,9 @@ case "boardLang": localStorage.trivabbleBoardLang = value; document.getElementById("board-lang").value = value; - downloadDictionary(value); + if (localStorage.spellChecker !== "false") { + downloadDictionary(value); + } break; } } @@ -1622,6 +1635,9 @@ } function checkSpelling() { + if (localStorage.spellChecker === false) { + return; + } const newWords = searchNewWords(); if (newWords.length === 0) { @@ -1743,6 +1759,20 @@ } } + function initSpellChecker() { + if (!Object.prototype.hasOwnProperty.call(localStorage, "spellChecker")) { + localStorage.spellChecker = Conf.SPELL_CHECKER; + } + + document.getElementById("enable-spell-checker").onclick = enableSpellChecker; + + if (localStorage.spellChecker !== "false") { + downloadDictionary(localStorage.spellChecker) + } else { + checkSpellCheckerState("false"); + } + } + function repromptName(f) { if (localStorage.trivabblePlayerName && localStorage.trivabblePlayerName.trim()) { f(); @@ -1835,7 +1865,6 @@ document.getElementById("join-game").onclick = joinGame; document.getElementById("clear-rack").onclick = clearRack; document.getElementById("show-rack").onclick = showRack; - document.getElementById("enable-spell-checker").onclick = enableSpellChecker; document.getElementById("check-spelling").onclick = checkSpelling; helpClear.onclick = clearGame; @@ -1961,6 +1990,7 @@ initChat(); initGame(); initSound(); + initSpellChecker(); }; trivabble.l10nError = trivabble.run;