Fix settings and unset SpellCheckerEnabledOnce when disabling the spell checker

This commit is contained in:
Raphaël Jakse 2020-10-08 18:43:05 +02:00
parent 6fdfc05437
commit cdd2ca777a
1 changed files with 17 additions and 17 deletions

View File

@ -63,10 +63,12 @@
let type;
let value;
/* get default value from configuration */
if (Object.prototype.hasOwnProperty.call(Conf, key)) {
// get default value from configuration
value = Conf[key];
type = typeof value;
} else if (Object.prototype.hasOwnProperty.call(SettingsTypes, key)) {
type = SettingsTypes[key];
}
/* try to retrieve value from localstorage */
@ -75,11 +77,7 @@
/* get type from localStorage if no default is set */
if (typeof type === "undefined") {
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key + "_type")) {
type = localStorage.getItem("trivabble" + key + "_type");
} else {
type = "string";
}
type = "string";
}
/* cast from string to type */
@ -99,6 +97,10 @@
return value;
}
function unsetSetting(key) {
localStorage.removeItem("trivabble" + key);
}
function setSetting(key, value) {
if (getSetting(key) === value) {
return;
@ -113,13 +115,6 @@
type = typeof Conf[key];
}
/* try to retrieve type from localstorage */
if (typeof type === "undefined") {
if (Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key)) {
type = localStorage.getItem("trivabble" + key + "_type");
}
}
/* storage value in localstorage */
if (type === typeof value) {
if (type === "object") {
@ -1956,7 +1951,7 @@
if (tilesSound) {
/* migration of old settings for tiles sound */
const oldSetting = getSetting("trivabbleTilesSound");
const oldSetting = getSetting("TilesSound");
if (oldSetting) {
setSetting("ENABLE_TILE_SOUND", oldSetting === "true");
delete localStorage.trivabbleTilesSound;
@ -1972,7 +1967,7 @@
if (msgSound) {
/* migration of old settings for message sound */
const oldSetting = getSetting("trivabbleMsgSound");
const oldSetting = getSetting("MsgSound");
if (oldSetting) {
setSetting("ENABLE_MSG_SOUND", oldSetting === "true");
delete localStorage.trivabbleMsgSound;
@ -1989,9 +1984,14 @@
const disabled = !getSetting("ENABLE_SPELL_CHECKER") || document.getElementById("disable-spell-checker").checked;
document.getElementById("check-spelling").hidden = disabled;
document.getElementById("info-spell-checking").hidden = disabled;
if (e) {
setSetting("DisableSpellChecker", disabled);
}
if (disabled) {
unsetSetting("SpellCheckerEnabledOnce");
}
}
function initSpellChecker() {
@ -2143,7 +2143,7 @@
}
function langSelectionChange(e) {
setSetting("trivabbleLang", e.target.value);
setSetting("Lang", e.target.value);
location.reload();
}
@ -2292,7 +2292,7 @@
}
function initLang() {
const lang = libD.lang = getSetting("trivabbleLang") || libD.lang;
const lang = libD.lang = getSetting("Lang") || libD.lang;
const langSel = document.getElementById("select-lang");
langSel.value = lang;