add default values for tiles and messages sound enablers
authorLaurent Mazet <mazet@softndesign.org>
Sun, 13 Sep 2020 20:37:33 +0000 (22:37 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sun, 13 Sep 2020 20:37:33 +0000 (22:37 +0200)
public/index.html
public/trivabble.js

index d97ccec761cb1b9595bac7a677f4c4e712be5220..dd9aec5fb2e7eaf75c123c14448d4f53b42cf937 100644 (file)
@@ -51,8 +51,8 @@
                     <span class="modal-button" id="btn-settings-close">&#215;</span>
                        </h2>
                 <div id="prefs">
-                    <p><label><input type="checkbox" id="tiles-sound" checked="checked" /><span data-l10n="text-content">Sound of the tiles</span></label></p>
-                    <p><label><input type="checkbox" id="msg-sound" checked="checked" /><span data-l10n="text-content">Sound of messages</span></label></p>
+                    <p><label><input type="checkbox" id="tiles-sound" /><span data-l10n="text-content">Sound of the tiles</span></label></p>
+                    <p><label><input type="checkbox" id="msg-sound" /><span data-l10n="text-content">Sound of messages</span></label></p>
                     <p id="enable-spell-checker-outer" style="display:none"><label><input type="checkbox" id="enable-spell-checker" /> <span data-l10n="text-content">Enable spell checker</span></label></p>
                            <p><label><span data-l10n="text-content">(fast)</span><input type="range" min="0" max="0" id="double-tap-duration"/><span data-l10n="text-content">(slow)</span><br/><span data-l10n="text-content">Double tap duration</span></label></p>
                            <p><label><span data-l10n="text-content">(fast)</span><input type="range" min="0" max="0" id="flash-light-duration"/><span data-l10n="text-content">(slow)</span><br/><span data-l10n="text-content">Flash light duration</span></label></p>
index dad11929d3ba6f2c8ee5d12ba354d5b07f510ef3..51ddbe4a4f12f7d06b3e01c31398391d6701ff20 100644 (file)
@@ -45,6 +45,8 @@
     setConf("ENABLE_EVENT_SOURCE",   true);
     setConf("MAX_WEBSOCKET_ERRORS",  1);
     setConf("APP_PATH",              "");
+    setConf("ENABLE_MSG_SOUND",      true);
+    setConf("ENABLE_TILE_SOUND",     true);
     setConf("ENABLE_SPELL_CHECKER",  false);
     setConf("DOUBLE_TAP_DURATIONS",  [650, 1100, 1800, 3000, 5000]);
     setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]);
         tile.lastChild.textContent = scoreOf[letter] || "";
         if (highlight) {
             tile.classList.add("tile-highlight");
-            if (tilesSound.checked) {
+            if (getSetting("ENABLE_TILE_SOUND")) {
                 audioNotification.play();
             }
         } else {
         chatMessages.scrollTop = chatMessages.scrollHeight;
 
         if (sender && sender !== getSetting("trivabblePlayerName")) {
-            if (msgSound.checked) {
+            if (getSetting("ENABLE_MSG_SOUND")) {
                 audioChat.play();
             }
 
 
     let audioTileLoaded = false;
     let audioMsgLoaded = false;
-    let tilesSound;
-    let msgSound;
 
     function loadAudio() {
-        if (!audioTileLoaded && tilesSound.checked) {
+        if (!audioTileLoaded && getSetting("ENABLE_TILE_SOUND")) {
             audioTileLoaded = true;
             audioNotification.load();
         }
 
-        if (!audioMsgLoaded  && msgSound.checked) {
+        if (!audioMsgLoaded  && getSetting("ENABLE_MSG_SOUND")) {
             audioMsgLoaded = true;
             audioChat.load();
         }
         audioChat.appendChild(audioSourceOGG);
         audioChat.appendChild(audioSourceMP3);
 
-
-        tilesSound = document.getElementById("tiles-sound");
-        msgSound = document.getElementById("msg-sound");
-
-        tilesSound.onclick = function () {
-            setSetting("trivabbleTileSound", tilesSound.checked);
-        };
-
-        msgSound.onclick = function () {
-            setSetting("trivabbleMsgSound", msgSound.checked);
-        };
-
-        if (isSetting("trivabbleMsgSound")) {
-            msgSound.checked = getSetting("trivabbleMsgSound");
-        } else {
-            setSetting("trivabbleMsgSound", msgSound.checked);
+        const tilesSound = document.getElementById("tiles-sound");
+        if (tilesSound) {
+            tilesSound.checked = getSetting("ENABLE_TILE_SOUND");
+            tilesSound.onclick = function () {
+                setSetting("ENABLE_TILE_SOUND", this.checked);
+            };
         }
 
-        if (isSetting("trivabbleTileSound")) {
-            tilesSound.checked = getSetting("trivabbleTileSound");
-        } else {
-            setSetting("trivabbleTilesSound", tilesSound.checked);
+        const msgSound = document.getElementById("msg-sound");
+        if (msgSound) {
+            msgSound.checked = getSetting("ENABLE_MSG_SOUND");
+            msgSound.onclick = function () {
+                setSetting("ENABLE_MSG_SOUND", this.checked);
+            };
         }
     }