New option for caption
authorLaurent Mazet <mazet@softndesign.org>
Wed, 23 Dec 2020 20:52:09 +0000 (21:52 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 23 Dec 2020 20:52:09 +0000 (21:52 +0100)
public/index.html
public/trivabble.css
public/trivabble.js

index 8d046a01c185b685d8406879e38ff1149f2dabab..ed592cf0ea8c7710032c23ded9b34af7a3a1115e 100644 (file)
                         </label>
                     </p>
                 </div>
+                    <p id="cell-captions-p">
+                        <label>
+                            <span data-l10n="text-content">Cell captions</span>
+                            <select id="cell-captions">
+                                <option value="clip">Clip when overflows</option>
+                                <option value="dots">Dots when overflows</option>
+                                <option value="none">No caption</option>
+                                <option value="short">Short caption</option>
+                            </select>
+                        </label>
+                    </p>
+                <div>
             </div>
         </section>
 
index 85127fdd9b74120d4d11c1d93fbb3c40c219ca95..ce40519be8074f77e97735400fcd8de121f7962c 100644 (file)
@@ -122,10 +122,25 @@ html, #board, [draggable], .tile {
     display:inline-block;
     white-space:pre-wrap;
     font-size:7px;
-    text-overflow:ellipsis;
     overflow:hidden;
 }
 
+.special-cell-label-clip {
+    text-overflow:clip;
+}
+
+.special-cell-label-dots {
+    text-overflow:ellipsis;
+}
+
+.special-cell-label-none {
+    visibility:hidden;
+}
+
+.special-cell-label-short {
+    display:inline;
+}
+
 #center-cell .special-cell-label {
     font-weight:bold;
     color:black;
index 717ebd8c7f69519d3288c9476454f893ca761ab1..4e7a3b260961b4bc513b6e72128f7254317d2de9 100644 (file)
@@ -63,6 +63,7 @@
     setConf("PREMIUM_SEVEN_TILES",   50);
     setConf("SCORE_LAST_PLAYER",     true);
     setConf("ENABLE_TIMER",          false);
+    setConf("CELL_CAPTIONS",         "dots"); // "clip", "dots", "none", "short"
 
     function isSetting(key) {
         return Object.prototype.hasOwnProperty.call(Conf, key) ||
         Timer: "number",
         TimerEnable: "boolean",
         TimerGameDate: "number",
-        TimerTurnDate: "number"
+        TimerTurnDate: "number",
+        CellCaptions: "string"
     };
 
     const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {
     }
 
     const specialTypesText = {
-        doubleLetter: _("Double\nLetter"),
-        doubleWord:   _("Double\nWord"),
-        tripleLetter: _("Triple\nLetter"),
-        tripleWord:   _("Triple\nWord")
+        doubleLetter: "Double\nLetter",
+        doubleWord:   "Double\nWord",
+        tripleLetter: "Triple\nLetter",
+        tripleWord:   "Triple\nWord"
+    };
+
+    const specialTypesShortText = {
+        doubleLetter: "DL",
+        doubleWord:   "DW",
+        tripleLetter: "TL",
+        tripleWord:   "TW"
     };
 
     function specialCell(type, cell) {
         cell.firstChild.appendChild(document.createElement("span"));
         cell.classList.add("special-cell");
         cell.classList.add("special-cell-" + type);
-        cell.lastChild.lastChild.textContent = cell.title =  _(specialTypesText[type]);
+        cell.lastChild.lastChild.longText = cell.title = _(specialTypesText[type]);
+        cell.lastChild.lastChild.shortText = _(specialTypesShortText[type]);
         cell.lastChild.lastChild.className = "special-cell-label";
     }
 
         }
     }
 
+    function initCellCaptions() {
+        document.getElementById("cell-captions").onclick = function () {
+            setCellCaptions(document.getElementById("cell-captions").value);
+        };
+
+        setCellCaptions(getSetting("CellCaptions", getSetting("CELL_CAPTIONS")));
+    }
+
+    function setCellCaptions(mode) {
+        setSetting("CellCaptions", mode);
+        document.getElementById("cell-captions").value = mode;
+
+        for (const cells of [].slice.call(document.getElementsByClassName("special-cell-label"))) {
+            cells.classList.remove("special-cell-label-clip");
+            cells.classList.remove("special-cell-label-dots");
+            cells.classList.remove("special-cell-label-none");
+            cells.classList.remove("special-cell-label-short");
+
+            cells.classList.add("special-cell-label-" + mode);
+
+            cells.innerHTML = (mode === "short") ? cells.shortText : cells.longText;
+        }
+    }
+
     function repromptName(f) {
         if (getSetting("PlayerName") && getSetting("PlayerName").trim()) {
             f();
         initFlashLight();
         nextHelpMessage();
         initTimer();
+        initCellCaptions();
     };
 
     trivabble.l10nError = trivabble.run;