Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,54 @@ navLinks?.addEventListener('click', (e) => {
}
});

// --- Theme toggle (shared by navbar and accessibility panel) ---
(function themeControls() {
const root = document.documentElement;
const store = window.localStorage;
const get = (k, d) => { try { return store.getItem(k) ?? d; } catch { return d; } };
const set = (k, v) => { try { store.setItem(k, v); } catch {} };
const remove = (k) => { try { store.removeItem(k); } catch {} };

function currentTheme() {
return root.dataset.theme === 'dark' ? 'dark' : 'light';
}

function applyTheme(theme, persist = true) {
const next = theme === 'dark' ? 'dark' : 'light';
root.dataset.theme = next;
if (persist) set('guide-theme', next);

document.querySelectorAll('[data-theme-choice]').forEach((button) => {
button.setAttribute('aria-pressed', String(button.dataset.themeChoice === next));
});

document.querySelectorAll('[data-theme-toggle]').forEach((button) => {
const isDark = next === 'dark';
const label = isDark ? 'Switch to light mode' : 'Switch to dark mode';
button.setAttribute('aria-pressed', String(isDark));
button.setAttribute('aria-label', label);
button.title = label;
const icon = button.querySelector('.theme-icon');
if (icon) icon.textContent = isDark ? '☀' : '☾';
});
}

document.querySelectorAll('[data-theme-choice]').forEach((button) => {
button.addEventListener('click', () => applyTheme(button.dataset.themeChoice));
});

document.querySelectorAll('[data-theme-toggle]').forEach((button) => {
button.addEventListener('click', () => applyTheme(currentTheme() === 'dark' ? 'light' : 'dark'));
});

window.resetGuideTheme = () => {
remove('guide-theme');
applyTheme('light', false);
};

applyTheme(get('guide-theme', 'light'), false);
})();

// --- Accessibility toolbar (persisted preferences) ---
(function a11y() {
const fab = document.getElementById('a11yFab');
Expand Down Expand Up @@ -108,6 +156,7 @@ navLinks?.addEventListener('click', (e) => {
document.getElementById('a11yReset')?.addEventListener('click', () => {
['a11y-size', 'a11y-hc', 'a11y-ul-links', 'a11y-reduce-motion'].forEach((k) => { try { store.removeItem(k); } catch {} });
applySize('1'); ['hc', 'ul-links', 'reduce-motion'].forEach((c) => applyToggle(c, false));
window.resetGuideTheme?.();
});

// restore saved prefs (default reduce-motion to the OS setting if unset)
Expand Down
28 changes: 25 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&family=Space+Mono:wght@400;700&family=Inter:wght@400;500;600;700&family=Mukta:wght@800&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="styles.css?v=17" />
<script>
(() => {
try {
if (localStorage.getItem('guide-theme') === 'dark') {
document.documentElement.dataset.theme = 'dark';
}
} catch {}
})();
</script>
<link rel="stylesheet" href="styles.css?v=20" />
</head>
<body>
<a class="skip" href="#main">Skip to content</a>
Expand All @@ -40,7 +49,6 @@
<header class="nav">
<div class="wrap nav-inner">
<div class="brand"><span class="dc">Devcon 8 India</span><span class="sep">/</span><span class="pl">Mumbai Field Guide</span></div>
<button class="nav-toggle" id="navToggle" aria-label="Open menu" aria-expanded="false" aria-controls="navLinks">Menu</button>
<nav class="nav-links" id="navLinks" aria-label="Primary">
<a href="#getting">Transit</a>
<a href="#stay">Hotels</a>
Expand All @@ -52,6 +60,12 @@
<a href="#street">Street Smart</a>
<a href="#know">Know</a>
</nav>
<div class="nav-actions">
<button class="theme-toggle" id="themeToggle" type="button" data-theme-toggle aria-label="Switch to dark mode" aria-pressed="false">
<span class="theme-icon" aria-hidden="true">☾</span>
</button>
<button class="nav-toggle" id="navToggle" aria-label="Open menu" aria-expanded="false" aria-controls="navLinks">Menu</button>
</div>
</div>
</header>

Expand Down Expand Up @@ -906,6 +920,14 @@ <h3>Accessibility</h3>
</div>
</div>

<div class="a11y-row">
<span class="rl" id="theme-label">Theme</span>
<div class="opts" role="group" aria-labelledby="theme-label">
<button class="a11y-opt" data-theme-choice="light" aria-pressed="true">Light</button>
<button class="a11y-opt" data-theme-choice="dark" aria-pressed="false">Dark</button>
</div>
</div>

<div class="a11y-row">
<span class="rl" id="ul-label">Underline links</span>
<div class="opts" role="group" aria-labelledby="ul-label">
Expand All @@ -925,6 +947,6 @@ <h3>Accessibility</h3>
<button class="a11y-reset" id="a11yReset">Reset to defaults</button>
</div>

<script src="app.js?v=5"></script>
<script src="app.js?v=6"></script>
</body>
</html>
Loading