lightweight, client-only calendar web application. All data persists in the URL hash for instant sharing, No backend required. Optional AES-GCM password protection keeps shared links locked without a server
JavaScript
feat(i18n): add Italian localization support and sync language keys
Supun Lakmal26012e014f35
diff --git a/index.html b/index.htmlindex b187d9c..c0bd635 100644--- a/index.html+++ b/index.html@@ -551,9 +551,23 @@<button id="mobile-theme-toggle" type="button" class="mobile-drawer-item"><i class="fa-solid fa-circle-half-stroke"></i> <span>Theme: Light</span></button>- <button id="mobile-language-btn" type="button" class="mobile-drawer-item">- <i class="fa-solid fa-language"></i> <span>English</span>- </button>+ <div class="mobile-drawer-item mobile-language-picker dropdown-container">+ <button id="mobile-language-btn" class="dropdown-trigger" type="button" aria-haspopup="listbox"+ aria-expanded="false"+ style="width: 100%; border: none; background: transparent; padding: 0; box-shadow: none; justify-content: space-between;">+ <div style="display: flex; align-items: center; gap: 10px;">+ <i class="fa-solid fa-language"></i>+ <span id="mobile-current-lang">English</span>+ </div>+ <i class="fa-solid fa-chevron-down"></i>+ </button>+ <div id="mobile-language-dropdown" class="dropdown-menu hidden"+ style="width: 100%; bottom: calc(100% + 5px); top: auto; right: 0;">+ <ul id="mobile-language-list" class="dropdown-list" role="listbox">+ <!-- Generated by JS -->+ </ul>+ </div>+ </div></div></div></aside>diff --git a/script.js b/script.jsindex c093562..f5d8d60 100644--- a/script.js+++ b/script.js@@ -322,27 +322,30 @@ function cacheElements() {ui.mobileAddEvent = document.getElementById("mobile-add-event");ui.mobileCopyLink = document.getElementById("mobile-copy-link");ui.mobileShareQr = document.getElementById("mobile-share-qr");- ui.mobileLockBtn = document.getElementById("mobile-lock-btn");- ui.mobileUnlockBtn = document.getElementById("mobile-unlock-btn");- ui.mobileFocusBtn = document.getElementById("mobile-focus-btn");- ui.mobileWorldPlannerBtn = document.getElementById("mobile-world-planner-btn");- ui.mobileEventList = document.getElementById("mobile-event-list");- ui.mobileSelectedDateLabel = document.getElementById("mobile-selected-date-label");- ui.mobileAddEventInline = document.getElementById("mobile-add-event-inline");- ui.mobileUrlLength = document.getElementById("mobile-url-length");- ui.mobileUrlWarning = document.getElementById("mobile-url-warning");- ui.mobileViewJson = document.getElementById("mobile-view-json");- ui.mobileExportJson = document.getElementById("mobile-export-json");- ui.mobileImportIcs = document.getElementById("mobile-import-ics");- ui.mobileClearAll = document.getElementById("mobile-clear-all");- ui.mobileTzList = document.getElementById("mobile-tz-list");- ui.mobileAddTzBtn = document.getElementById("mobile-add-tz-btn");- ui.mobileDrawerViewButtons = Array.from(- document.querySelectorAll(".mobile-drawer-view-toggle [data-view]")- );+ ui.mobileLockBtn = document.getElementById("mobile-lock-btn");+ ui.mobileUnlockBtn = document.getElementById("mobile-unlock-btn");+ ui.mobileFocusBtn = document.getElementById("mobile-focus-btn");+ ui.mobileWorldPlannerBtn = document.getElementById("mobile-world-planner-btn");+ ui.mobileEventList = document.getElementById("mobile-event-list");+ ui.mobileSelectedDateLabel = document.getElementById("mobile-selected-date-label");+ ui.mobileAddEventInline = document.getElementById("mobile-add-event-inline");+ ui.mobileUrlLength = document.getElementById("mobile-url-length");+ ui.mobileUrlWarning = document.getElementById("mobile-url-warning");+ ui.mobileViewJson = document.getElementById("mobile-view-json");+ ui.mobileExportJson = document.getElementById("mobile-export-json");+ ui.mobileImportIcs = document.getElementById("mobile-import-ics");+ ui.mobileClearAll = document.getElementById("mobile-clear-all");+ ui.mobileTzList = document.getElementById("mobile-tz-list");+ ui.mobileAddTzBtn = document.getElementById("mobile-add-tz-btn");+ ui.mobileDrawerViewButtons = Array.from(+ document.querySelectorAll(".mobile-drawer-view-toggle [data-view]")+ );ui.mobileWeekstartToggle = document.getElementById("mobile-weekstart-toggle");ui.mobileThemeToggle = document.getElementById("mobile-theme-toggle");- ui.mobileLanguageBtn = document.getElementById("mobile-language-btn");+ ui.mobileLangBtn = document.getElementById("mobile-language-btn");+ ui.mobileLangList = document.getElementById("mobile-language-list");+ ui.mobileCurrentLang = document.getElementById("mobile-current-lang");+ ui.mobileLangDropdown = document.getElementById("mobile-language-dropdown");// World Plannerui.worldPlannerBtn = document.getElementById("world-planner-btn");@@ -391,40 +394,40 @@ function createTzCard(zoneId, isLocal) {return div;}-function renderTimezones() {- const targets = [ui.tzList, ui.mobileTzList].filter(Boolean);- if (!targets.length) return;-- const localZone = getLocalZone();- const zones = Array.isArray(state.timezones) ? state.timezones : [];- const savedZones = [];- const seen = new Set();-- zones.forEach((zone) => {- if (zone === localZone) return;- if (seen.has(zone)) return;- if (!isValidZone(zone)) return;- seen.add(zone);- savedZones.push(zone);- });-- targets.forEach((target) => {- target.innerHTML = "";- target.appendChild(createTzCard(localZone, true));-- if (!savedZones.length) {- const empty = document.createElement("p");- empty.className = "tz-empty";- empty.textContent = t("tz.addToCompare");- target.appendChild(empty);- return;- }-- savedZones.forEach((zone) => {- target.appendChild(createTzCard(zone, false));- });- });-}+function renderTimezones() {+ const targets = [ui.tzList, ui.mobileTzList].filter(Boolean);+ if (!targets.length) return;++ const localZone = getLocalZone();+ const zones = Array.isArray(state.timezones) ? state.timezones : [];+ const savedZones = [];+ const seen = new Set();++ zones.forEach((zone) => {+ if (zone === localZone) return;+ if (seen.has(zone)) return;+ if (!isValidZone(zone)) return;+ seen.add(zone);+ savedZones.push(zone);+ });++ targets.forEach((target) => {+ target.innerHTML = "";+ target.appendChild(createTzCard(localZone, true));++ if (!savedZones.length) {+ const empty = document.createElement("p");+ empty.className = "tz-empty";+ empty.textContent = t("tz.addToCompare");+ target.appendChild(empty);+ return;+ }++ savedZones.forEach((zone) => {+ target.appendChild(createTzCard(zone, false));+ });+ });+}function addTimezone(zoneStr) {if (!zoneStr || !isValidZone(zoneStr)) return;@@ -652,14 +655,14 @@ function scheduleSave() {}, DEBOUNCE_MS);}-function updateUrlLength() {- const length = window.location.hash.length;- if (ui.urlLength) ui.urlLength.textContent = String(length);- if (ui.mobileUrlLength) ui.mobileUrlLength.textContent = String(length);- const warning = length > 2000 ? t("panel.urlWarning") : "";- if (ui.urlWarning) ui.urlWarning.textContent = warning;- if (ui.mobileUrlWarning) ui.mobileUrlWarning.textContent = warning;-}+function updateUrlLength() {+ const length = window.location.hash.length;+ if (ui.urlLength) ui.urlLength.textContent = String(length);+ if (ui.mobileUrlLength) ui.mobileUrlLength.textContent = String(length);+ const warning = length > 2000 ? t("panel.urlWarning") : "";+ if (ui.urlWarning) ui.urlWarning.textContent = warning;+ if (ui.mobileUrlWarning) ui.mobileUrlWarning.textContent = warning;+}function updateTheme() {document.body.dataset.theme = state.s.d ? "dark" : "light";@@ -756,13 +759,13 @@ function updateLockUI() {ui.lockBtn.textContent = t("btn.lock");}}- if (ui.lockedOverlay) {- ui.lockedOverlay.classList.toggle("hidden", !isLocked);- }- const disabled = isLocked;- [ui.addEventBtn, ui.addEventInline, ui.mobileAddEventInline, ui.copyLinkBtn, ui.shareQrBtn].forEach((btn) => {- if (btn) btn.disabled = disabled;- });+ if (ui.lockedOverlay) {+ ui.lockedOverlay.classList.toggle("hidden", !isLocked);+ }+ const disabled = isLocked;+ [ui.addEventBtn, ui.addEventInline, ui.mobileAddEventInline, ui.copyLinkBtn, ui.shareQrBtn].forEach((btn) => {+ if (btn) btn.disabled = disabled;+ });// Mobile lock/unlock button visibilityif (ui.mobileLockBtn && ui.mobileUnlockBtn) {@@ -783,69 +786,122 @@ function updateLockUI() {});}+function applyLanguageSelection(langCode) {+ if (!SUPPORTED_LANGUAGES.some((lang) => lang.code === langCode)) return;+ setLanguage(langCode);+ state.s.l = langCode;+ scheduleSave();+ updateLanguageUI();+}+function initLanguageDropdown() {if (!ui.langBtn || !ui.langList) return;- import("./modules/i18n.js").then(({ SUPPORTED_LANGUAGES }) => {- ui.langList.innerHTML = "";- SUPPORTED_LANGUAGES.forEach((lang) => {- const li = document.createElement("li");- li.className = "dropdown-item";- li.dataset.lang = lang.code;- li.innerHTML = `+ ui.langList.innerHTML = "";+ if (ui.mobileLangList) ui.mobileLangList.innerHTML = "";++ SUPPORTED_LANGUAGES.forEach((lang) => {+ // Desktop list item+ const li = document.createElement("li");+ li.className = "dropdown-item";+ li.dataset.lang = lang.code;+ li.innerHTML = `+ <span>${t(lang.nameKey)}</span>+ <i class="fa-solid fa-check check-icon"></i>+ `;+ li.addEventListener("click", () => {+ applyLanguageSelection(lang.code);+ closeLanguageDropdown(ui.langDropdown, ui.langBtn);+ });+ ui.langList.appendChild(li);++ // Mobile list item+ if (ui.mobileLangList) {+ const mobileLi = document.createElement("li");+ mobileLi.className = "dropdown-item";+ mobileLi.dataset.lang = lang.code;+ mobileLi.innerHTML = `<span>${t(lang.nameKey)}</span><i class="fa-solid fa-check check-icon"></i>`;- li.addEventListener("click", () => {- setLanguage(lang.code);- state.s.l = lang.code;- scheduleSave();- updateLanguageUI();- closeLanguageDropdown();+ mobileLi.addEventListener("click", () => {+ applyLanguageSelection(lang.code);+ closeLanguageDropdown(ui.mobileLangDropdown, ui.mobileLangBtn);});- ui.langList.appendChild(li);- });- updateLanguageUI();+ ui.mobileLangList.appendChild(mobileLi);+ }});- ui.langBtn.addEventListener("click", (e) => {- e.stopPropagation();- toggleLanguageDropdown();- });+ updateLanguageUI();++ if (ui.langBtn) {+ ui.langBtn.addEventListener("click", (e) => {+ e.stopPropagation();+ toggleLanguageDropdown(ui.langDropdown, ui.langBtn);+ });+ }++ if (ui.mobileLangBtn) {+ ui.mobileLangBtn.addEventListener("click", (e) => {+ e.stopPropagation();+ toggleLanguageDropdown(ui.mobileLangDropdown, ui.mobileLangBtn);+ });+ }document.addEventListener("click", (e) => {if (ui.langDropdown && !ui.langDropdown.classList.contains("hidden") && !ui.langDropdown.contains(e.target)) {- closeLanguageDropdown();+ closeLanguageDropdown(ui.langDropdown, ui.langBtn);+ }+ if (ui.mobileLangDropdown && !ui.mobileLangDropdown.classList.contains("hidden") && !ui.mobileLangDropdown.contains(e.target)) {+ closeLanguageDropdown(ui.mobileLangDropdown, ui.mobileLangBtn);}});}-function toggleLanguageDropdown() {- if (!ui.langDropdown) return;- const isHidden = ui.langDropdown.classList.contains("hidden");+function toggleLanguageDropdown(dropdown, trigger) {+ if (!dropdown || !trigger) return;+ const isHidden = dropdown.classList.contains("hidden");if (isHidden) {- ui.langDropdown.classList.remove("hidden");- ui.langBtn.setAttribute("aria-expanded", "true");+ // Close other dropdowns first+ closeLanguageDropdown(ui.langDropdown, ui.langBtn);+ closeLanguageDropdown(ui.mobileLangDropdown, ui.mobileLangBtn);++ dropdown.classList.remove("hidden");+ trigger.setAttribute("aria-expanded", "true");} else {- closeLanguageDropdown();+ closeLanguageDropdown(dropdown, trigger);}}-function closeLanguageDropdown() {- if (ui.langDropdown) {- ui.langDropdown.classList.add("hidden");- ui.langBtn.setAttribute("aria-expanded", "false");- }+function closeLanguageDropdown(dropdown, trigger) {+ const d = dropdown || ui.langDropdown;+ const t = trigger || ui.langBtn;+ if (d) d.classList.add("hidden");+ if (t) t.setAttribute("aria-expanded", "false");}function updateLanguageUI() {if (!ui.currentLang || !ui.langList) return;const langCode = getCurrentLanguage();- ui.currentLang.textContent = t(`lang.${langCode}`);++ if (ui.currentLang) {+ ui.currentLang.textContent = t(`lang.${langCode}`);+ }++ if (ui.mobileCurrentLang) {+ ui.mobileCurrentLang.textContent = t(`lang.${langCode}`);+ }++ if (ui.langList) {+ ui.langList.querySelectorAll(".dropdown-item").forEach((item) => {+ item.classList.toggle("active", item.dataset.lang === langCode);+ });+ }- if (ui.mobileLanguageBtn) {- const span = ui.mobileLanguageBtn.querySelector("span");- if (span) span.textContent = t(`lang.${langCode}`);+ if (ui.mobileLangList) {+ ui.mobileLangList.querySelectorAll(".dropdown-item").forEach((item) => {+ item.classList.toggle("active", item.dataset.lang === langCode);+ });}ui.langList.querySelectorAll(".dropdown-item").forEach((item) => {@@ -1009,19 +1065,19 @@ function render() {initCountdownWidget(state.e);}-function renderEventList() {- const key = formatDateKey(selectedDate);- const list = occurrencesByDay.get(key) || [];- const label = formatDateLabel(selectedDate);- const targets = [- [ui.selectedDateLabel, ui.eventList],- [ui.mobileSelectedDateLabel, ui.mobileEventList],- ];-- const createEventItem = (event) => {- const item = document.createElement("div");- item.className = "event-item";- item.dataset.index = String(event.sourceIndex);+function renderEventList() {+ const key = formatDateKey(selectedDate);+ const list = occurrencesByDay.get(key) || [];+ const label = formatDateLabel(selectedDate);+ const targets = [+ [ui.selectedDateLabel, ui.eventList],+ [ui.mobileSelectedDateLabel, ui.mobileEventList],+ ];++ const createEventItem = (event) => {+ const item = document.createElement("div");+ item.className = "event-item";+ item.dataset.index = String(event.sourceIndex);const left = document.createElement("div");left.className = "event-info";@@ -1037,31 +1093,31 @@ function renderEventList() {const dot = document.createElement("div");dot.className = "event-dot";dot.style.background = event.color;-- item.appendChild(left);- item.appendChild(dot);- item.addEventListener("click", () => openEventModal({ index: event.sourceIndex }));- return item;- };-- targets.forEach(([labelEl, listEl]) => {- if (!labelEl || !listEl) return;- labelEl.textContent = label;- listEl.innerHTML = "";-- if (!list.length) {- const empty = document.createElement("div");- empty.className = "event-item";- empty.textContent = t("calendar.noEvents");- listEl.appendChild(empty);- return;- }-- list.forEach((event) => {- listEl.appendChild(createEventItem(event));- });- });-}++ item.appendChild(left);+ item.appendChild(dot);+ item.addEventListener("click", () => openEventModal({ index: event.sourceIndex }));+ return item;+ };++ targets.forEach(([labelEl, listEl]) => {+ if (!labelEl || !listEl) return;+ labelEl.textContent = label;+ listEl.innerHTML = "";++ if (!list.length) {+ const empty = document.createElement("div");+ empty.className = "event-item";+ empty.textContent = t("calendar.noEvents");+ listEl.appendChild(empty);+ return;+ }++ list.forEach((event) => {+ listEl.appendChild(createEventItem(event));+ });+ });+}function handleSelectDay(date) {selectedDate = startOfDay(date);@@ -1085,18 +1141,18 @@ function openEventModal({ index = null, date = null } = {}) {if (!ui.eventModal) return;editingIndex = index;const isEditing = typeof index === "number";- ui.eventModalTitle.textContent = t(isEditing ? "modal.editEvent" : "modal.addEvent");- ui.eventDelete.classList.toggle("hidden", !isEditing);-- const baseDate = date || selectedDate;- const now = new Date();- let startDate = new Date(- baseDate.getFullYear(),- baseDate.getMonth(),- baseDate.getDate(),- now.getHours(),- now.getMinutes(),- );+ ui.eventModalTitle.textContent = t(isEditing ? "modal.editEvent" : "modal.addEvent");+ ui.eventDelete.classList.toggle("hidden", !isEditing);++ const baseDate = date || selectedDate;+ const now = new Date();+ let startDate = new Date(+ baseDate.getFullYear(),+ baseDate.getMonth(),+ baseDate.getDate(),+ now.getHours(),+ now.getMinutes(),+ );let duration = 60;let title = "";let color = state.c[0] || DEFAULT_COLORS[0];@@ -1594,12 +1650,12 @@ function bindEvents() {if (ui.tzAddBtn) ui.tzAddBtn.addEventListener("click", openTzModal);if (ui.tzClose) ui.tzClose.addEventListener("click", closeTzModal);if (ui.tzSearch) ui.tzSearch.addEventListener("input", handleTzSearch);- if (ui.tzResults) ui.tzResults.addEventListener("click", handleTzResultsClick);- if (ui.tzList) ui.tzList.addEventListener("click", handleTzListClick);- if (ui.mobileTzList) ui.mobileTzList.addEventListener("click", handleTzListClick);- if (ui.tzModal) {- ui.tzModal.addEventListener("click", (event) => {- if (event.target === ui.tzModal) closeTzModal();+ if (ui.tzResults) ui.tzResults.addEventListener("click", handleTzResultsClick);+ if (ui.tzList) ui.tzList.addEventListener("click", handleTzListClick);+ if (ui.mobileTzList) ui.mobileTzList.addEventListener("click", handleTzListClick);+ if (ui.tzModal) {+ ui.tzModal.addEventListener("click", (event) => {+ if (event.target === ui.tzModal) closeTzModal();});}@@ -1642,47 +1698,47 @@ function initResponsiveFeatures() {// Quick-action buttons delegate to existing handlersif (ui.mobileAddEvent) ui.mobileAddEvent.addEventListener("click", () => openEventModal({ date: selectedDate }));- if (ui.mobileCopyLink) ui.mobileCopyLink.addEventListener("click", handleCopyLink);- if (ui.mobileShareQr) ui.mobileShareQr.addEventListener("click", handleShareQr);- if (ui.mobileLockBtn) ui.mobileLockBtn.addEventListener("click", handleLockAction);- if (ui.mobileUnlockBtn) ui.mobileUnlockBtn.addEventListener("click", handleLockAction);- if (ui.mobileFocusBtn) ui.mobileFocusBtn.addEventListener("click", handleFocusToggle);- if (ui.mobileAddEventInline) {- ui.mobileAddEventInline.addEventListener("click", () => {- closeMobileDrawer();- openEventModal({ date: selectedDate });- });- }- if (ui.mobileViewJson) {- ui.mobileViewJson.addEventListener("click", () => {- closeMobileDrawer();- openJsonModal();- });- }- if (ui.mobileExportJson) {- ui.mobileExportJson.addEventListener("click", () => {- closeMobileDrawer();- handleExportJson();- });- }- if (ui.mobileImportIcs) {- ui.mobileImportIcs.addEventListener("click", () => {- closeMobileDrawer();- handleImportIcsClick();- });- }- if (ui.mobileClearAll) {- ui.mobileClearAll.addEventListener("click", () => {- closeMobileDrawer();- handleClearAll();- });- }- if (ui.mobileAddTzBtn) {- ui.mobileAddTzBtn.addEventListener("click", () => {- closeMobileDrawer();- openTzModal();- });- }+ if (ui.mobileCopyLink) ui.mobileCopyLink.addEventListener("click", handleCopyLink);+ if (ui.mobileShareQr) ui.mobileShareQr.addEventListener("click", handleShareQr);+ if (ui.mobileLockBtn) ui.mobileLockBtn.addEventListener("click", handleLockAction);+ if (ui.mobileUnlockBtn) ui.mobileUnlockBtn.addEventListener("click", handleLockAction);+ if (ui.mobileFocusBtn) ui.mobileFocusBtn.addEventListener("click", handleFocusToggle);+ if (ui.mobileAddEventInline) {+ ui.mobileAddEventInline.addEventListener("click", () => {+ closeMobileDrawer();+ openEventModal({ date: selectedDate });+ });+ }+ if (ui.mobileViewJson) {+ ui.mobileViewJson.addEventListener("click", () => {+ closeMobileDrawer();+ openJsonModal();+ });+ }+ if (ui.mobileExportJson) {+ ui.mobileExportJson.addEventListener("click", () => {+ closeMobileDrawer();+ handleExportJson();+ });+ }+ if (ui.mobileImportIcs) {+ ui.mobileImportIcs.addEventListener("click", () => {+ closeMobileDrawer();+ handleImportIcsClick();+ });+ }+ if (ui.mobileClearAll) {+ ui.mobileClearAll.addEventListener("click", () => {+ closeMobileDrawer();+ handleClearAll();+ });+ }+ if (ui.mobileAddTzBtn) {+ ui.mobileAddTzBtn.addEventListener("click", () => {+ closeMobileDrawer();+ openTzModal();+ });+ }// Drawer view buttonsif (ui.mobileDrawerViewButtons && ui.mobileDrawerViewButtons.length) {@@ -1701,21 +1757,10 @@ function initResponsiveFeatures() {if (ui.mobileThemeToggle) {ui.mobileThemeToggle.addEventListener("click", handleThemeToggle);}- if (ui.mobileLanguageBtn) {- ui.mobileLanguageBtn.addEventListener("click", () => {- const codes = SUPPORTED_LANGUAGES.map((lang) => lang.code);- const currentIndex = codes.indexOf(getCurrentLanguage());- const nextIndex = (currentIndex + 1) % codes.length;- setLanguage(codes[nextIndex]);- state.s.l = codes[nextIndex];- scheduleSave();- updateLanguageUI();- });- }- // Drawer world planner button- if (ui.mobileWorldPlannerBtn) {- ui.mobileWorldPlannerBtn.addEventListener("click", () => {+ // Drawer world planner button+ if (ui.mobileWorldPlannerBtn) {+ ui.mobileWorldPlannerBtn.addEventListener("click", () => {closeMobileDrawer();if (ui.worldPlannerBtn) ui.worldPlannerBtn.click();});diff --git a/styles.css b/styles.cssindex fdfdd08..8e1869c 100644--- a/styles.css+++ b/styles.css@@ -2504,6 +2504,22 @@ body[data-theme="dark"] .ripple {border-color: var(--accent);}+.mobile-language-select {+ flex: 1;+ min-width: 0;+ border: none;+ background: transparent;+ color: inherit;+ font: inherit;+ margin: 0;+ padding: 0;+ cursor: pointer;+}++.mobile-language-select:focus {+ outline: none;+}+/* Constrain embedded lists in mobile drawer */#mobile-event-list {max-height: 200px;