source: Klonkt/src/views/partials/topnav.ejs@ ec2e358

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

Prutter = premium Hub feature: Hub-only + behind premium gate

Prutter (DMs) is now hard-scoped to Hub mode (route 404s outside hub) and
locked behind the premium gate via the new premiumUnlocked() (= premium off
→ freely available, demos keep working; premium on → Patreon required).
UI entry points (topnav/bottom-tab/Send DM) follow the same condition.
Added to the premium description in Admin → Settings.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

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