From: Laurent Mazet Date: Fri, 16 Oct 2020 06:05:51 +0000 (+0200) Subject: avoid display spell checker if there is no dictionary X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=356a2ef7d87b47702e07a90263bec2553ad006a2;p=trivabble.git avoid display spell checker if there is no dictionary --- diff --git a/dict-dists-extractor/Makefile b/dict-dists-extractor/Makefile index 938ffbb..c494283 100644 --- a/dict-dists-extractor/Makefile +++ b/dict-dists-extractor/Makefile @@ -24,13 +24,14 @@ LOWS = $(addsuffix .low,$(LANGS)) DICTS = $(addsuffix .dict,$(LANGS)) -DEPEND = Makefile +#DEPEND = Makefile #MAKEFLAGS = -s -.PHONY: all required count clean low +.PHONY: all required count clean low list all: required make $(addprefix check-,$(LANGS)) + make list $(ROOT_DICT): mkdir $(ROOT_DICT) @@ -45,6 +46,15 @@ low: $(LOWS) required: ${OBJ_DIR} ${OBJ_DIR}/src.mk ${ROOT_DICT} +list: $(ROOT_DICT)/list.js + +$(ROOT_DICT)/list.js: $(wildcard $(ROOT_DICT)/*.dict) + ls -s ${ROOT_DICT}/*.dict| \ + awk 'BEGIN { printf "window.DictionaryList = {\n" } \ + { $$0 = gensub(/(.+) .*\/(.+)\.dict/, "\\1 \\2", "g"); \ + printf "\"%s\": %d,\n", $$2, $$1 } \ + END { printf "\"none\": 0\n};" }' > $@ + $(OBJ_DIR)/src.mk: echo Creation language table wget $(ASPDICT) -q -O - | \ diff --git a/public/index.html b/public/index.html index 165cc22..c56bccf 100644 --- a/public/index.html +++ b/public/index.html @@ -9,6 +9,7 @@ + diff --git a/public/trivabble.js b/public/trivabble.js index 08b6dbf..f5da04d 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -31,6 +31,8 @@ const Conf = window.TrivabbleConf || {}; + const DictionaryList = window.DictionaryList || {}; + function setConf(parameterName, defaultValue) { if (typeof Conf[parameterName] === "undefined") { Conf[parameterName] = defaultValue; @@ -247,6 +249,18 @@ } } + function checkDictionaryExistance() { + const code = document.getElementById("board-lang").value; + + if (DictionaryList.hasOwnProperty(code) && getSetting("ENABLE_SPELL_CHECKER") && !document.getElementById("disable-spell-checker").checked) { + document.getElementById("check-spelling").hidden = false; + document.getElementById("info-spell-checking").hidden = false; + } else { + document.getElementById("check-spelling").hidden = true; + document.getElementById("info-spell-checking").hidden = true; + } + } + function getDictionary(code, callback, force) { if (downloadedDictionaries[code]) { if (downloadedDictionaries[code].length) { @@ -730,6 +744,7 @@ case "boardLang": document.getElementById("board-lang").value = value; setSetting("BoardLang", value); + checkDictionaryExistance(value); break; } } @@ -1981,8 +1996,7 @@ function toggleSpellChecker(e) { 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; + checkDictionaryExistance(); if (e) { setSetting("DisableSpellChecker", disabled);