Add hex color input

This commit is contained in:
rajchales-monito
2026-07-24 13:51:11 +02:00
parent 8f5779133f
commit 8178b4a4e7
3 changed files with 32 additions and 3 deletions
+13
View File
@@ -166,6 +166,19 @@ label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.setting-switch input:checked { background: var(--brand); } .setting-switch input:checked { background: var(--brand); }
.setting-switch input:checked:before { transform: translateX(18px); } .setting-switch input:checked:before { transform: translateX(18px); }
.color-field input { margin-top: 2px; } .color-field input { margin-top: 2px; }
.color-row {
display: grid;
grid-template-columns: 58px minmax(0, 1fr);
gap: 8px;
align-items: center;
}
.color-row input[type="color"] {
width: 58px;
}
.hex-input {
font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
text-transform: lowercase;
}
.list-tools { .list-tools {
padding: 10px 14px; padding: 10px 14px;
border-bottom: 1px solid var(--line); border-bottom: 1px solid var(--line);
+3
View File
@@ -99,7 +99,10 @@
<label>Titulek EN <input name="titleEn"></label> <label>Titulek EN <input name="titleEn"></label>
<label>Intro EN <textarea name="introEn" rows="2"></textarea></label> <label>Intro EN <textarea name="introEn" rows="2"></textarea></label>
<label class="color-field">Barva <label class="color-field">Barva
<span class="color-row">
<input name="brand" type="color"> <input name="brand" type="color">
<input name="brandHex" class="hex-input" type="text" inputmode="text" maxlength="7" placeholder="#0f8f6f" pattern="#?[0-9a-fA-F]{6}">
</span>
</label> </label>
<label>Pozice desktop <select name="desktopSide"><option>right</option><option>left</option></select></label> <label>Pozice desktop <select name="desktopSide"><option>right</option><option>left</option></select></label>
<label>Desktop bottom px <input name="desktopBottom" type="number"></label> <label>Desktop bottom px <input name="desktopBottom" type="number"></label>
+15 -2
View File
@@ -47,6 +47,13 @@ $("#logoutButton").addEventListener("click", async () => {
$("#settingsButton").addEventListener("click", () => $("#settingsPanel").classList.remove("hidden")); $("#settingsButton").addEventListener("click", () => $("#settingsPanel").classList.remove("hidden"));
$("#closeSettingsButton").addEventListener("click", () => $("#settingsPanel").classList.add("hidden")); $("#closeSettingsButton").addEventListener("click", () => $("#settingsPanel").classList.add("hidden"));
$("#settingsForm").brand.addEventListener("input", (event) => {
$("#settingsForm").brandHex.value = normalizeHexColor(event.target.value) || event.target.value;
});
$("#settingsForm").brandHex.addEventListener("input", (event) => {
const color = normalizeHexColor(event.target.value);
if (color) $("#settingsForm").brand.value = color;
});
window.addEventListener("focus", stopAttention); window.addEventListener("focus", stopAttention);
document.addEventListener("visibilitychange", () => { document.addEventListener("visibilitychange", () => {
@@ -65,7 +72,7 @@ $("#settingsForm").addEventListener("submit", async (event) => {
settings.intro.cs = form.get("introCs"); settings.intro.cs = form.get("introCs");
settings.title.en = form.get("titleEn"); settings.title.en = form.get("titleEn");
settings.intro.en = form.get("introEn"); settings.intro.en = form.get("introEn");
settings.colors.brand = form.get("brand"); settings.colors.brand = normalizeHexColor(form.get("brandHex")) || form.get("brand");
settings.desktop.side = form.get("desktopSide"); settings.desktop.side = form.get("desktopSide");
settings.desktop.bottomPx = Number(form.get("desktopBottom")); settings.desktop.bottomPx = Number(form.get("desktopBottom"));
settings.desktop.sideOffsetPx = Number(form.get("desktopOffset")); settings.desktop.sideOffsetPx = Number(form.get("desktopOffset"));
@@ -309,7 +316,8 @@ function renderSite() {
form.introCs.value = s.intro.cs || ""; form.introCs.value = s.intro.cs || "";
form.titleEn.value = s.title.en || ""; form.titleEn.value = s.title.en || "";
form.introEn.value = s.intro.en || ""; form.introEn.value = s.intro.en || "";
form.brand.value = s.colors.brand || "#0f8f6f"; form.brand.value = normalizeHexColor(s.colors.brand) || "#0f8f6f";
form.brandHex.value = form.brand.value;
form.desktopSide.value = s.desktop.side || "right"; form.desktopSide.value = s.desktop.side || "right";
form.desktopBottom.value = s.desktop.bottomPx || 22; form.desktopBottom.value = s.desktop.bottomPx || 22;
form.desktopOffset.value = s.desktop.sideOffsetPx || 22; form.desktopOffset.value = s.desktop.sideOffsetPx || 22;
@@ -829,6 +837,11 @@ function escapeHtml(value) {
})[char]); })[char]);
} }
function normalizeHexColor(value) {
const match = String(value || "").trim().match(/^#?([0-9a-fA-F]{6})$/);
return match ? `#${match[1].toLowerCase()}` : "";
}
function flag(countryCode) { function flag(countryCode) {
if (!countryCode || countryCode.length !== 2) return ""; if (!countryCode || countryCode.length !== 2) return "";
return countryCode.toUpperCase().replace(/./g, (char) => String.fromCodePoint(127397 + char.charCodeAt())); return countryCode.toUpperCase().replace(/./g, (char) => String.fromCodePoint(127397 + char.charCodeAt()));