source: Klonkt/src/views/partials/topnav.ejs@ 05a6ca0

main
Last change on this file since 05a6ca0 was 42081fb, checked in by roboburr <roboburr@…>, 3 months ago

hub: home button on user sites — masthead brand becomes the hub name -> hub home

On /user/<artist> pages the masthead now shows the HUB name (hub_title)
top-left, linking to the hub home (/) — a clear home button. The artist
name remains in the profile header below. Not on the overview (the name
is already in the hero there). hubTitle comes from render.js (getSetting).

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

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