Skip to content

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

add Gallery

Supun Lakmalf121261cb453
diff --git a/index.html b/index.html
index 4518fb4..7c34cea 100644
--- a/index.html
+++ b/index.html
@@ -246,6 +246,7 @@
<button id="view-json" type="button" class="ghost" data-i18n="btn.viewJson">View JSON</button>
<button id="export-json" type="button" class="ghost" data-i18n="btn.exportJson">Export JSON</button>
<button id="import-ics" type="button" class="ghost" data-i18n="btn.importIcs">Import .ics</button>
+ <button id="open-template-gallery" type="button" class="ghost" data-i18n="btn.templateGallery">Template gallery</button>
<input id="ics-input" type="file" accept=".ics,text/calendar" hidden>
</div>
</div>
@@ -426,6 +427,26 @@
</div>
</div>
+ <div id="template-modal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="template-modal-title">
+ <div class="modal-backdrop"></div>
+ <div class="modal-card template-modal-card">
+ <header class="modal-header">
+ <h3 id="template-modal-title" data-i18n="modal.templateGallery">Template gallery</h3>
+ <button id="template-close" type="button" class="icon-btn" aria-label="Close"
+ data-i18n-aria-label="label.close">x</button>
+ </header>
+ <div class="modal-form">
+ <div class="modal-body template-modal-body">
+ <p class="modal-note" data-i18n="template.modalHint">Pick a starter template and open it in a fresh calendar.</p>
+ <div id="template-links" class="template-links"></div>
+ </div>
+ <div class="modal-actions">
+ <button id="template-cancel" type="button" class="ghost" data-i18n="btn.cancel">Cancel</button>
+ </div>
+ </div>
+ </div>
+ </div>
+
<div id="qr-modal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="qr-modal-title">
<div class="modal-backdrop"></div>
<div class="modal-card qr-modal-card">
@@ -589,6 +610,7 @@
<button id="mobile-view-json" type="button" class="ghost" data-i18n="btn.viewJson">View JSON</button>
<button id="mobile-export-json" type="button" class="ghost" data-i18n="btn.exportJson">Export JSON</button>
<button id="mobile-import-ics" type="button" class="ghost" data-i18n="btn.importIcs">Import .ics</button>
+ <button id="mobile-open-template-gallery" type="button" class="ghost" data-i18n="btn.templateGallery">Template gallery</button>
</div>
</div>
</div>
diff --git a/locales/en.js b/locales/en.js
index 336cd5c..5275f34 100644
--- a/locales/en.js
+++ b/locales/en.js
@@ -39,6 +39,7 @@ export default {
"btn.downloadJson": "Download JSON",
"btn.copyTextLink": "Copy text link instead",
"btn.worldPlanner": "Planner",
+ "btn.templateGallery": "Template gallery",
"planner.notFound": "Timezone not found",
"planner.homeTitle": "Make Home",
"planner.removeTitle": "Remove",
@@ -56,6 +57,7 @@ export default {
"modal.scanQr": "Scan to open on mobile",
"modal.selectTimezone": "Select timezone",
"modal.worldPlanner": "World Planner",
+ "modal.templateGallery": "Template gallery",
// Event form fields
"event.title": "Title",
@@ -90,6 +92,10 @@ export default {
"panel.urlLength": "URL length",
"panel.urlWarning": "Warning: long URLs may get truncated when shared.",
+ // Template gallery
+ "template.modalHint": "Pick a starter template and open it in a fresh calendar.",
+ "template.useTemplate": "Open template",
+
// Timezone/world clock
"tz.worldClock": "World Clock",
"tz.subtitle": "Local time plus saved zones",
@@ -157,6 +163,7 @@ export default {
"confirm.deleteEvent": "Delete this event?",
"confirm.clearAll": "Clear all events? This cannot be undone.",
"confirm.removeLock": "Remove password protection? This will store data unencrypted in the URL.",
+ "confirm.openTemplate": "Open this template in a fresh calendar? This will replace your current URL state.",
// Mobile warning
"mobile.title": "Mobile view notice",
diff --git a/locales/it.js b/locales/it.js
index 495e923..a9988fc 100644
--- a/locales/it.js
+++ b/locales/it.js
@@ -46,6 +46,13 @@ export default {
'launcher.appsTitle': 'App',
'app.calendar': 'Hash Calendar',
'app.spreadsheet': 'Foglio di calcolo in tempo reale',
+ 'btn.templateGallery': 'Galleria template',
+ 'modal.templateGallery': 'Galleria template',
+
+ // Template gallery
+ 'template.modalHint': 'Scegli un template iniziale e aprilo in un calendario nuovo.',
+ 'template.useTemplate': 'Apri template',
+ 'confirm.openTemplate': 'Aprire questo template in un calendario nuovo? Sostituira lo stato URL corrente.',
// Modal titles
'modal.addEvent': 'Aggiungi evento',
diff --git a/locales/si.js b/locales/si.js
index 28bdec8..2288768 100644
--- a/locales/si.js
+++ b/locales/si.js
@@ -46,6 +46,13 @@ export default {
"launcher.appsTitle": "යෙදුම්",
"app.calendar": "Hash Calendar",
"app.spreadsheet": "Spreadsheet Live",
+ "btn.templateGallery": "Template gallery",
+ "modal.templateGallery": "Template gallery",
+
+ // Template gallery
+ "template.modalHint": "Pick a starter template and open it in a fresh calendar.",
+ "template.useTemplate": "Open template",
+ "confirm.openTemplate": "Open this template in a fresh calendar? This will replace your current URL state.",
// Modal titles
"modal.addEvent": "සිදුවීම එක් කරන්න",
diff --git a/locales/ta.js b/locales/ta.js
index 5092b93..c24a516 100644
--- a/locales/ta.js
+++ b/locales/ta.js
@@ -46,6 +46,13 @@ export default {
'launcher.appsTitle': 'செயலிகள்',
'app.calendar': 'Hash Calendar',
'app.spreadsheet': 'Spreadsheet Live',
+ 'btn.templateGallery': 'Template gallery',
+ 'modal.templateGallery': 'Template gallery',
+
+ // Template gallery
+ 'template.modalHint': 'Pick a starter template and open it in a fresh calendar.',
+ 'template.useTemplate': 'Open template',
+ 'confirm.openTemplate': 'Open this template in a fresh calendar? This will replace your current URL state.',
// Modal titles
'modal.addEvent': 'நிகழ்வைச் சேர்',
diff --git a/modules/responsiveFeatures.js b/modules/responsiveFeatures.js
new file mode 100644
index 0000000..a4b03fe
--- /dev/null
+++ b/modules/responsiveFeatures.js
@@ -0,0 +1,215 @@
+export function createResponsiveFeaturesController({ ui, cssClasses, t } = {}) {
+ const activeClass = cssClasses && cssClasses.IS_ACTIVE ? cssClasses.IS_ACTIVE : "is-active";
+ const translate = typeof t === "function" ? t : (key) => key;
+ let initialized = false;
+
+ function syncTopbarHeight() {
+ if (!ui || !ui.topbar) return;
+ const topbarH = ui.topbar.offsetHeight;
+ document.documentElement.style.setProperty("--topbar-height", `${topbarH}px`);
+ const quickBar = ui.mobileQuickActions;
+ const quickH = quickBar && window.getComputedStyle(quickBar).display !== "none" ? quickBar.offsetHeight : 0;
+ document.documentElement.style.setProperty("--topbar-plus-quick", `${topbarH + quickH}px`);
+ }
+
+ function openMobileDrawer() {
+ if (!ui) return;
+ if (ui.mobileDrawer) ui.mobileDrawer.classList.add(activeClass);
+ if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.classList.add(activeClass);
+ document.body.style.overflow = "hidden";
+ const icon = ui.hamburgerBtn && ui.hamburgerBtn.querySelector("i");
+ if (icon) {
+ icon.classList.remove("fa-bars");
+ icon.classList.add("fa-xmark");
+ }
+ }
+
+ function closeMobileDrawer() {
+ if (!ui) return;
+ if (ui.mobileDrawer) ui.mobileDrawer.classList.remove(activeClass);
+ if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.classList.remove(activeClass);
+ document.body.style.overflow = "";
+ const icon = ui.hamburgerBtn && ui.hamburgerBtn.querySelector("i");
+ if (icon) {
+ icon.classList.add("fa-bars");
+ icon.classList.remove("fa-xmark");
+ }
+ }
+
+ function setMobileSidebarLabel(key) {
+ if (!ui || !ui.mobileSidebarToggle) return;
+ const span = ui.mobileSidebarToggle.querySelector("span");
+ if (span) span.textContent = translate(key);
+ }
+
+ function init({
+ getSelectedDate,
+ openEventModal,
+ handleCopyLink,
+ handleShareQr,
+ handleLockAction,
+ handleFocusToggle,
+ openJsonModal,
+ handleExportJson,
+ handleImportIcsClick,
+ openTemplateModal,
+ handleClearAll,
+ openTzModal,
+ setView,
+ handleWeekStartToggle,
+ handleThemeToggle,
+ handleNotificationToggle,
+ handleReadOnlyToggle,
+ openWorldPlanner,
+ } = {}) {
+ if (!ui || initialized) return;
+ initialized = true;
+
+ const readSelectedDate = typeof getSelectedDate === "function" ? getSelectedDate : () => new Date();
+
+ if (ui.hamburgerBtn) {
+ ui.hamburgerBtn.addEventListener("click", (event) => {
+ event.stopPropagation();
+ if (ui.mobileDrawer && ui.mobileDrawer.classList.contains(activeClass)) {
+ closeMobileDrawer();
+ } else {
+ openMobileDrawer();
+ }
+ });
+ }
+
+ if (ui.mobileDrawerClose) ui.mobileDrawerClose.addEventListener("click", closeMobileDrawer);
+ if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.addEventListener("click", closeMobileDrawer);
+
+ if (ui.mobileAddEvent && typeof openEventModal === "function") {
+ ui.mobileAddEvent.addEventListener("click", () => openEventModal({ date: readSelectedDate() }));
+ }
+ if (ui.mobileCopyLink && typeof handleCopyLink === "function") {
+ ui.mobileCopyLink.addEventListener("click", handleCopyLink);
+ }
+ if (ui.mobileShareQr && typeof handleShareQr === "function") {
+ ui.mobileShareQr.addEventListener("click", handleShareQr);
+ }
+ if (ui.mobileLockBtn && typeof handleLockAction === "function") {
+ ui.mobileLockBtn.addEventListener("click", handleLockAction);
+ }
+ if (ui.mobileUnlockBtn && typeof handleLockAction === "function") {
+ ui.mobileUnlockBtn.addEventListener("click", handleLockAction);
+ }
+ if (ui.mobileFocusBtn && typeof handleFocusToggle === "function") {
+ ui.mobileFocusBtn.addEventListener("click", handleFocusToggle);
+ }
+ if (ui.mobileAddEventInline && typeof openEventModal === "function") {
+ ui.mobileAddEventInline.addEventListener("click", () => {
+ closeMobileDrawer();
+ openEventModal({ date: readSelectedDate() });
+ });
+ }
+ if (ui.mobileViewJson && typeof openJsonModal === "function") {
+ ui.mobileViewJson.addEventListener("click", () => {
+ closeMobileDrawer();
+ openJsonModal();
+ });
+ }
+ if (ui.mobileExportJson && typeof handleExportJson === "function") {
+ ui.mobileExportJson.addEventListener("click", () => {
+ closeMobileDrawer();
+ handleExportJson();
+ });
+ }
+ if (ui.mobileImportIcs && typeof handleImportIcsClick === "function") {
+ ui.mobileImportIcs.addEventListener("click", () => {
+ closeMobileDrawer();
+ handleImportIcsClick();
+ });
+ }
+ if (ui.mobileTemplateGalleryBtn && typeof openTemplateModal === "function") {
+ ui.mobileTemplateGalleryBtn.addEventListener("click", () => {
+ closeMobileDrawer();
+ openTemplateModal();
+ });
+ }
+ if (ui.mobileClearAll && typeof handleClearAll === "function") {
+ ui.mobileClearAll.addEventListener("click", () => {
+ closeMobileDrawer();
+ handleClearAll();
+ });
+ }
+ if (ui.mobileAddTzBtn && typeof openTzModal === "function") {
+ ui.mobileAddTzBtn.addEventListener("click", () => {
+ closeMobileDrawer();
+ openTzModal();
+ });
+ }
+
+ if (ui.mobileDrawerViewButtons && ui.mobileDrawerViewButtons.length && typeof setView === "function") {
+ ui.mobileDrawerViewButtons.forEach((button) => {
+ button.addEventListener("click", () => {
+ setView(button.dataset.view);
+ closeMobileDrawer();
+ });
+ });
+ }
+
+ if (ui.mobileWeekstartToggle && typeof handleWeekStartToggle === "function") {
+ ui.mobileWeekstartToggle.addEventListener("click", handleWeekStartToggle);
+ }
+ if (ui.mobileThemeToggle && typeof handleThemeToggle === "function") {
+ ui.mobileThemeToggle.addEventListener("click", handleThemeToggle);
+ }
+ if (ui.mobileNotifyToggle && typeof handleNotificationToggle === "function") {
+ ui.mobileNotifyToggle.addEventListener("click", handleNotificationToggle);
+ }
+ if (ui.mobileReadOnlyBtn && typeof handleReadOnlyToggle === "function") {
+ ui.mobileReadOnlyBtn.addEventListener("click", () => {
+ handleReadOnlyToggle();
+ closeMobileDrawer();
+ });
+ }
+
+ if (ui.mobileWorldPlannerBtn && typeof openWorldPlanner === "function") {
+ ui.mobileWorldPlannerBtn.addEventListener("click", () => {
+ closeMobileDrawer();
+ openWorldPlanner();
+ });
+ }
+
+ if (ui.mobileSidebarToggle) {
+ ui.mobileSidebarToggle.addEventListener("click", () => {
+ if (!ui.sidePanel || !ui.tzSidebar) return;
+ if (ui.sidePanel.classList.contains(activeClass)) {
+ ui.sidePanel.classList.remove(activeClass);
+ ui.tzSidebar.classList.add(activeClass);
+ setMobileSidebarLabel("label.clock");
+ } else if (ui.tzSidebar.classList.contains(activeClass)) {
+ ui.tzSidebar.classList.remove(activeClass);
+ setMobileSidebarLabel("label.details");
+ } else {
+ ui.sidePanel.classList.add(activeClass);
+ setMobileSidebarLabel("label.events");
+ }
+ });
+ }
+
+ if (ui.sidePanelClose) {
+ ui.sidePanelClose.addEventListener("click", () => {
+ if (ui.sidePanel) ui.sidePanel.classList.remove(activeClass);
+ setMobileSidebarLabel("label.details");
+ });
+ }
+
+ if (ui.tzSidebarClose) {
+ ui.tzSidebarClose.addEventListener("click", () => {
+ if (ui.tzSidebar) ui.tzSidebar.classList.remove(activeClass);
+ setMobileSidebarLabel("label.details");
+ });
+ }
+ }
+
+ return {
+ syncTopbarHeight,
+ openMobileDrawer,
+ closeMobileDrawer,
+ init,
+ };
+}
diff --git a/modules/template-gallery-links.json b/modules/template-gallery-links.json
new file mode 100644
index 0000000..c848782
--- /dev/null
+++ b/modules/template-gallery-links.json
@@ -0,0 +1,74 @@
+[
+ {
+ "id": "personal-weekly",
+ "title": "Personal weekly planner",
+ "description": "Morning routine, planning block, and evening reflection.",
+ "path": "#/2026/02/16/06/30+45/Morning-Workout,2026/02/16/08/00+20/Plan-Day,2026/02/16/20/30+20/Journal-and-Reflect"
+ },
+ {
+ "id": "work-sprint",
+ "title": "Work sprint board",
+ "description": "Standup, deep work block, review, and retro checkpoints.",
+ "path": "#/2026/02/16/09/30+20/Daily-Standup,2026/02/16/10/00+120/Sprint-Deep-Work,2026/02/18/14/00+60/Sprint-Review,2026/02/19/14/00+60/Sprint-Retrospective"
+ },
+ {
+ "id": "student-semester",
+ "title": "Student semester schedule",
+ "description": "Class sessions, lab time, and assignment study blocks.",
+ "path": "#/2026/02/16/08/30+90/Math-Lecture,2026/02/16/11/00+120/Lab-Session,2026/02/17/17/30+120/Assignment-Block,2026/02/20/09/00+120/Revision-Session"
+ },
+ {
+ "id": "exam-countdown",
+ "title": "Exam countdown plan",
+ "description": "Revision sprints and final exam day reminders.",
+ "path": "#/2026/02/25/Exam-Day,2026/02/20/07/00+90/Revision-Sprint,2026/02/22/18/00+120/Past-Papers,2026/02/24/20/00+45/Quick-Review"
+ },
+ {
+ "id": "content-calendar",
+ "title": "Content production week",
+ "description": "Script, filming, editing, and publishing sequence.",
+ "path": "#/2026/02/16/10/00+90/Script-Writing,2026/02/17/14/00+120/Filming,2026/02/18/16/00+90/Editing,2026/02/19/19/00+30/Publish-and-Share"
+ },
+ {
+ "id": "project-launch",
+ "title": "Project launch timeline",
+ "description": "MVP, build phase, QA, checklist, and launch day.",
+ "path": "#/2026/02/16/09/00+60/Define-MVP,2026/02/18/09/30+120/Build-Core-Features,2026/02/22/10/00+90/QA-and-Fixes,2026/02/24/11/00+60/Launch-Checklist,2026/02/25/Launch-Day"
+ },
+ {
+ "id": "budget-bills",
+ "title": "Budget and bills tracker",
+ "description": "Salary, rent, utilities, savings transfer, and card payment.",
+ "path": "#/2026/02/01/Salary-Day,2026/02/03/Rent-Due,2026/02/07/Utilities-Check,2026/02/15/Savings-Transfer,2026/02/25/Credit-Card-Payment"
+ },
+ {
+ "id": "fitness-meal",
+ "title": "Fitness and meal prep",
+ "description": "Workout cadence plus meal prep and recovery sessions.",
+ "path": "#/2026/02/16/06/00+60/Strength-Workout,2026/02/17/06/00+45/Cardio-Session,2026/02/18/19/00+60/Meal-Prep,2026/02/19/06/00+60/Strength-Workout,2026/02/20/18/00+30/Stretch-and-Mobility"
+ },
+ {
+ "id": "family-events",
+ "title": "Family events planner",
+ "description": "Family dinner, school meeting, outing, and birthday.",
+ "path": "#/2026/02/14/Family-Dinner,2026/02/18/18/00+60/School-Meeting,2026/02/21/10/00+180/Weekend-Outing,2026/02/28/Birthday-Celebration"
+ },
+ {
+ "id": "travel-itinerary",
+ "title": "Travel itinerary",
+ "description": "Airport, hotel, activities, and return flight timeline.",
+ "path": "#/2026/03/10/07/30+90/Airport-Check-in,2026/03/10/11/00+60/Hotel-Check-in,2026/03/11/09/00+480/City-Tour,2026/03/12/13/00+180/Museum-and-Lunch,2026/03/13/16/00+60/Return-Flight"
+ },
+ {
+ "id": "sri-lanka-holidays",
+ "title": "Sri Lanka holidays",
+ "description": "Starter list with key national holidays.",
+ "path": "#/2026/01/01/New-Year-Day,2026/02/04/National-Day,2026/04/13/Avurudu-Eve,2026/05/01/May-Day"
+ },
+ {
+ "id": "festival-calendar",
+ "title": "Festival calendar",
+ "description": "Pongal, Vesak, and Deepavali reminders.",
+ "path": "#/2026/01/14/Pongal,2026/05/24/Vesak-Poya,2026/10/29/Deepavali"
+ }
+]
diff --git a/modules/templateGallery.js b/modules/templateGallery.js
new file mode 100644
index 0000000..09c1081
--- /dev/null
+++ b/modules/templateGallery.js
@@ -0,0 +1,133 @@
+const TEMPLATE_GALLERY_JSON_URL = new URL("./template-gallery-links.json", import.meta.url);
+
+function normalizeTemplateGalleryLinks(raw) {
+ if (!Array.isArray(raw)) return [];
+ return raw
+ .filter((item) => item && typeof item === "object")
+ .map((item) => ({
+ id: String(item.id || "").trim(),
+ title: String(item.title || "").trim(),
+ description: String(item.description || "").trim(),
+ path: String(item.path || "").trim().replace(/^\/+/, ""),
+ }))
+ .filter((item) => item.id && item.title && item.description && item.path);
+}
+
+function isTemplatePathDateSegment(yearText, monthText, dayText) {
+ if (!/^\d{4}$/.test(yearText) || !/^\d{1,2}$/.test(monthText) || !/^\d{1,2}$/.test(dayText)) {
+ return false;
+ }
+ const year = Number(yearText);
+ const month = Number(monthText);
+ const day = Number(dayText);
+ if (month < 1 || month > 12 || day < 1 || day > 31) return false;
+ const date = new Date(year, month - 1, day);
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
+}
+
+function getTemplateBasePath(pathname) {
+ const safePath = String(pathname || "/");
+ const segments = safePath.split("/").filter(Boolean);
+ let dateStart = -1;
+ for (let i = 0; i <= segments.length - 3; i += 1) {
+ if (isTemplatePathDateSegment(segments[i], segments[i + 1], segments[i + 2])) {
+ dateStart = i;
+ break;
+ }
+ }
+ if (dateStart === -1) {
+ if (safePath.endsWith(".html")) {
+ const slashIndex = safePath.lastIndexOf("/");
+ return slashIndex >= 0 ? safePath.slice(0, slashIndex + 1) || "/" : "/";
+ }
+ return safePath || "/";
+ }
+ const baseSegments = segments.slice(0, dateStart);
+ return `/${baseSegments.join("/")}${baseSegments.length ? "/" : ""}`;
+}
+
+function getTemplateHref(path) {
+ const cleanPath = String(path || "").replace(/^\/+/, "");
+ if (!cleanPath) return window.location.pathname || "/";
+ const basePath = getTemplateBasePath(window.location.pathname || "/");
+ if (basePath.endsWith("/")) {
+ return `${basePath}${cleanPath}`;
+ }
+ return `${basePath}/${cleanPath}`;
+}
+
+export function createTemplateGalleryController({ ui, hiddenClass = "hidden", t } = {}) {
+ let templateGalleryLinks = [];
+ const translate = typeof t === "function" ? t : (key) => key;
+
+ function render() {
+ if (!ui || !ui.templateLinks) return;
+ ui.templateLinks.innerHTML = "";
+ templateGalleryLinks.forEach((template) => {
+ const card = document.createElement("article");
+ card.className = "template-card";
+
+ const title = document.createElement("h4");
+ title.className = "template-card-title";
+ title.textContent = template.title;
+
+ const description = document.createElement("p");
+ description.className = "template-card-description";
+ description.textContent = template.description;
+
+ const link = document.createElement("a");
+ link.className = "template-card-link";
+ link.href = getTemplateHref(template.path);
+ link.dataset.templateId = template.id;
+ link.textContent = translate("template.useTemplate");
+
+ card.append(title, description, link);
+ ui.templateLinks.appendChild(card);
+ });
+ }
+
+ async function loadLinks() {
+ try {
+ const response = await fetch(TEMPLATE_GALLERY_JSON_URL, { cache: "no-cache" });
+ if (!response.ok) {
+ throw new Error(`Template gallery JSON load failed: ${response.status}`);
+ }
+ const payload = await response.json();
+ templateGalleryLinks = normalizeTemplateGalleryLinks(payload);
+ } catch (error) {
+ templateGalleryLinks = [];
+ console.error("Template gallery links could not be loaded.", error);
+ }
+ }
+
+ function openModal() {
+ if (!ui || !ui.templateModal) return;
+ render();
+ ui.templateModal.classList.remove(hiddenClass);
+ }
+
+ function closeModal() {
+ if (!ui || !ui.templateModal) return;
+ ui.templateModal.classList.add(hiddenClass);
+ }
+
+ function handleLinkClick(event) {
+ if (!(event.target instanceof Element)) return;
+ const link = event.target.closest(".template-card-link");
+ if (!link) return;
+ const confirmed = window.confirm(translate("confirm.openTemplate"));
+ if (!confirmed) {
+ event.preventDefault();
+ return;
+ }
+ closeModal();
+ }
+
+ return {
+ render,
+ loadLinks,
+ openModal,
+ closeModal,
+ handleLinkClick,
+ };
+}
diff --git a/script.js b/script.js
index 7e05ae6..21adc34 100644
--- a/script.js
+++ b/script.js
@@ -39,7 +39,9 @@ import { createJsonModalController, createPasswordModalController } from "./modu
import { getCreationHashPath, importEventsFromPath as importEventsFromPathFromLocation } from "./modules/pathImportManager.js";
import { initQRCodeManager } from "./modules/qrCodeManager.js";
import { expandEvents } from "./modules/recurrenceEngine.js";
+import { createResponsiveFeaturesController } from "./modules/responsiveFeatures.js";
import { StateSaveManager } from "./modules/stateSaveManager.js";
+import { createTemplateGalleryController } from "./modules/templateGallery.js";
import { AVAILABLE_ZONES, getLocalZone, getZoneInfo, isValidZone, parseOffsetSearchTerm } from "./modules/timezoneManager.js";
import { parsePathToEventEntries } from "./modules/urlPathEventParser.js";
import { WorldPlanner } from "./modules/worldPlannerModule.js";
@@ -60,6 +62,8 @@ let saveManager = null;
let passwordModalController = null;
let jsonModalController = null;
let notificationTimer = null;
+let responsiveFeaturesController = null;
+let templateGalleryController = null;
const notifiedOccurrences = new Map();
const ui = {};
@@ -295,13 +299,14 @@ function cacheElements() {
ui.addEventInline = document.getElementById("add-event-inline");
ui.urlLength = document.getElementById("url-length");
ui.urlWarning = document.getElementById("url-warning");
- ui.viewJson = document.getElementById("view-json");
- ui.exportJson = document.getElementById("export-json");
- ui.importIcs = document.getElementById("import-ics");
- ui.icsInput = document.getElementById("ics-input");
- ui.clearAll = document.getElementById("clear-all");
- ui.lockedOverlay = document.getElementById("locked-overlay");
- ui.unlockBtn = document.getElementById("unlock-btn");
+ ui.viewJson = document.getElementById("view-json");
+ ui.exportJson = document.getElementById("export-json");
+ ui.importIcs = document.getElementById("import-ics");
+ ui.templateGalleryBtn = document.getElementById("open-template-gallery");
+ ui.icsInput = document.getElementById("ics-input");
+ ui.clearAll = document.getElementById("clear-all");
+ ui.lockedOverlay = document.getElementById("locked-overlay");
+ ui.unlockBtn = document.getElementById("unlock-btn");
ui.eventModal = document.getElementById("event-modal");
ui.eventForm = document.getElementById("event-form");
@@ -335,9 +340,13 @@ function cacheElements() {
ui.jsonClose = document.getElementById("json-close");
ui.jsonHash = document.getElementById("json-hash");
ui.jsonOutput = document.getElementById("json-output");
- ui.jsonCopy = document.getElementById("json-copy");
- ui.jsonCopyHash = document.getElementById("json-copy-hash");
- ui.jsonDownload = document.getElementById("json-download");
+ ui.jsonCopy = document.getElementById("json-copy");
+ ui.jsonCopyHash = document.getElementById("json-copy-hash");
+ ui.jsonDownload = document.getElementById("json-download");
+ ui.templateModal = document.getElementById("template-modal");
+ ui.templateClose = document.getElementById("template-close");
+ ui.templateCancel = document.getElementById("template-cancel");
+ ui.templateLinks = document.getElementById("template-links");
ui.toastContainer = document.getElementById("toast-container");
@@ -375,10 +384,11 @@ function cacheElements() {
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.mobileViewJson = document.getElementById("mobile-view-json");
+ ui.mobileExportJson = document.getElementById("mobile-export-json");
+ ui.mobileImportIcs = document.getElementById("mobile-import-ics");
+ ui.mobileTemplateGalleryBtn = document.getElementById("mobile-open-template-gallery");
+ ui.mobileClearAll = document.getElementById("mobile-clear-all");
ui.mobileTzList = document.getElementById("mobile-tz-list");
ui.mobileAddTzBtn = document.getElementById("mobile-add-tz-btn");
ui.shareExportSection = document.getElementById("share-export-section");
@@ -660,14 +670,10 @@ function updateTheme() {
}
}
-function syncTopbarHeight() {
- if (!ui.topbar) return;
- const topbarH = ui.topbar.offsetHeight;
- document.documentElement.style.setProperty("--topbar-height", `${topbarH}px`);
- const quickBar = ui.mobileQuickActions;
- const quickH = quickBar && window.getComputedStyle(quickBar).display !== "none" ? quickBar.offsetHeight : 0;
- document.documentElement.style.setProperty("--topbar-plus-quick", `${topbarH + quickH}px`);
-}
+function syncTopbarHeight() {
+ if (!responsiveFeaturesController) return;
+ responsiveFeaturesController.syncTopbarHeight();
+}
function updateWeekStartLabel() {
const label = t(state.s.m ? "settings.weekStartsMonday" : "settings.weekStartsSunday");
@@ -1091,16 +1097,17 @@ function updateLanguageUI() {
item.classList.toggle(CSS_CLASSES.ACTIVE, item.dataset.lang === langCode);
});
- // Re-translate components
- updateTheme();
- updateWeekStartLabel();
- updateLockUI();
- updateFocusButton();
- render();
- if (focusMode && focusMode.isActive()) {
- focusMode.tick();
- }
-}
+ // Re-translate components
+ updateTheme();
+ updateWeekStartLabel();
+ updateLockUI();
+ updateFocusButton();
+ renderTemplateGallery();
+ render();
+ if (focusMode && focusMode.isActive()) {
+ focusMode.tick();
+ }
+}
function groupOccurrences(occurrences) {
const map = new Map();
@@ -1726,6 +1733,31 @@ function closeJsonModal() {
jsonModalController.close();
}
+function renderTemplateGallery() {
+ if (!templateGalleryController) return;
+ templateGalleryController.render();
+}
+
+async function loadTemplateGalleryLinks() {
+ if (!templateGalleryController) return;
+ await templateGalleryController.loadLinks();
+}
+
+function openTemplateModal() {
+ if (!templateGalleryController) return;
+ templateGalleryController.openModal();
+}
+
+function closeTemplateModal() {
+ if (!templateGalleryController) return;
+ templateGalleryController.closeModal();
+}
+
+function handleTemplateLinkClick(event) {
+ if (!templateGalleryController) return;
+ templateGalleryController.handleLinkClick(event);
+}
+
async function handleCopyJson() {
if (!jsonModalController) return;
await jsonModalController.copyJson();
@@ -1851,12 +1883,13 @@ function bindEvents() {
if (ui.themeToggle) ui.themeToggle.addEventListener("click", handleThemeToggle);
if (ui.notifyToggle) ui.notifyToggle.addEventListener("click", handleNotificationToggle);
initLanguageDropdown();
- if (ui.unlockBtn) ui.unlockBtn.addEventListener("click", attemptUnlock);
- if (ui.viewJson) ui.viewJson.addEventListener("click", openJsonModal);
- if (ui.exportJson) ui.exportJson.addEventListener("click", handleExportJson);
- if (ui.importIcs) ui.importIcs.addEventListener("click", handleImportIcsClick);
- if (ui.icsInput) ui.icsInput.addEventListener("change", handleIcsFile);
- if (ui.clearAll) ui.clearAll.addEventListener("click", handleClearAll);
+ if (ui.unlockBtn) ui.unlockBtn.addEventListener("click", attemptUnlock);
+ if (ui.viewJson) ui.viewJson.addEventListener("click", openJsonModal);
+ if (ui.exportJson) ui.exportJson.addEventListener("click", handleExportJson);
+ if (ui.importIcs) ui.importIcs.addEventListener("click", handleImportIcsClick);
+ if (ui.templateGalleryBtn) ui.templateGalleryBtn.addEventListener("click", openTemplateModal);
+ if (ui.icsInput) ui.icsInput.addEventListener("change", handleIcsFile);
+ if (ui.clearAll) ui.clearAll.addEventListener("click", handleClearAll);
if (ui.eventClose) ui.eventClose.addEventListener("click", closeEventModal);
if (ui.eventCancel) ui.eventCancel.addEventListener("click", closeEventModal);
@@ -1875,20 +1908,30 @@ function bindEvents() {
if (ui.passwordCancel) ui.passwordCancel.addEventListener("click", closePasswordModal);
if (ui.passwordSubmit) ui.passwordSubmit.addEventListener("click", submitPassword);
if (ui.jsonClose) ui.jsonClose.addEventListener("click", closeJsonModal);
- if (ui.jsonCopy) ui.jsonCopy.addEventListener("click", handleCopyJson);
- if (ui.jsonCopyHash) ui.jsonCopyHash.addEventListener("click", handleCopyHash);
- if (ui.jsonDownload) ui.jsonDownload.addEventListener("click", handleExportJson);
- if (ui.tzAddBtn) ui.tzAddBtn.addEventListener("click", openTzModal);
- if (ui.tzClose) ui.tzClose.addEventListener("click", closeTzModal);
+ if (ui.jsonCopy) ui.jsonCopy.addEventListener("click", handleCopyJson);
+ if (ui.jsonCopyHash) ui.jsonCopyHash.addEventListener("click", handleCopyHash);
+ if (ui.jsonDownload) ui.jsonDownload.addEventListener("click", handleExportJson);
+ if (ui.templateClose) ui.templateClose.addEventListener("click", closeTemplateModal);
+ if (ui.templateCancel) ui.templateCancel.addEventListener("click", closeTemplateModal);
+ if (ui.templateLinks) ui.templateLinks.addEventListener("click", handleTemplateLinkClick);
+ 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.tzModal) {
+ ui.tzModal.addEventListener("click", (event) => {
+ if (event.target === ui.tzModal) closeTzModal();
+ });
+ }
+ if (ui.templateModal) {
+ ui.templateModal.addEventListener("click", (event) => {
+ if (event.target === ui.templateModal || event.target.classList.contains("modal-backdrop")) {
+ closeTemplateModal();
+ }
+ });
+ }
window.addEventListener("hashchange", handleHashChange);
window.addEventListener("resize", syncTopbarHeight);
@@ -1899,159 +1942,56 @@ function bindEvents() {
});
}
-function openMobileDrawer() {
- if (ui.mobileDrawer) ui.mobileDrawer.classList.add(CSS_CLASSES.IS_ACTIVE);
- if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.classList.add(CSS_CLASSES.IS_ACTIVE);
- document.body.style.overflow = "hidden";
- const icon = ui.hamburgerBtn && ui.hamburgerBtn.querySelector("i");
- if (icon) {
- icon.classList.remove("fa-bars");
- icon.classList.add("fa-xmark");
- }
-}
-
-function closeMobileDrawer() {
- if (ui.mobileDrawer) ui.mobileDrawer.classList.remove(CSS_CLASSES.IS_ACTIVE);
- if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.classList.remove(CSS_CLASSES.IS_ACTIVE);
- document.body.style.overflow = "";
- const icon = ui.hamburgerBtn && ui.hamburgerBtn.querySelector("i");
- if (icon) {
- icon.classList.add("fa-bars");
- icon.classList.remove("fa-xmark");
- }
-}
-
-function initResponsiveFeatures() {
- // Hamburger opens/closes the drawer
- if (ui.hamburgerBtn) {
- ui.hamburgerBtn.addEventListener("click", (e) => {
- e.stopPropagation();
- if (ui.mobileDrawer && ui.mobileDrawer.classList.contains(CSS_CLASSES.IS_ACTIVE)) {
- closeMobileDrawer();
- } else {
- openMobileDrawer();
- }
- });
- }
-
- // Close button & backdrop close the drawer
- if (ui.mobileDrawerClose) ui.mobileDrawerClose.addEventListener("click", closeMobileDrawer);
- if (ui.mobileDrawerBackdrop) ui.mobileDrawerBackdrop.addEventListener("click", closeMobileDrawer);
-
- // Quick-action buttons delegate to existing handlers
- if (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();
- });
- }
-
- // Drawer view buttons
- if (ui.mobileDrawerViewButtons && ui.mobileDrawerViewButtons.length) {
- ui.mobileDrawerViewButtons.forEach((button) => {
- button.addEventListener("click", () => {
- setView(button.dataset.view);
- closeMobileDrawer();
- });
- });
- }
-
- // Drawer settings buttons
- if (ui.mobileWeekstartToggle) {
- ui.mobileWeekstartToggle.addEventListener("click", handleWeekStartToggle);
- }
- if (ui.mobileThemeToggle) {
- ui.mobileThemeToggle.addEventListener("click", handleThemeToggle);
- }
- if (ui.mobileNotifyToggle) {
- ui.mobileNotifyToggle.addEventListener("click", handleNotificationToggle);
- }
- if (ui.mobileReadOnlyBtn) {
- ui.mobileReadOnlyBtn.addEventListener("click", () => {
- handleReadOnlyToggle();
- closeMobileDrawer();
- });
- }
-
- // Drawer world planner button
- if (ui.mobileWorldPlannerBtn) {
- ui.mobileWorldPlannerBtn.addEventListener("click", () => {
- closeMobileDrawer();
- worldPlanner.open();
- });
- }
-
- // Existing mobile sidebar toggle logic (unchanged)
- if (ui.mobileSidebarToggle) {
- ui.mobileSidebarToggle.addEventListener("click", () => {
- if (ui.sidePanel.classList.contains(CSS_CLASSES.IS_ACTIVE)) {
- ui.sidePanel.classList.remove(CSS_CLASSES.IS_ACTIVE);
- ui.tzSidebar.classList.add(CSS_CLASSES.IS_ACTIVE);
- ui.mobileSidebarToggle.querySelector("span").textContent = t("label.clock");
- } else if (ui.tzSidebar.classList.contains(CSS_CLASSES.IS_ACTIVE)) {
- ui.tzSidebar.classList.remove(CSS_CLASSES.IS_ACTIVE);
- ui.mobileSidebarToggle.querySelector("span").textContent = t("label.details");
- } else {
- ui.sidePanel.classList.add(CSS_CLASSES.IS_ACTIVE);
- ui.mobileSidebarToggle.querySelector("span").textContent = t("label.events");
- }
- });
- }
-
- if (ui.sidePanelClose) {
- ui.sidePanelClose.addEventListener("click", () => {
- ui.sidePanel.classList.remove(CSS_CLASSES.IS_ACTIVE);
- if (ui.mobileSidebarToggle) ui.mobileSidebarToggle.querySelector("span").textContent = t("label.details");
- });
- }
-
- if (ui.tzSidebarClose) {
- ui.tzSidebarClose.addEventListener("click", () => {
- ui.tzSidebar.classList.remove(CSS_CLASSES.IS_ACTIVE);
- if (ui.mobileSidebarToggle) ui.mobileSidebarToggle.querySelector("span").textContent = t("label.details");
- });
- }
-}
+function openMobileDrawer() {
+ if (!responsiveFeaturesController) return;
+ responsiveFeaturesController.openMobileDrawer();
+}
+
+function closeMobileDrawer() {
+ if (!responsiveFeaturesController) return;
+ responsiveFeaturesController.closeMobileDrawer();
+}
+
+function initResponsiveFeatures() {
+ if (!responsiveFeaturesController) return;
+ responsiveFeaturesController.init({
+ getSelectedDate: () => selectedDate,
+ openEventModal,
+ handleCopyLink,
+ handleShareQr,
+ handleLockAction,
+ handleFocusToggle,
+ openJsonModal,
+ handleExportJson,
+ handleImportIcsClick,
+ openTemplateModal,
+ handleClearAll,
+ openTzModal,
+ setView,
+ handleWeekStartToggle,
+ handleThemeToggle,
+ handleNotificationToggle,
+ handleReadOnlyToggle,
+ openWorldPlanner: () => {
+ if (worldPlanner) worldPlanner.open();
+ },
+ });
+}
async function init() {
cacheElements();
+ responsiveFeaturesController = createResponsiveFeaturesController({
+ ui,
+ cssClasses: CSS_CLASSES,
+ t,
+ });
syncTopbarHeight();
+ templateGalleryController = createTemplateGalleryController({
+ ui,
+ hiddenClass: CSS_CLASSES.HIDDEN,
+ t,
+ });
+ await loadTemplateGalleryLinks();
passwordModalController = createPasswordModalController({
ui,
hiddenClass: CSS_CLASSES.HIDDEN,
diff --git a/styles.css b/styles.css
index 79c60ed..0b73508 100644
--- a/styles.css
+++ b/styles.css
@@ -1412,6 +1412,10 @@ body[data-theme="dark"] .time-indicator-circle {
width: min(720px, 94vw);
}
+.template-modal-card {
+ width: min(860px, 96vw);
+}
+
.qr-modal-card {
width: min(420px, 92vw);
text-align: center;
@@ -1732,6 +1736,54 @@ body[data-theme="dark"] .app-launcher-modal-body,
color: var(--danger);
}
+.template-modal-body {
+ gap: 14px;
+}
+
+.template-links {
+ display: grid;
+ grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
+ gap: 12px;
+}
+
+.template-card {
+ border: 1px solid var(--border-soft);
+ border-radius: 10px;
+ background: var(--panel-2);
+ padding: 14px;
+ display: flex;
+ flex-direction: column;
+ gap: 10px;
+}
+
+.template-card-title {
+ margin: 0;
+ font-size: 0.9rem;
+}
+
+.template-card-description {
+ margin: 0;
+ font-size: 0.8rem;
+ color: var(--muted);
+ flex: 1;
+}
+
+.template-card-link {
+ border: 1px solid var(--border-soft);
+ border-radius: 8px;
+ padding: 8px 10px;
+ text-decoration: none;
+ font-size: 0.8rem;
+ color: var(--text);
+ background: var(--panel);
+ transition: border-color 0.2s ease, transform 0.2s ease;
+}
+
+.template-card-link:hover {
+ border-color: var(--accent);
+ transform: translateY(-1px);
+}
+
.locked-overlay {
position: absolute;
inset: 0;