-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnav.js
More file actions
133 lines (125 loc) · 5.91 KB
/
nav.js
File metadata and controls
133 lines (125 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* nav.js — inject shared nav + footer into every page */
(function () {
const currentPage = location.pathname.split('/').pop() || 'index.html';
const links = [
{ href: 'index.html', icon: '🏠', label: 'Home' },
{ href: 'tools.html', icon: '🛠️', label: 'Tools' },
{ href: 'articles.html', icon: '📖', label: 'Articles' },
{ href: 'resources.html', icon: '🆘', label: 'Resources' },
{ href: 'about.html', icon: '💙', label: 'About' },
];
const navHTML = `
<a class="skip-link" href="#main">Skip to main content</a>
<div class="nav-wrapper" role="banner">
<div class="nav-inner">
<a class="nav-logo" href="index.html" aria-label="MindLift Home">MindLift</a>
<ul class="nav-links" role="navigation" aria-label="Main navigation">
${links.map(l=>`<li><a href="${l.href}" class="${currentPage===l.href?'active':''}">${l.icon} ${l.label}</a></li>`).join('')}
<li><a href="tools.html#chat" class="nav-cta">💬 Talk Now</a></li>
</ul>
<div class="nav-end">
<button class="icon-btn" id="themeBtn" onclick="toggleTheme()" aria-label="Toggle light/dark mode">🌙</button>
<button class="icon-btn nav-toggle" id="navToggle" onclick="toggleMobileNav()" aria-label="Toggle menu" aria-expanded="false">☰</button>
</div>
</div>
</div>
<nav class="nav-mobile" id="navMobile" aria-label="Mobile navigation">
${links.map(l=>`<a href="${l.href}" class="${currentPage===l.href?'active':''}">${l.icon} ${l.label}</a>`).join('')}
<a href="tools.html#chat" style="background:var(--accent);color:#fff;border-color:var(--accent)">💬 Talk to AI Companion</a>
</nav>`;
const footerHTML = `
<div class="crisis-strip page-wrap reveal">
<span style="font-size:1.4rem;flex-shrink:0">🆘</span>
<p>In crisis or having thoughts of self-harm? Call <strong>988</strong> (US) or <strong>116 123</strong> (UK) — free, 24/7, confidential.
<a href="resources.html" style="color:var(--accent2);margin-left:8px;font-weight:600">All helplines →</a></p>
</div>
<footer class="site-footer" role="contentinfo">
<div class="footer-inner">
<div class="footer-brand">
<a class="nav-logo" href="index.html">MindLift</a>
<p>A safe space to breathe, reflect, and find support. Built with compassion for everyone who is struggling.</p>
</div>
<div class="footer-col">
<h4>Tools</h4>
<a href="tools.html#breathe">Breathing Exercises</a>
<a href="tools.html#mood">Mood Tracker</a>
<a href="tools.html#journal">Gratitude Journal</a>
<a href="tools.html#quiz">Self-Assessment</a>
<a href="tools.html#chat">AI Companion</a>
</div>
<div class="footer-col">
<h4>Learn</h4>
<a href="articles.html">All Articles</a>
<a href="articles.html#anxiety">Anxiety</a>
<a href="articles.html#depression">Depression</a>
<a href="articles.html#selfcare">Self-Care</a>
<a href="articles.html#therapy">Therapy</a>
</div>
<div class="footer-col">
<h4>Support</h4>
<a href="resources.html">Crisis Helplines</a>
<a href="resources.html#find">Find a Therapist</a>
<a href="resources.html#community">Community</a>
<a href="about.html">About MindLift</a>
<a href="about.html#disclaimer">Disclaimer</a>
</div>
</div>
<div class="footer-bottom">
<p>© 2026 MindLift — Your mental health matters.</p>
<p>Not a substitute for professional medical advice. <a href="about.html#disclaimer">Read disclaimer</a></p>
</div>
</footer>`;
// Inject nav before body content
document.body.insertAdjacentHTML('afterbegin', navHTML);
document.body.insertAdjacentHTML('beforeend', footerHTML);
// Theme
window.toggleTheme = function () {
const isLight = document.documentElement.getAttribute('data-theme') === 'light';
document.documentElement.setAttribute('data-theme', isLight ? 'dark' : 'light');
document.getElementById('themeBtn').textContent = isLight ? '🌙' : '☀️';
localStorage.setItem('ml_theme', isLight ? 'dark' : 'light');
};
const saved = localStorage.getItem('ml_theme');
if (saved === 'light') {
document.documentElement.setAttribute('data-theme', 'light');
setTimeout(() => { const b = document.getElementById('themeBtn'); if (b) b.textContent = '☀️'; }, 0);
}
// Mobile nav
window.toggleMobileNav = function () {
const m = document.getElementById('navMobile');
const t = document.getElementById('navToggle');
const open = m.classList.toggle('open');
t.textContent = open ? '✕' : '☰';
t.setAttribute('aria-expanded', open);
};
document.addEventListener('click', e => {
const m = document.getElementById('navMobile');
const t = document.getElementById('navToggle');
const w = document.querySelector('.nav-wrapper');
if (m && m.classList.contains('open') && !m.contains(e.target) && !w.contains(e.target)) {
m.classList.remove('open');
t.textContent = '☰';
}
});
// Scroll reveal
const io = new IntersectionObserver(entries => {
entries.forEach(e => { if (e.isIntersecting) e.target.classList.add('in'); });
}, { threshold: 0.1 });
const observe = () => document.querySelectorAll('.reveal').forEach(el => io.observe(el));
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', observe);
else observe();
// Smooth hash scroll
document.addEventListener('click', e => {
const a = e.target.closest('a[href*="#"]');
if (!a) return;
const [pagePart, hashPart] = a.getAttribute('href').split('#');
const currentFile = location.pathname.split('/').pop() || 'index.html';
if ((!pagePart || pagePart === currentFile) && hashPart) {
const target = document.getElementById(hashPart);
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
});
})();