avoid display spell checker if there is no dictionary
authorLaurent Mazet <mazet@softndesign.org>
Fri, 16 Oct 2020 06:05:51 +0000 (08:05 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 16 Oct 2020 06:05:51 +0000 (08:05 +0200)
dict-dists-extractor/Makefile
public/index.html
public/trivabble.js

index 938ffbbdbeb721b7af31c7ebe01352818824a31c..c49428329ea631eba141a59b7fb13903557336f2 100644 (file)
@@ -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 - | \
index 165cc22c20b1d8fde6adefa70422355ff5ee75e2..c56bccf656a3a4db95f57c4fd62cb29c72e7aade 100644 (file)
@@ -9,6 +9,7 @@
         <meta name="apple-mobile-web-app-capable" content="yes" />
         <meta name="format-detection" content="telephone=no" />
         <script src="config.js"></script>
+        <script src="dict/list.js"></script>
         <script src="l10n.js"></script>
         <script src="alert.js"></script>
         <script src="touch2click.js"></script>
index 08b6dbff68c37a3804f1461062ddccd3fb8ace86..f5da04db5b31f04782185b1f7df227545501439d 100644 (file)
@@ -31,6 +31,8 @@
 
     const Conf = window.TrivabbleConf || {};
 
+    const DictionaryList = window.DictionaryList || {};
+
     function setConf(parameterName, defaultValue) {
         if (typeof Conf[parameterName] === "undefined") {
             Conf[parameterName] = defaultValue;
         }
     }
 
+    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) {
             case "boardLang":
                 document.getElementById("board-lang").value = value;
                 setSetting("BoardLang", value);
+                checkDictionaryExistance(value);
                 break;
         }
     }
 
     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);