correct setting functions
authorLaurent Mazet <mazet@softndesign.org>
Thu, 10 Sep 2020 06:03:45 +0000 (08:03 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 10 Sep 2020 06:03:45 +0000 (08:03 +0200)
public/trivabble.js

index f471e06904501fa43a9cb569d2ff169a89c61ad1..8979b391894fed1ac7da7d66c7578788ad1f024b 100644 (file)
     setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]);
     setConf("FLASH_LIGHT_COLOR", "#E3E");
 
+    function isSetting(key) {
+        return Object.prototype.hasOwnProperty.call(Conf, key) ||
+            Object.prototype.hasOwnProperty.call(localStorage, key);
+    }
+
     function getSetting(key) {
         let type = undefined;
-        let value;
+        let value = undefined;
 
         /* get default value from configuration */
         if (Object.prototype.hasOwnProperty.call(Conf, key)) {
         if (Object.prototype.hasOwnProperty.call(localStorage, key)) {
             value = localStorage.getItem(key);
 
-            /* get type from localStore if no default is set */
-            if (type === "undefined") {
-                type = localStorage.getItem(key + "_type");
+            /* get type from localStorage if no default is set */
+            if (type === undefined) {
+                if (Object.prototype.hasOwnProperty.call(localStorage, key + "_key")) {
+                    type = localStorage.getItem(key + "_type");
+                } else {
+                    type = "string";
+                }
             }
 
             /* cast from string to type */
 
         /* if not set type is defined from value */
         if (type === undefined) {
-            typeof value;
+            type = typeof value;
         }
 
         /* storage value in localstorage */