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;
}
}
- 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");
}
}
};
}
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) {
case "boardLang":
localStorage.trivabbleBoardLang = value;
document.getElementById("board-lang").value = value;
- downloadDictionary(value);
+ if (localStorage.spellChecker !== "false") {
+ downloadDictionary(value);
+ }
break;
}
}
}
function checkSpelling() {
+ if (localStorage.spellChecker === false) {
+ return;
+ }
const newWords = searchNewWords();
if (newWords.length === 0) {
}
}
+ 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();
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;
initChat();
initGame();
initSound();
+ initSpellChecker();
};
trivabble.l10nError = trivabble.run;