source: Klonkt/src/views/partials/topnav.ejs@ 7bc636b

main
Last change on this file since 7bc636b was 7bc636b, checked in by Robin <robin@…>, 4 months ago

Initial commit — PrutFolio v1 source (pulled from Hetzner /srv/prutfolio)

  • Property mode set to 100644
File size: 19.2 KB
Line 
1<%
2// Top nav — RESPONSIVE.
3//
4// Mobile (<768px):
5// - Brand centered, small theme-toggle right.
6// - All other actions live in the bottom-tab nav.
7// - Sticky top, blur background, safe-area-top respected.
8//
9// Desktop (≥768px):
10// - Full v9 masthead: brand left, action row right
11// (Archief / Search / Install / Theme / Prutter / User-menu).
12// - bottom-tab is hidden via CSS, so all nav must live here.
13
14const _siteUrlBase = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
15const _isAdmin = typeof bodyClass !== 'undefined' && bodyClass.indexOf('on-admin') >= 0;
16const _hasSearch = !site || site.show_search === undefined || site.show_search;
17const _hasPrutter = user && site && site.enable_prutter;
18const _canPost = user && permissions && permissions.canCreatePost && permissions.canCreatePost(user, site);
19%>
20
21<header class="masthead">
22 <div class="container masthead-inner">
23
24 <!-- Brand block (always visible) -->
25 <div class="masthead-brand">
26 <% if (_isAdmin) { %>
27 <a href="<%= _siteUrlBase %>/" class="nav-link nav-link-admin">← Terug naar site</a>
28 <% } else if (site) { %>
29 <a class="site-title" href="<%= _siteUrlBase %>/"
30 hx-get="<%= _siteUrlBase %>/?partial=1" hx-target="#pcms-main" hx-swap="innerHTML"
31 hx-push-url="<%= _siteUrlBase %>/" hx-indicator="#pcms-loading"><%= site.title %></a>
32 <% } else { %>
33 <a class="site-title" href="/">PrutFolio</a>
34 <% } %>
35 </div>
36
37 <!-- Mobile: theme toggle ONLY for logged-out users.
38 Logged-in users get the toggle inside the profile sheet
39 (bottom-tab → Profiel → Thema). All other actions in bottom-tab. -->
40 <% if (!user) { %>
41 <div class="top-nav-mobile">
42 <button type="button" class="nav-btn" id="theme-toggle-mobile" aria-label="Thema wisselen" title="Thema wisselen">
43 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>
44 </button>
45 </div>
46 <% } %>
47
48 <!-- Desktop-only: full action row -->
49 <nav class="top-nav top-nav-desktop" aria-label="Hoofdnavigatie">
50
51 <% if (!_isAdmin) { %>
52 <a class="nav-link" href="<%= _siteUrlBase %>/archive"
53 hx-get="<%= _siteUrlBase %>/archive?partial=1" hx-target="#pcms-main"
54 hx-swap="innerHTML" hx-push-url="<%= _siteUrlBase %>/archive"
55 hx-indicator="#pcms-loading">
56 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 8v13H3V8"/><rect x="1" y="3" width="22" height="5" rx="1"/><line x1="10" y1="12" x2="14" y2="12"/></svg>
57 <span class="nav-label">Archief</span>
58 </a>
59 <% } %>
60
61 <% if (_hasSearch) { %>
62 <button type="button" class="nav-btn" id="search-toggle" aria-label="Zoeken" title="Zoeken">
63 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
64 </button>
65 <% } %>
66
67 <button type="button" class="nav-btn" id="pwa-install-btn" hidden aria-label="App installeren" title="App installeren">
68 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
69 </button>
70
71 <button type="button" class="nav-btn" id="theme-toggle" aria-label="Thema wisselen" title="Thema wisselen">
72 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.41-1.41M17.66 6.34l1.41-1.41"/></svg>
73 </button>
74
75 <% if (_hasPrutter) { %>
76 <a class="nav-btn" href="<%= _siteUrlBase %>/prutter" aria-label="Prutter (DMs)" title="Prutter">
77 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>
78 </a>
79 <% } %>
80
81 <% if (user) { %>
82 <details class="user-menu">
83 <summary class="nav-btn user-toggle" aria-label="Gebruikersmenu">
84 <% if (user.avatar_url) { %>
85 <img class="user-avatar user-avatar-img" src="<%= user.avatar_url %>" alt="">
86 <% } else { %>
87 <span class="user-avatar"><%= user.username.charAt(0).toUpperCase() %></span>
88 <% } %>
89 </summary>
90 <div class="user-dropdown" role="menu">
91 <div class="user-dropdown-header">
92 <% if (user.avatar_url) { %>
93 <img class="udh-avatar" src="<%= user.avatar_url %>" alt="">
94 <% } else { %>
95 <span class="udh-avatar udh-avatar-fallback"><%= user.username.charAt(0).toUpperCase() %></span>
96 <% } %>
97 <div class="udh-meta">
98 <span class="udh-name"><%= user.username %></span>
99 <% if (user.role === 'god') { %>
100 <span class="udh-role">Admin</span>
101 <% } else if (user.role === 'admin' || user.role === 'moderator') { %>
102 <span class="udh-role"><%= user.role.charAt(0).toUpperCase() + user.role.slice(1) %></span>
103 <% } %>
104 </div>
105 </div>
106 <div class="user-dropdown-list">
107 <a href="/account" role="menuitem" class="udi">
108 <svg class="udi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
109 <span>Account</span>
110 </a>
111 <% if (user.role === 'god' || user.role === 'admin') { %>
112 <a href="/admin" role="menuitem" class="udi">
113 <svg class="udi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 3h7v7H3z"/><path d="M14 3h7v7h-7z"/><path d="M14 14h7v7h-7z"/><path d="M3 14h7v7H3z"/></svg>
114 <span>Beheer</span>
115 </a>
116 <% } %>
117 <% if (_canPost) { %>
118 <a href="/posts/new" role="menuitem" class="udi"
119 hx-get="/posts/new?partial=1" hx-target="#pcms-main" hx-swap="innerHTML"
120 hx-push-url="/posts/new" hx-indicator="#pcms-loading">
121 <svg class="udi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5z"/></svg>
122 <span>Nieuwe post</span>
123 </a>
124 <% } %>
125 </div>
126 <div class="user-dropdown-divider" aria-hidden="true"></div>
127 <div class="user-dropdown-list">
128 <a href="/auth/logout" role="menuitem" class="udi udi-danger">
129 <svg class="udi-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
130 <span>Uitloggen</span>
131 </a>
132 </div>
133 </div>
134 </details>
135 <% } else { %>
136 <a class="nav-link" href="/auth/login">
137 <span class="nav-label">Inloggen</span>
138 </a>
139 <% } %>
140
141 </nav>
142 </div>
143</header>
144
145<!-- Search overlay (shared by mobile bottom-tab + desktop top-nav) -->
146<div id="search-overlay" class="search-overlay" hidden>
147 <div class="container">
148 <form class="search-overlay-form" method="get" action="<%= _siteUrlBase %>/search">
149 <input type="search" name="q" placeholder="Zoeken in posts…" autocomplete="off">
150 <button type="submit" class="nav-btn" aria-label="Zoeken">
151 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
152 </button>
153 <button type="button" class="nav-btn" id="search-close" aria-label="Sluiten">
154 <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
155 </button>
156 </form>
157 </div>
158</div>
159
160<script>
161(function() {
162 // Theme toggle (works for both mobile + desktop buttons)
163 function toggleTheme() {
164 const cur = document.documentElement.getAttribute('data-theme') || 'dark';
165 const next = cur === 'dark' ? 'light' : 'dark';
166 document.documentElement.setAttribute('data-theme', next);
167 try { localStorage.setItem('pcms-theme', next); } catch (e) {}
168 }
169 // Theme toggle — event delegation so it works for ANY button with the
170 // matching ids, even ones rendered later in the page (footer is below
171 // topnav in source order, so getElementById would have returned null
172 // when this IIFE ran).
173 document.body.addEventListener('click', function(e) {
174 const btn = e.target.closest(
175 '#theme-toggle, #theme-toggle-mobile, #theme-toggle-footer'
176 );
177 if (btn) toggleTheme();
178 });
179
180 // Search overlay
181 const overlay = document.getElementById('search-overlay');
182 document.getElementById('search-toggle')?.addEventListener('click', function() {
183 if (overlay) {
184 overlay.hidden = false;
185 const inp = overlay.querySelector('input');
186 if (inp) inp.focus();
187 }
188 });
189 document.getElementById('search-close')?.addEventListener('click', function() {
190 if (overlay) overlay.hidden = true;
191 });
192 document.addEventListener('keydown', function(e) {
193 if (e.key === 'Escape' && overlay && !overlay.hidden) overlay.hidden = true;
194 });
195
196 // Close user dropdown on outside click
197 document.addEventListener('click', function(e) {
198 const open = document.querySelector('.user-menu[open]');
199 if (open && !open.contains(e.target)) open.removeAttribute('open');
200 });
201})();
202</script>
203
204<style>
205/* ============================================================
206 TOP-NAV — responsive
207 Mobile: brand centered, small theme btn right, NOTHING else.
208 Desktop (≥768px): full v9 layout — brand left, action row right.
209 ============================================================ */
210
211.masthead-inner {
212 /* Override v9's flex-end → space-between so brand is on the left */
213 justify-content: space-between !important;
214 gap: 1rem;
215}
216.masthead-brand .site-title,
217.masthead-brand .nav-link-admin {
218 display: inline-block;
219 vertical-align: middle;
220}
221
222/* Site title is suppressed everywhere — the profile-header carries the brand
223 on content pages, and admin pages have their own "← Terug naar site" link
224 (a different selector, .nav-link-admin, which stays visible). The masthead
225 becomes a thin utility strip with just theme-toggle / search / etc. */
226.masthead-brand .site-title {
227 display: none;
228}
229
230/* On mobile, hide the entire masthead except for admin pages. The brand
231 appears in the profile-header on content pages, and the bottom-tab
232 provides all navigation. Admin keeps it because the "← Terug naar site"
233 link is the only way back to the public site from /admin/*. */
234@media (max-width: 767px) {
235 body:not(.on-admin) .masthead { display: none; }
236}
237
238/* On mobile, center the brand in the masthead */
239@media (max-width: 767px) {
240 .masthead-inner {
241 justify-content: center !important;
242 position: relative;
243 }
244 .masthead-brand {
245 text-align: center;
246 }
247 /* Lone theme button for logged-out users — minimal, icon-only,
248 no border/background to avoid the iOS sticky-hover look. */
249 .top-nav-mobile {
250 position: absolute;
251 right: 0;
252 top: 50%;
253 transform: translateY(-50%);
254 }
255 .top-nav-mobile .nav-btn {
256 width: 44px;
257 height: 44px;
258 padding: 0;
259 background: transparent !important;
260 border-color: transparent !important;
261 color: var(--ink-soft);
262 display: inline-flex;
263 align-items: center;
264 justify-content: center;
265 }
266 .top-nav-mobile .nav-btn:active {
267 transform: scale(0.92);
268 color: var(--ink);
269 }
270 /* Suppress sticky hover on touch — only show feedback for real hover devices */
271 @media (hover: none) {
272 .top-nav-mobile .nav-btn:hover {
273 background: transparent !important;
274 border-color: transparent !important;
275 color: var(--ink-soft);
276 }
277 }
278 .top-nav-desktop {
279 display: none !important;
280 }
281}
282
283/* On desktop, hide the mobile-only theme button */
284@media (min-width: 768px) {
285 .top-nav-mobile { display: none; }
286}
287
288/* ── Admin "back" link styling (inherited from v9 patterns) ── */
289.nav-link-admin {
290 background: var(--accent);
291 color: #fff !important;
292 padding: .5rem .85rem;
293 border-radius: 6px;
294 text-decoration: none;
295 font-family: var(--font-ui);
296 font-size: .875rem;
297 font-weight: 500;
298}
299.nav-link-admin:hover { opacity: .9; color: #fff !important; }
300
301/* ── Tap-target enforcement for all nav buttons on touch ── */
302@media (hover: none) {
303 .nav-btn, .nav-link {
304 min-height: 44px;
305 min-width: 44px;
306 }
307 .nav-btn:active {
308 transform: scale(0.95);
309 background: var(--paper-2);
310 }
311}
312
313/* ── User dropdown (desktop only — mobile uses bottom-tab → /account) ── */
314.user-menu { position: relative; list-style: none; }
315.user-menu > summary {
316 list-style: none; cursor: pointer;
317 padding: .25rem; border-radius: 6px;
318 display: inline-flex; align-items: center;
319 border: 1px solid transparent;
320 transition: all var(--transition);
321}
322.user-menu > summary::-webkit-details-marker { display: none; }
323.user-menu > summary::marker { content: ''; }
324.user-menu > summary:hover { background: var(--paper-2); border-color: var(--rule); }
325.user-avatar {
326 display: inline-flex; align-items: center; justify-content: center;
327 width: 28px; height: 28px; border-radius: 50%;
328 background: var(--paper-2); /* neutral so transparent avatars blend */
329 color: var(--accent); /* fallback initial color */
330 font-family: var(--font-ui); font-weight: 600; font-size: .8rem;
331 pointer-events: none;
332 overflow: hidden;
333}
334.user-avatar-img {
335 /* When the pill renders as <img> instead of <span>, fill it edge-to-edge. */
336 object-fit: cover;
337}
338.user-dropdown {
339 position: absolute; top: calc(100% + .55rem); right: 0;
340 min-width: 220px;
341 padding: .35rem;
342 background: color-mix(in srgb, var(--paper) 92%, transparent);
343 backdrop-filter: blur(14px) saturate(180%);
344 -webkit-backdrop-filter: blur(14px) saturate(180%);
345 border: 1px solid var(--rule);
346 border-radius: 12px;
347 box-shadow:
348 0 1px 2px color-mix(in srgb, var(--ink) 8%, transparent),
349 0 8px 24px color-mix(in srgb, var(--ink) 14%, transparent),
350 0 16px 48px color-mix(in srgb, var(--ink) 10%, transparent);
351 z-index: 200;
352 font-family: var(--font-ui);
353 transform-origin: top right;
354}
355/* Open animation — only fires when <details open> matches, so closing the
356 dropdown doesn't replay the entry animation. */
357.user-menu[open] > .user-dropdown {
358 animation: ud-fade-in .14s cubic-bezier(.2, .8, .25, 1);
359}
360@keyframes ud-fade-in {
361 from { opacity: 0; transform: translateY(-6px) scale(.98); }
362 to { opacity: 1; transform: translateY(0) scale(1); }
363}
364
365/* Identity header — small avatar + username/role badge */
366.user-dropdown-header {
367 display: flex; align-items: center; gap: .65rem;
368 padding: .55rem .65rem .65rem;
369 border-bottom: 1px solid color-mix(in srgb, var(--rule) 65%, transparent);
370 margin-bottom: .35rem;
371}
372.udh-avatar {
373 width: 36px; height: 36px; border-radius: 50%;
374 object-fit: cover;
375 background: var(--paper-2);
376 display: inline-flex; align-items: center; justify-content: center;
377 flex-shrink: 0;
378}
379.udh-avatar-fallback {
380 color: var(--accent); font-weight: 700; font-size: .95rem;
381}
382.udh-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
383.udh-name {
384 font-weight: 600; font-size: .92rem; color: var(--ink);
385 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px;
386}
387.udh-role {
388 font-size: .68rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
389 color: var(--accent); opacity: .85; margin-top: .12rem;
390}
391
392/* Item list group */
393.user-dropdown-list { display: flex; flex-direction: column; gap: 1px; }
394.user-dropdown-divider {
395 height: 1px;
396 margin: .35rem .25rem;
397 background: color-mix(in srgb, var(--rule) 60%, transparent);
398}
399
400/* Items — icon + label, rounded inner highlight on hover (macOS feel) */
401.user-dropdown .udi {
402 display: flex; align-items: center; gap: .65rem;
403 padding: .5rem .65rem;
404 color: var(--ink); text-decoration: none;
405 font-size: .88rem; font-weight: 500;
406 border-radius: 7px;
407 transition: background var(--transition), color var(--transition), transform var(--transition);
408}
409.user-dropdown .udi:hover,
410.user-dropdown .udi:focus-visible {
411 background: color-mix(in srgb, var(--accent) 10%, var(--paper-2));
412 color: var(--accent);
413 outline: none;
414}
415.user-dropdown .udi:active { transform: scale(.98); }
416.user-dropdown .udi-icon {
417 width: 16px; height: 16px;
418 opacity: .7;
419 flex-shrink: 0;
420 transition: opacity var(--transition);
421}
422.user-dropdown .udi:hover .udi-icon,
423.user-dropdown .udi:focus-visible .udi-icon { opacity: 1; }
424
425/* Logout: subtle danger tint on hover, never on rest. Uses a fixed red so
426 it always reads as a destructive action even if the user's accent is red. */
427.user-dropdown .udi-danger:hover,
428.user-dropdown .udi-danger:focus-visible {
429 background: color-mix(in srgb, #dc2626 14%, var(--paper-2));
430 color: #dc2626;
431}
432
433/* ── Search overlay ── */
434.search-overlay {
435 position: fixed; top: 0; left: 0; right: 0;
436 background: color-mix(in srgb, var(--paper) 96%, transparent);
437 backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
438 border-bottom: 1px solid var(--rule);
439 padding: 1rem 0; z-index: 200;
440 padding-top: calc(1rem + env(safe-area-inset-top, 0));
441 box-shadow: 0 8px 24px color-mix(in srgb, var(--ink) 8%, transparent);
442}
443.search-overlay-form { display: flex; gap: .5rem; align-items: center; }
444.search-overlay-form input {
445 flex: 1; padding: .85rem 1rem;
446 min-height: 44px;
447 border: 1px solid var(--rule); border-radius: 8px;
448 font-family: var(--font-ui); font-size: 1rem;
449 background: var(--paper); color: var(--ink);
450}
451.search-overlay-form input:focus {
452 outline: 2px solid var(--accent); outline-offset: 0;
453}
454.search-overlay-form .nav-btn {
455 width: 44px; height: 44px;
456 display: inline-flex; align-items: center; justify-content: center;
457}
458</style>
Note: See TracBrowser for help on using the repository browser.