Skip to content

Commit a2e058b

Browse files
committed
Fixes #356
1 parent 8b4f7c0 commit a2e058b

File tree

3 files changed

+188
-123
lines changed

3 files changed

+188
-123
lines changed

internal/frontend/lobby.js

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,6 @@ function hideMenu() {
9292
menu.hidePopover();
9393
}
9494

95-
// Since chromes implementation of the popup is dumb, we can't position
96-
// it correctly without javascript.
97-
if (!navigator.userAgent.toLowerCase().includes("firefox")) {
98-
const menu_button = document.getElementById("menu-button");
99-
menu.addEventListener("toggle", (event) => {
100-
if (event.newState === "open") {
101-
const bounds = menu_button.getBoundingClientRect();
102-
// Technically this won't correctly handle the scrolling
103-
// position, but we'll cope for now.
104-
menu.style.top = bounds.bottom + "px";
105-
menu.style.left = bounds.left + "px";
106-
}
107-
});
108-
}
109-
11095
function showDialog(id, title, contentNode, buttonBar) {
11196
hideMenu();
11297

@@ -999,21 +984,23 @@ const handleEvent = (parsed) => {
999984

1000985
// We don't do this in applyWordHints because that's called in all kinds of places
1001986
if (parsed.data.some((hint) => hint.character)) {
1002-
var hints = parsed.data.map((hint) => {
1003-
if (hint.character) {
1004-
var char = String.fromCharCode(hint.character);
1005-
if (char === " " || hint.revealed) {
1006-
return char;
1007-
}
1008-
}
1009-
return "_";
1010-
}).join(" ");
1011-
appendMessage(
1012-
["system-message", "hint-chat-message"],
1013-
'{{.Translation.Get "system"}}',
1014-
'{{.Translation.Get "word-hint-revealed"}}\n' + hints,
1015-
{ "dir": wordContainer.getAttribute("dir") },
1016-
);
987+
var hints = parsed.data
988+
.map((hint) => {
989+
if (hint.character) {
990+
var char = String.fromCharCode(hint.character);
991+
if (char === " " || hint.revealed) {
992+
return char;
993+
}
994+
}
995+
return "_";
996+
})
997+
.join(" ");
998+
appendMessage(
999+
["system-message", "hint-chat-message"],
1000+
'{{.Translation.Get "system"}}',
1001+
'{{.Translation.Get "word-hint-revealed"}}\n' + hints,
1002+
{ dir: wordContainer.getAttribute("dir") },
1003+
);
10171004
}
10181005
} else if (parsed.type === "message") {
10191006
appendMessage(null, parsed.data.author, parsed.data.content);
@@ -1409,11 +1396,11 @@ function appendMessage(styleClass, author, message, attrs) {
14091396
const newMessageDiv = document.createElement("div");
14101397
newMessageDiv.classList.add("message");
14111398
if (isString(styleClass)) {
1412-
styleClass = [styleClass];
1399+
styleClass = [styleClass];
14131400
}
14141401

1415-
for (const cls of styleClass){
1416-
newMessageDiv.classList.add(cls);
1402+
for (const cls of styleClass) {
1403+
newMessageDiv.classList.add(cls);
14171404
}
14181405

14191406
if (author !== null && author !== "") {
@@ -1429,11 +1416,11 @@ function appendMessage(styleClass, author, message, attrs) {
14291416
newMessageDiv.appendChild(messageSpan);
14301417

14311418
if (attrs !== null && attrs !== "") {
1432-
if (isObject(attrs)) {
1433-
for (const [attrKey, attrValue] of Object.entries(attrs)) {
1434-
messageSpan.setAttribute(attrKey, attrValue);
1419+
if (isObject(attrs)) {
1420+
for (const [attrKey, attrValue] of Object.entries(attrs)) {
1421+
messageSpan.setAttribute(attrKey, attrValue);
1422+
}
14351423
}
1436-
}
14371424
}
14381425

14391426
messageContainer.appendChild(newMessageDiv);
@@ -1608,17 +1595,16 @@ function updateRoundsDisplay() {
16081595
const applyWordHints = (wordHints, dummy) => {
16091596
const isDrawer = drawerID === ownID;
16101597

1611-
// We abuse the container to prevent the layout from jumping.
1612-
if (!dummy) {
1613-
wordContainer.style.visibility = "visible";
1614-
} else {
1615-
wordContainer.style.visibility = "hidden";
1616-
}
1598+
let wordLengths = [];
1599+
let count = 0;
16171600

16181601
wordContainer.replaceChildren(
1619-
...wordHints.map((hint) => {
1602+
...wordHints.map((hint, index) => {
16201603
const hintSpan = document.createElement("span");
16211604
hintSpan.classList.add("hint");
1605+
if (dummy) {
1606+
hintSpan.style.visibility = "hidden";
1607+
}
16221608
if (hint.character === 0) {
16231609
hintSpan.classList.add("hint-underline");
16241610
hintSpan.innerHTML = " ";
@@ -1629,13 +1615,33 @@ const applyWordHints = (wordHints, dummy) => {
16291615
hintSpan.innerText = String.fromCharCode(hint.character);
16301616
}
16311617

1618+
// space
1619+
if (hint.character === 32) {
1620+
wordLengths.push(count);
1621+
count = 0;
1622+
} else if (index === wordHints.length - 1) {
1623+
count += 1;
1624+
wordLengths.push(count);
1625+
} else {
1626+
count += 1;
1627+
}
1628+
16321629
if (hint.revealed && isDrawer) {
16331630
hintSpan.classList.add("hint-revealed");
16341631
}
16351632

16361633
return hintSpan;
16371634
}),
16381635
);
1636+
1637+
const lengthHint = document.createElement("sub");
1638+
lengthHint.classList.add("word-length-hint");
1639+
if (dummy) {
1640+
lengthHint.style.visibility = "hidden";
1641+
}
1642+
lengthHint.setAttribute("dir", wordContainer.getAttribute("dir"));
1643+
lengthHint.innerText = `(${wordLengths.join(", ")})`;
1644+
wordContainer.appendChild(lengthHint);
16391645
};
16401646

16411647
const set_dummy_word_hints = () => {
@@ -2027,14 +2033,16 @@ function getCookie(name) {
20272033
}
20282034

20292035
function isString(obj) {
2030-
return typeof obj === 'string';
2036+
return typeof obj === "string";
20312037
}
20322038

20332039
function isObject(obj) {
2034-
return typeof obj === 'object' &&
2035-
obj !== null &&
2036-
!Array.isArray(obj) &&
2037-
Object.prototype.toString.call(obj) === '[object Object]';
2040+
return (
2041+
typeof obj === "object" &&
2042+
obj !== null &&
2043+
!Array.isArray(obj) &&
2044+
Object.prototype.toString.call(obj) === "[object Object]"
2045+
);
20382046
}
20392047

20402048
const connectToWebsocket = () => {

internal/frontend/resources/lobby.css

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ kbd {
114114
grid-gap: 5px;
115115
}
116116

117-
#lobby-header > * {
117+
#lobby-header > *,
118+
#menu-button-container {
118119
background-color: white;
119120
height: 100%;
120121
align-items: center;
@@ -125,6 +126,7 @@ kbd {
125126

126127
#lobby-header-center-element {
127128
display: flex;
129+
justify-content: center;
128130
/* Hack to remove extra space between buttons */
129131
font-size: 0;
130132
}
@@ -160,6 +162,12 @@ kbd {
160162
overflow-x: hidden;
161163
}
162164

165+
.word-length-hint {
166+
font-family: monospace;
167+
font-size: 0.8rem;
168+
padding-top: 0.4rem;
169+
}
170+
163171
.hint-chat-message {
164172
white-space: pre;
165173
text-wrap-mode: wrap;
@@ -668,11 +676,50 @@ kbd {
668676
}
669677

670678
#lobby-header {
671-
grid-template-columns: max-content auto max-content;
672-
673-
grid-column-start: 1;
679+
background-color: transparent;
680+
display: grid;
674681
grid-column-end: 3;
682+
grid-column-start: 1;
683+
grid-gap: 5px;
675684
grid-row: 1;
685+
grid-template-columns: 1fr auto 1fr;
686+
grid-template-rows: auto auto;
687+
}
688+
689+
#lobby-header-center-element {
690+
display: contents;
691+
}
692+
693+
#menu-button-container {
694+
grid-column: 2;
695+
grid-row: 1;
696+
display: flex;
697+
justify-content: center;
698+
}
699+
700+
#round-container {
701+
grid-column: 1;
702+
grid-row: 1;
703+
justify-content: flex-start;
704+
}
705+
706+
#time-left {
707+
grid-column: 3;
708+
grid-row: 1;
709+
justify-content: flex-end;
710+
}
711+
712+
#word-container {
713+
grid-column: 1 / 4;
714+
grid-row: 2;
715+
background-color: white;
716+
align-items: center;
717+
padding: 0.1rem 0.2rem;
718+
border-radius: var(--component-border-radius);
719+
column-gap: 0.2rem;
720+
width: auto;
721+
min-width: 0;
722+
overflow: visible;
676723
}
677724

678725
#round-container,
@@ -727,9 +774,21 @@ kbd {
727774
}
728775
}
729776

777+
#menu-button-container {
778+
position: relative;
779+
}
780+
781+
#menu-button {
782+
anchor-name: menu-anchor;
783+
}
784+
730785
#menu {
731-
position: absolute;
732-
inset: unset;
786+
position-anchor: menu-anchor;
787+
position-area: bottom span-right;
788+
position-try-fallbacks: flip-block, flip-inline;
789+
790+
margin: 0;
791+
inset: auto;
733792
border: 1px solid gray;
734793
border-radius: var(--component-border-radius);
735794
}

0 commit comments

Comments
 (0)