source: Klonkt/src/views/partials/topnav.ejs@ 0c2228a

main
Last change on this file since 0c2228a was 0c2228a, checked in by roboburr <roboburr@…>, 3 months ago

hub: home button actually visible + delete for every user (cascade)

  • topnav: the hub-home brand used .site-title, which is display:none everywhere (the profile header carries the name). Now its own visible class .nav-hub-home -> the hub name is truly shown top-left on /user/ pages, linking to the hub home.
  • admin/users: delete button for EVERY user (except yourself), not only empty accounts. Deletion cascades (sites + posts + playlists + audio + members + comments) atomically in a transaction; god-only, not the last god, not yourself. Confirmation warns when content will be removed.

Co-Authored-By: Claude <noreply@…>

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