source: Klonkt/src/views/shell.ejs@ aadb11e

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

Fediverse UI: one ⭐ like, transparent circle logos, accent-following Klonkt gradient

  • Merge the duplicate ⭐ like: drop the post-header like-button; the 'From the fediverse' section now always shows and its ⭐ is the clickable like (with count).
  • Circle-feed avatar: transparent background behind a logo image (accent stays only for the letter fallback) — fixes the accent showing through transparent logos.
  • Klonkt palette now uses the generic accent glow so its background gradient follows the chosen accent (dropped the hard-coded navy override). style.css?v=47.

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

  • Property mode set to 100644
File size: 30.9 KB
Line 
1<%
2// ── Helpers used inside this template ─────────────────────────────
3function _e(s) {
4 return String(s == null ? '' : s)
5 .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
6 .replace(/"/g, '&quot;').replace(/'/g, '&#39;');
7}
8
9const safeSite = site || {};
10const safeUrlBase = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
11const safeAccent = safeSite.accent && /^#[0-9a-fA-F]{6}$/.test(safeSite.accent) ? safeSite.accent : '#e8b04b';
12const lang = safeSite.language || 'nl';
13const ogLocale = safeSite.og_locale || (lang === 'nl' ? 'nl_NL' : (lang.length === 2 ? lang + '_' + lang.toUpperCase() : 'en_US'));
14const homePath = safeUrlBase + '/';
15const isPostPage = bodyClass && bodyClass.indexOf('on-post') >= 0;
16const isHomePage = bodyClass && bodyClass.indexOf('on-home') >= 0;
17const isSpecialPg = bodyClass && bodyClass.indexOf('on-special') >= 0;
18const isAdminPage = bodyClass && bodyClass.indexOf('on-admin') >= 0;
19
20// ── <title> via site.title_template ──────────────────────────────
21// Template: '{title} — {site}'. If pageTitle equals site.title (homepage) we
22// just use the site title alone, otherwise apply the template.
23const _siteTitle = safeSite.title || 'Klonkt';
24const _rawTitle = pageTitle || _siteTitle;
25const _tpl = safeSite.title_template || '{title} — {site}';
26const _finalTitle = (_rawTitle === _siteTitle)
27 ? _siteTitle
28 : _tpl.replace('{title}', _rawTitle).replace('{site}', _siteTitle);
29
30// ── Robots: noindex on listing pages and on per-post override ─────
31let _shouldIndex = safeSite.robots_index !== 0;
32if (typeof post !== 'undefined' && post && post.noindex) _shouldIndex = false;
33// Listing pages (search/tag/type/archive) shouldn't be indexed (dupe content)
34if (currentPath) {
35 if (/^\/(?:search|tag|type|archive|users|account|admin)(?:$|\/)/.test(currentPath)) {
36 _shouldIndex = false;
37 }
38}
39// Special-flagged views from routes opt out too
40if (isSpecialPg && (currentPath === '/search' || /^\/(tag|type|archive|users)\//.test(currentPath))) {
41 _shouldIndex = false;
42}
43
44// ── Canonical URL (only when we have one configured) ─────────────
45let _canonical = null;
46if (safeSite.canonical) {
47 const _base = safeSite.canonical.replace(/\/+$/, '');
48 let _path = '/';
49 if (typeof post !== 'undefined' && post && post.slug) _path = '/' + post.slug;
50 else if (currentPath) _path = currentPath;
51 _canonical = _base + _path;
52}
53
54// ── Social bits (OG/Twitter) ──────────────────────────────────────
55const _socialTitle = (typeof post !== 'undefined' && post && post.title) ? post.title : _siteTitle;
56const _socialDescr = (typeof socialDescr !== 'undefined' && socialDescr)
57 ? socialDescr
58 : (safeSite.default_description || safeSite.description || '');
59// og:image — custom (post/site) first; otherwise the auto-generated themed card
60// (/og/<slug>.png), so every site has a branded social preview by default.
61let _socialImage = '', _ogGenerated = false;
62if (typeof socialImage !== 'undefined' && socialImage) _socialImage = socialImage;
63else if (safeSite.og_image_default) _socialImage = safeSite.og_image_default;
64else if (safeSite.default_cover) _socialImage = safeSite.default_cover;
65else if (safeSite.slug && typeof ogOrigin !== 'undefined' && ogOrigin) {
66 _socialImage = ogOrigin + '/og/' + encodeURIComponent(safeSite.slug) + '.png';
67 _ogGenerated = true;
68}
69const _ogType = isPostPage ? 'article' : 'website';
70
71// ── JSON-LD ───────────────────────────────────────────────────────
72const _publisher = {
73 '@type': safeSite.schema_type === 'Organization' ? 'Organization' : 'Person',
74 name: safeSite.publisher_name || _siteTitle,
75 url: safeSite.publisher_url || (_canonical ? _canonical.split(/(?<=^[^/]*\/\/[^/]+)\//)[0] + '/' : null),
76};
77if (safeSite.publisher_logo) {
78 _publisher.logo = { '@type': 'ImageObject', url: safeSite.publisher_logo };
79}
80let _jsonLd = null;
81if (typeof post !== 'undefined' && post && post.slug) {
82 _jsonLd = {
83 '@context': 'https://schema.org',
84 '@type': (post.type === 'foto' || post.type === 'video') ? 'CreativeWork' : 'Article',
85 headline: post.title || _siteTitle,
86 description: _socialDescr,
87 datePublished: post.published_at || post.created_at || new Date().toISOString(),
88 dateModified: post.updated_at || post.published_at || new Date().toISOString(),
89 publisher: _publisher,
90 };
91 if (_socialImage) _jsonLd.image = _socialImage;
92 if (post.author_username) _jsonLd.author = { '@type': 'Person', name: post.author_username };
93 if (Array.isArray(post.tags) && post.tags.length) _jsonLd.keywords = post.tags.join(', ');
94} else if (isHomePage) {
95 _jsonLd = {
96 '@context': 'https://schema.org',
97 '@type': 'WebSite',
98 name: _siteTitle,
99 description: safeSite.description || safeSite.default_description || '',
100 publisher: _publisher,
101 };
102}
103%><!DOCTYPE html>
104<html lang="<%= _e(lang) %>" data-palette="<%= _e((typeof palette !== 'undefined' && palette) ? palette : (safeSite.palette || 'klonkt')) %>">
105<head>
106<meta charset="utf-8">
107<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
108<meta name="color-scheme" content="dark light">
109
110<title><%= _finalTitle %></title>
111<meta name="description" content="<%= _e(_socialDescr) %>">
112<meta name="theme-color" content="<%= _e(safeAccent) %>">
113<meta name="robots" content="<%= _shouldIndex ? 'index,follow' : 'noindex,nofollow' %>">
114<% if (safeSite.author) { %><meta name="author" content="<%= _e(safeSite.author) %>"><% } %>
115<% if (_canonical) { %><link rel="canonical" href="<%= _e(_canonical) %>"><% } %>
116
117<!-- Search-engine verification -->
118<% if (safeSite.google_verification) { %><meta name="google-site-verification" content="<%= _e(safeSite.google_verification) %>"><% } %>
119<% if (safeSite.bing_verification) { %><meta name="msvalidate.01" content="<%= _e(safeSite.bing_verification) %>"><% } %>
120<% if (safeSite.pinterest_verification) { %><meta name="p:domain_verify" content="<%= _e(safeSite.pinterest_verification) %>"><% } %>
121<% if (safeSite.yandex_verification) { %><meta name="yandex-verification" content="<%= _e(safeSite.yandex_verification) %>"><% } %>
122
123<!-- Feed autodiscovery -->
124<% if (site) { %>
125<link rel="alternate" type="application/rss+xml" title="<%= _e(_siteTitle) %> — RSS" href="<%= _e(safeUrlBase + '/feed.xml') %>">
126<link rel="alternate" type="application/atom+xml" title="<%= _e(_siteTitle) %> — Atom" href="<%= _e(safeUrlBase + '/atom.xml') %>">
127<% } %>
128
129<!-- PWA -->
130<link rel="manifest" href="<%= _e(safeUrlBase + '/manifest.webmanifest') %>">
131<meta name="mobile-web-app-capable" content="yes">
132<meta name="apple-mobile-web-app-capable" content="yes">
133<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
134<meta name="apple-mobile-web-app-title" content="<%= _e(_siteTitle.slice(0, 16)) %>">
135<link rel="apple-touch-icon" href="<%= _e(safeSite.profile_photo || '/favicon.ico') %>">
136<link rel="icon" type="image/svg+xml" href="/favicon.svg?v=sf">
137<link rel="alternate icon" href="/favicon.ico?v=sf">
138
139<!-- OpenGraph -->
140<meta property="og:type" content="<%= _ogType %>">
141<meta property="og:title" content="<%= _e(_socialTitle) %>">
142<meta property="og:description" content="<%= _e(_socialDescr) %>">
143<meta property="og:site_name" content="<%= _e(_siteTitle) %>">
144<meta property="og:locale" content="<%= _e(ogLocale) %>">
145<% if (_socialImage) { %>
146<meta property="og:image" content="<%= _e(_socialImage) %>">
147<meta property="og:image:alt" content="<%= _e(_socialTitle) %>">
148<% if (_ogGenerated) { %>
149<meta property="og:image:width" content="1200">
150<meta property="og:image:height" content="630">
151<meta property="og:image:type" content="image/png">
152<% } %>
153<% } %>
154<% if (_canonical) { %><meta property="og:url" content="<%= _e(_canonical) %>"><% } %>
155<% if (typeof post !== 'undefined' && post && post.published_at) { %>
156<meta property="article:published_time" content="<%= _e(post.published_at) %>">
157<% if (post.author_username) { %><meta property="article:author" content="<%= _e(post.author_username) %>"><% } %>
158<% } %>
159<% if (safeSite.facebook_app_id) { %><meta property="fb:app_id" content="<%= _e(safeSite.facebook_app_id) %>"><% } %>
160
161<!-- Twitter Cards -->
162<meta name="twitter:card" content="<%= _socialImage ? 'summary_large_image' : 'summary' %>">
163<meta name="twitter:title" content="<%= _e(_socialTitle) %>">
164<meta name="twitter:description" content="<%= _e(_socialDescr) %>">
165<% if (_socialImage) { %><meta name="twitter:image" content="<%= _e(_socialImage) %>"><% } %>
166<% if (safeSite.twitter) { %><meta name="twitter:creator" content="<%= _e(safeSite.twitter) %>"><meta name="twitter:site" content="<%= _e(safeSite.twitter) %>"><% } %>
167
168<% if (_jsonLd) { %>
169<script type="application/ld+json"><%- JSON.stringify(_jsonLd) %></script>
170<% } %>
171
172<!-- Self-hosted fonts (privacy-first) -->
173<link rel="preload" href="/assets/fonts/literata-latin-opsz-normal.woff2" as="font" type="font/woff2" crossorigin>
174<link rel="preload" href="/assets/fonts/fraunces-latin-full-normal.woff2" as="font" type="font/woff2" crossorigin>
175
176<!-- v9 stylesheet (full palette system) -->
177<link rel="stylesheet" href="/assets/css/style.css?v=47">
178
179<!-- Audio player styles: loaded on every page so the mini-player works
180 anywhere (admin previews, post embeds, etc). The player itself is
181 a singleton — see the script tag near </body>. -->
182<link rel="stylesheet" href="/assets/css/audio.css?v=11">
183<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) in huisstijl. -->
184<link rel="stylesheet" href="/assets/css/embed.css?v=8">
185
186<%- include('partials/shared-styles') %>
187
188<!-- v1 P55 — Inline the saved site accent. The base stylesheet only sets a
189 fallback (#c2410c orange) and palette blocks don't define --accent at
190 all, so without this override the saved accent never reaches the page.
191 :root + [data-palette] hits both unscoped and palette-scoped variants;
192 source-order wins on equal specificity, and this comes after style.css. -->
193<style id="pcms-site-accent">
194 :root,
195 [data-palette] {
196 --accent: <%= _e(safeAccent) %>;
197 --accent-soft: color-mix(in srgb, <%= _e(safeAccent) %> 80%, white);
198 --accent-tint: color-mix(in srgb, <%= _e(safeAccent) %> 12%, transparent);
199 }
200</style>
201
202<!-- Per-site custom CSS injection -->
203<% if (safeSite.custom_css) { %>
204<style id="pcms-custom-css"><%- safeSite.custom_css %></style>
205<% } %>
206
207<!-- Apply theme ASAP, before paint. Precedence (first match wins):
208 1. localStorage override (visitor toggled earlier on this browser)
209 2. Site default (theme_override + palette) — what new visitors see
210 3. Device prefers-color-scheme (only if site default is empty/auto)
211 4. 'dark' as last-ditch fallback
212 Note: PALETTE never has a localStorage layer anymore. There's no UI for
213 visitors to pick a palette, so any cached pcms-palette is stale data
214 from old code paths and gets cleaned up here. Site default always wins
215 for palette. -->
216<script>
217 (function() {
218 try {
219 var siteDefault = '<%= safeSite.theme_override || "" %>';
220 var sitePalette = '<%= (typeof palette !== 'undefined' && palette) ? palette : (safeSite.palette || 'klonkt') %>';
221
222 // One-time cleanup: drop the orphan pcms-palette key set by P43-P57
223 // bootstrap. After this it never re-appears because nothing writes it.
224 try { localStorage.removeItem('pcms-palette'); } catch(_) {}
225
226 // Theme: localStorage > site override > device pref > dark
227 var storedTheme = null;
228 try { storedTheme = localStorage.getItem('pcms-theme'); } catch(_) {}
229 var deviceDark = window.matchMedia &&
230 window.matchMedia('(prefers-color-scheme: dark)').matches;
231 var t = storedTheme
232 || siteDefault
233 || (deviceDark ? 'dark' : 'light');
234
235 // Palette: site default only.
236 document.documentElement.setAttribute('data-theme', t);
237 document.documentElement.setAttribute('data-palette', sitePalette);
238 } catch(e) {
239 document.documentElement.setAttribute('data-theme', 'dark');
240 }
241 })();
242</script>
243
244<!-- HTMX — bundled locally from node_modules at boot, zero third-party requests -->
245<script src="/assets/js/htmx.min.js"></script>
246
247<!-- Per-site custom <head> HTML (analytics, verification, etc.) -->
248<% if (safeSite.custom_head_html) { %>
249<%- safeSite.custom_head_html %>
250<% } %>
251</head>
252
253<body class="<%= bodyClass || 'on-home' %> has-bottom-tab" data-feed-view="<%= _e(safeSite.feed_view_default || 'timeline') %>" data-grid-cols="3" data-site-base="<%= _e((typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '') %>">
254
255<% if (typeof isViewer !== 'undefined' && isViewer) { %>
256 <div class="viewer-banner" role="status">
257 <span class="viewer-banner-ico" aria-hidden="true">👁️</span>
258 <span class="viewer-banner-text"><strong>Kijker-modus</strong> — je kunt alles bekijken, maar niets wijzigen.</span>
259 </div>
260 <style>
261 .viewer-banner {
262 position: sticky; top: 0; z-index: 60;
263 display: flex; align-items: center; justify-content: center; gap: 0.5rem;
264 padding: 0.5rem 1rem;
265 background: linear-gradient(90deg,
266 color-mix(in srgb, var(--accent) 88%, #000) 0%,
267 var(--accent) 100%);
268 color: #fff;
269 font-size: 0.85rem; line-height: 1.3;
270 box-shadow: 0 1px 6px color-mix(in srgb, var(--accent) 45%, transparent);
271 }
272 .viewer-banner-ico { font-size: 1rem; }
273 .viewer-banner-text strong { font-weight: 700; }
274 </style>
275<% } %>
276
277<%# Site-chrome (topnav + profielkop + view-switcher) in één vaste slot #pcms-chrome.
278 Bij htmx-navigatie wordt dit slot out-of-band ververst (zie chrome.ejs +
279 render.js), zodat de kop ALTIJD bij de nieuwe pagina/artiest hoort terwijl de
280 audioplayer (los in document.body) blijft leven → geen verspringen. Op de
281 hub-landing is het slot leeg: de hero is daar de header. %>
282<%- include('partials/chrome') %>
283
284<%# Geen hx-history-elt: htmx' eigen history staat uit (zie de link-boost).
285 Back/forward wordt door onze popstate-listener gedaan, die de partial
286 her-fetcht (incl. correcte OOB-chrome). Met hx-history-elt + htmx-history
287 aan dumpte htmx de partial ongefilterd hier → dubbele kop. %>
288<main id="pcms-main" class="pcms-main">
289 <div id="pcms-loading" class="pcms-loading" aria-hidden="true"></div>
290 <%- pageContent %>
291</main>
292
293<%- include('partials/footer') %>
294
295<!-- Mobile bottom-tab navigation (auto-hidden ≥768px). Toont overal — óók op de
296 hub-landing (zodat mobiel altijd Home/Zoek/Inloggen heeft) — behalve op de
297 auth-focusschermen. -->
298<% if (!(typeof bodyClass === 'string' && bodyClass.indexOf('on-auth') >= 0)) { %>
299<%- include('partials/bottom-tab') %>
300<% } %>
301
302<!-- Mobile profile sheet (auto-hidden ≥768px; only rendered when logged in) -->
303<% if (user) { %>
304<%- include('partials/profile-sheet') %>
305<% } %>
306
307<!-- Audio player: load on every page (admin + public) so window.pcmsAudioPlayer
308 is always available. The PCMS_SITE_TRACKS bootstrap is still gated on
309 enable_audio_player since it's a public-page concept (auto-discovered
310 tracks from rendered post embeds).
311
312 ?v=N — cache-buster: bump bij elke audio-player.js wijziging zodat
313 Cloudflare (max-age=1y) niet de oude versie blijft serveren. -->
314<script src="/assets/js/audio-player.js?v=29"></script>
315<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) via de echte
316 player-API's + gedeelde mutual-exclusion registry met de site-speler. -->
317<script src="/assets/js/embed-player.js?v=16" defer></script>
318<% if (site && site.enable_audio_player && audioTracks && audioTracks.length > 0) { %>
319 <script>window.PCMS_SITE_TRACKS = <%- JSON.stringify(audioTracks) %>;</script>
320<% } %>
321
322<!-- Install-app button: detects platform + shows install instructions modal -->
323<script src="/assets/js/install-app.js?v=2" defer></script>
324
325<!-- Service Worker registration -->
326<script>
327 if ('serviceWorker' in navigator) {
328 navigator.serviceWorker.register('/sw.js').catch(() => {});
329 }
330</script>
331
332<!-- HTMX navigation: keep body class in sync with the swapped page.
333 The server emits HX-Trigger-After-Settle: { pcmsNav: { bodyClass } } via
334 renderPage() in middleware/render.js. Without this listener the body
335 class stays whatever the initial page-load set, so the profile-header
336 never collapses/expands when navigating home → post → home via HTMX. -->
337<script>
338(function() {
339 // De page-context body-classes. Bij pcmsNav strippen we ze allemaal en zetten
340 // we opnieuw wat de server stuurde. 'on-auth' staat erbij zodat het login-
341 // focusscherm óók via htmx z'n styling krijgt (geen chrome, geen tab, audio op 0).
342 var PAGE_CLASSES = ['on-home','on-post','on-special','on-archive','on-search','on-admin','on-auth',
343 'on-shows','on-downloads','on-download','on-epk','on-linkbio','on-newsletter',
344 'on-tag','on-type','on-user','on-cirkel','on-hub','on-chat'];
345
346 document.body.addEventListener('pcmsNav', function(ev) {
347 var d = ev.detail || {};
348 // Per-site accent + palette bijwerken (head wordt niet mee-geswapt bij htmx-nav,
349 // dus zonder dit erft een artiest de kleuren van de vorige pagina).
350 if (d.accent && /^#[0-9a-fA-F]{6}$/.test(d.accent)) {
351 var sa = document.getElementById('pcms-site-accent');
352 if (sa) {
353 sa.textContent =
354 ':root,[data-palette]{--accent:' + d.accent +
355 ';--accent-soft:color-mix(in srgb,' + d.accent + ' 80%,white)' +
356 ';--accent-tint:color-mix(in srgb,' + d.accent + ' 12%,transparent);}';
357 }
358 }
359 if (d.palette && /^[a-z0-9-]+$/i.test(d.palette)) {
360 document.documentElement.setAttribute('data-palette', d.palette);
361 }
362
363 var next = d.bodyClass;
364 if (!next) return;
365 // De server kan meerdere page-classes sturen ("on-special on-auth"). Strip
366 // alle bekende en zet ALLE meegestuurde page-classes terug (niet alleen de
367 // eerste) — anders mist 'on-auth' bij htmx-nav en blijft het login-scherm
368 // de chrome/tab van de vorige pagina houden.
369 var matched = String(next).split(/\s+/).filter(function(c) {
370 return PAGE_CLASSES.indexOf(c) >= 0;
371 });
372 if (!matched.length) return;
373 PAGE_CLASSES.forEach(function(c) { document.body.classList.remove(c); });
374 matched.forEach(function(c) { document.body.classList.add(c); });
375 });
376
377 // (Back/forward wordt afgehandeld door de popstate-listener in de link-boost
378 // hieronder — die her-fetcht de partial via htmx.ajax, wat de OOB-chrome +
379 // de pcmsNav-trigger (accent/palette/bodyClass) correct toepast. De vroegere
380 // htmx:historyRestore-handler is vervallen nu htmx-history uitstaat.)
381})();
382</script>
383
384<!-- View switcher + grid-cols persistence (event delegation: works for switcher
385 elements rendered later by HTMX, e.g. when navigating back to home). -->
386<script>
387(function() {
388 var body = document.body;
389 // Restore feed view + grid cols from localStorage (overrides server default)
390 try {
391 var v = localStorage.getItem('pcms-feed-view');
392 if (v === 'timeline' || v === 'grid') body.dataset.feedView = v;
393 var c = parseInt(localStorage.getItem('pcms-grid-cols'), 10);
394 if (c === 2 || c === 3 || c === 4) body.dataset.gridCols = String(c);
395 } catch (e) {}
396
397 function syncAria() {
398 // Alleen op een feed-pagina hoort Tijdlijn/Grid 'actief' (wit) te zijn; op
399 // agenda/downloads/post/etc. beide grijs. Inline feed-check (FEED_PAGE_CLASSES
400 // staat verderop, maar deze functie draait al bij init).
401 var _feedC = ['on-home','on-tag','on-type','on-user','on-cirkel'];
402 var _onFeed = _feedC.some(function(c){ return body.classList.contains(c); });
403 document.querySelectorAll('.view-switch-btn').forEach(function(b) {
404 b.setAttribute('aria-selected', (_onFeed && b.dataset.view === body.dataset.feedView) ? 'true' : 'false');
405 });
406 document.querySelectorAll('.grid-cols-btn').forEach(function(b) {
407 b.classList.toggle('is-active', b.dataset.cols === body.dataset.gridCols);
408 });
409 }
410 syncAria();
411 // Re-sync after HTMX brings in new content (e.g. navigating back to home).
412 // pcmsNav vuurt ná de body-class-update (zie de pcmsNav-listener hierboven), dus
413 // dáár weet syncAria de juiste pagina-class — los van de afterSettle-timing.
414 // Een vertraagde herhaling wint eventuele resterende races (OOB-chrome-swap).
415 document.body.addEventListener('htmx:afterSettle', function(){ syncAria(); setTimeout(syncAria, 60); });
416 document.body.addEventListener('pcmsNav', function(){ syncAria(); setTimeout(syncAria, 60); });
417
418 // Pages where the body actually has a feed to toggle. On these the
419 // click stays put — it just flips body[data-feed-view] and CSS does
420 // the rest. Anywhere else (post detail, account, search, auth) we
421 // navigate to home in the chosen view, so the switcher is never
422 // a dead control.
423 // NB: 'on-archive' staat hier bewust NIET tussen — op het archief is er geen
424 // in-place timeline/grid-toggle; een klik op de switcher springt terug naar de
425 // feed in de gekozen weergave (zie de !isFeedPage()-tak hieronder).
426 var FEED_PAGE_CLASSES = ['on-home', 'on-tag', 'on-type', 'on-user', 'on-cirkel'];
427 function isFeedPage() {
428 for (var i = 0; i < FEED_PAGE_CLASSES.length; i++) {
429 if (body.classList.contains(FEED_PAGE_CLASSES[i])) return true;
430 }
431 return false;
432 }
433
434 // Event delegation — single listener handles current and future buttons.
435 document.addEventListener('click', function(e) {
436 var sw = e.target.closest('.view-switch-btn');
437 if (sw) {
438 var view = sw.dataset.view;
439 body.dataset.feedView = view;
440 try { localStorage.setItem('pcms-feed-view', view); } catch(_) {}
441 syncAria();
442 // On non-feed pages the switcher acts as a navigation: take the
443 // user back to home in the chosen view. Use HTMX if available so
444 // the page transition matches the rest of the site's nav.
445 if (!isFeedPage()) {
446 // Naar de SITE-home in de gekozen view (siteUrlBase), niet de globale '/'
447 // — in hub is '/' de hub-overview, niet de tijdlijn van deze artiest.
448 var base = body.dataset.siteBase || '';
449 if (window.htmx) {
450 window.htmx.ajax('GET', base + '/?partial=1', { target: '#pcms-main', swap: 'innerHTML' });
451 history.pushState({}, '', base + '/');
452 } else {
453 location.href = base + '/';
454 }
455 }
456 return;
457 }
458 var gc = e.target.closest('.grid-cols-btn');
459 if (gc) {
460 body.dataset.gridCols = gc.dataset.cols;
461 try { localStorage.setItem('pcms-grid-cols', gc.dataset.cols); } catch(_) {}
462 syncAria();
463 }
464 });
465})();
466</script>
467
468<!-- Globale link-boost: alle interne navigatie-links lopen via htmx in #pcms-main,
469 zodat de audioplayer (los in document.body) blijft spelen i.p.v. te verspringen
470 bij een full page-load. Werkt overal — Beheer, Account, posts, sites — zonder
471 elke link los htmx te maken. Links die écht een volledige load nodig hebben
472 (uitloggen/auth, downloads, feeds, media, assets, bestanden) worden overgeslagen,
473 net als links die al hun eigen hx-* hebben. -->
474<script>
475(function () {
476 if (!window.htmx) return;
477 // htmx' EIGEN history-afhandeling volledig uitzetten. We doen back/forward zelf
478 // via de popstate-listener hieronder (htmx.ajax → verwerkt de OOB-chrome netjes).
479 // Lieten we htmx z'n gang gaan, dan herstelde 'ie #pcms-main door de partial
480 // (inclusief de <div id=pcms-chrome hx-swap-oob>) ONGEFILTERD in #pcms-main te
481 // dumpen → een tweede, geneste kop = de pagina dubbel. Eén mechanisme nu.
482 try { window.htmx.config.historyEnabled = false; } catch (_) {}
483
484 function fullLoad(a, url) {
485 if (a.hasAttribute('download') || a.hasAttribute('data-full-load')) return true;
486 if (a.hasAttribute('hx-get') || a.hasAttribute('hx-post') || a.hasAttribute('hx-boost')) return true;
487 if (a.target && a.target !== '_self') return true;
488 if (a.getAttribute('rel') === 'external') return true;
489 var p = url.pathname;
490 // Sessie/redirect-acties → volledige navigatie (cookies, Google-redirect).
491 // Maar de auth-FORMULIERpagina's (/auth/admin, /auth/login, /auth/register,
492 // /auth/reset…) mogen wél via htmx, zodat de audiospeler blijft doorspelen
493 // i.p.v. te herstarten/verspringen bij een volledige page-load.
494 if (/^\/(logout|oauth)(?:\/|$)/.test(p)) return true;
495 if (/^\/auth\/(logout|google)(?:\/|$)/.test(p)) return true;
496 // Feeds, PWA, service-worker, statics, media-streams, downloads.
497 if (/^\/(feed|atom|sitemap|manifest|robots|sw\.js|assets|media|audio|uploads)(?:\/|\.|$)/.test(p)) return true;
498 if (/\.[a-z0-9]{2,5}$/i.test(p)) return true; // bestandsextensie → laat de browser 't halen
499 return false;
500 }
501
502 var lastPath = location.pathname + location.search;
503 var navTimer = null;
504
505 // Eén plek voor alle programmatische navigatie-swaps. Annuleert eerst een nog
506 // lopende request op #pcms-main (anti-race: bij snel klikken/terug-gaan kan een
507 // trage oude response anders een nieuwe pagina overschrijven → "kale content").
508 function doNav(dest) {
509 try { window.htmx.trigger('#pcms-main', 'htmx:abort'); } catch (_) {}
510 window.htmx.ajax('GET', dest, { target: '#pcms-main', swap: 'innerHTML' });
511 }
512
513 document.addEventListener('click', function (e) {
514 if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
515 var a = e.target.closest('a[href]');
516 if (!a) return;
517 var href = a.getAttribute('href');
518 if (!href || href.charAt(0) === '#') return;
519 var url; try { url = new URL(a.href, location.href); } catch (_) { return; }
520 if (url.origin !== location.origin) return;
521 if (fullLoad(a, url)) return;
522 e.preventDefault();
523 var dest = url.pathname + url.search;
524 if (dest !== lastPath) history.pushState({ b: 1 }, '', dest);
525 lastPath = dest;
526 if (navTimer) { clearTimeout(navTimer); navTimer = null; }
527 doNav(dest);
528 try { window.scrollTo(0, 0); } catch (_) {}
529 });
530
531 window.addEventListener('popstate', function () {
532 var here = location.pathname + location.search;
533 if (here === lastPath) return;
534 lastPath = here;
535 // Debounce: bij heel snel/herhaald terug-vooruit niet elke tussenpagina ophalen,
536 // alleen de LAATSTE bestemming. Voorkomt overlappende swaps ("kale content").
537 if (navTimer) clearTimeout(navTimer);
538 navTimer = setTimeout(function () {
539 navTimer = null;
540 doNav(location.pathname + location.search);
541 }, 90);
542 });
543
544 // Links MÉT eigen hx-get + hx-push-url (post-card/post-tile/topnav/…) lopen NIET
545 // via de boost hierboven, en hx-push-url is een no-op nu htmx-history uitstaat.
546 // Doe daarom de adresbalk-update hier zelf zodra htmx swapt. Programmatische
547 // htmx.ajax-calls (boost/popstate) hebben geen elt met hx-push-url → geen dubbel.
548 document.body.addEventListener('htmx:beforeRequest', function (evt) {
549 try {
550 var elt = evt.detail && evt.detail.elt; // het TRIGGERENDE element (de link)
551 if (!elt || !elt.closest) return;
552 var node = elt.closest('[hx-push-url]');
553 if (!node) return;
554 var u = node.getAttribute('hx-push-url');
555 if (!u || u === 'false') return;
556 if (u !== (location.pathname + location.search)) history.pushState({ b: 1 }, '', u);
557 lastPath = u;
558 } catch (_) {}
559 });
560
561 // Spring naar boven na ELKE navigatie-swap van #pcms-main. De boost hierboven
562 // scrollt al, maar links met hun eigen hx-get (post-nav Newer/Older, post-kaarten)
563 // lopen NIET via de boost → zonder dit blijf je op de oude scrollpositie hangen
564 // bij het openen van een gerelateerde/volgende post. Alleen #pcms-main, zodat
565 // in-page swaps (comments e.d.) en de OOB-chrome-swap niet meescrollen.
566 document.body.addEventListener('htmx:afterSwap', function (evt) {
567 var t = evt.detail && evt.detail.target;
568 if (t && t.id === 'pcms-main') { try { window.scrollTo(0, 0); } catch (_) {} }
569 });
570})();
571</script>
572
573<!-- Mobiel toetsenbord vs. site-layout: zet body.kb-open zodra het toetsenbord
574 open is (visual viewport fors korter dan het venster) ÉN er een invoerveld
575 focus heeft. CSS verbergt dan de vaste onderbalken (bottom-tab + mini-speler)
576 zodat ze niet over het invoerveld zweven. -->
577<script>
578(function () {
579 var vv = window.visualViewport;
580 if (!vv) return;
581 function isField(el) {
582 if (!el) return false;
583 var t = el.tagName;
584 return t === 'INPUT' || t === 'TEXTAREA' || el.isContentEditable;
585 }
586 function update() {
587 var open = (window.innerHeight - vv.height) > 150 && isField(document.activeElement);
588 document.body.classList.toggle('kb-open', open);
589 }
590 vv.addEventListener('resize', update);
591 vv.addEventListener('scroll', update);
592 document.addEventListener('focusin', function () { setTimeout(update, 60); });
593 document.addEventListener('focusout', function () { setTimeout(update, 60); });
594})();
595</script>
596
597<!-- Afbeeldingen lastiger op te slaan: rechtsklik-menu + slepen blokkeren op <img>.
598 Frictie, geen echte beveiliging (DevTools/screenshot blijven kunnen). -->
599<script>
600(function () {
601 document.addEventListener('contextmenu', function (e) {
602 if (e.target && e.target.tagName === 'IMG') e.preventDefault();
603 });
604 document.addEventListener('dragstart', function (e) {
605 if (e.target && e.target.tagName === 'IMG') e.preventDefault();
606 });
607})();
608</script>
609
610<!-- Auto-resize: elk <textarea> groeit mee met de inhoud i.p.v. intern te scrollen
611 (scroll-binnen-scroll is verwarrend). Site-breed; ook na htmx-swaps. -->
612<script>
613(function () {
614 function autoSize(ta) {
615 if (!ta || ta.tagName !== 'TEXTAREA') return;
616 ta.style.overflowY = 'hidden';
617 ta.style.height = 'auto';
618 ta.style.height = ta.scrollHeight + 'px';
619 }
620 function sizeAll(root) {
621 (root || document).querySelectorAll('textarea').forEach(autoSize);
622 }
623 document.addEventListener('input', function (e) { autoSize(e.target); });
624 document.addEventListener('focusin', function (e) { autoSize(e.target); });
625 // Init + opnieuw na htmx-navigatie/partials.
626 sizeAll();
627 document.body.addEventListener('htmx:afterSettle', function () { sizeAll(); });
628 window.addEventListener('load', function () { sizeAll(); });
629})();
630</script>
631
632<!-- PWA install prompt — show button when browser fires beforeinstallprompt -->
633<script>
634(function() {
635 var btn = document.getElementById('pwa-install-btn');
636 if (!btn) return;
637 var deferred = null;
638 window.addEventListener('beforeinstallprompt', function(e) {
639 e.preventDefault();
640 deferred = e;
641 btn.hidden = false;
642 });
643 btn.addEventListener('click', async function() {
644 if (!deferred) return;
645 btn.hidden = true;
646 deferred.prompt();
647 try { await deferred.userChoice; } catch(e) {}
648 deferred = null;
649 });
650 window.addEventListener('appinstalled', function() {
651 btn.hidden = true;
652 deferred = null;
653 });
654})();
655</script>
656
657<!-- Per-site custom footer HTML -->
658<% if (safeSite.custom_foot_html) { %>
659<%- safeSite.custom_foot_html %>
660<% } %>
661
662</body>
663</html>
Note: See TracBrowser for help on using the repository browser.