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

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

fix(ios-pwa): pad body for safe-area when masthead is hidden on mobile

Root cause (found via on-device debug): <=767px the masthead is display:none
(bottom-tab replaces it), so its safe-area padding has no effect (height 0) and the
profile-header lands at top=0 behind the Dynamic Island. Landscape (>767px) shows the
masthead so it worked there. Fix: pad body:not(.on-admin) by --ios-safe-top in the same
mobile media query, and make the JS adaptive (masthead hidden -> force body padding,
else masthead). Removed the temporary debug overlay; SW cache -> v14.

  • Property mode set to 100644
File size: 34.3 KB
RevLine 
[7bc636b]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 : '';
[9b851e7]11const safeAccent = safeSite.accent && /^#[0-9a-fA-F]{6}$/.test(safeSite.accent) ? safeSite.accent : '#e8b04b';
[7bc636b]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.
[5019e22]23const _siteTitle = safeSite.title || 'Klonkt';
[7bc636b]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) {
[8f2f97c]35 if (/^\/(?:search|tag|type|archive|users|account|admin)(?:$|\/)/.test(currentPath)) {
[7bc636b]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 || '');
[69815b2]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}
[7bc636b]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>
[9cc0f9f]104<html lang="<%= _e(lang) %>" data-palette="<%= _e((typeof palette !== 'undefined' && palette) ? palette : (safeSite.palette || 'klonkt')) %>">
[7bc636b]105<head>
106<meta charset="utf-8">
[9217e4e]107<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
[7bc636b]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') %>">
[b5bae24]136<link rel="icon" type="image/svg+xml" href="/favicon.svg?v=sf">
137<link rel="alternate icon" href="/favicon.ico?v=sf">
[7bc636b]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) %>">
[69815b2]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<% } %>
[7bc636b]153<% } %>
154<% if (_canonical) { %><meta property="og:url" content="<%= _e(_canonical) %>"><% } %>
[4c9c60b]155<%
156// Fediverse/social PLAYER card for posts with audio: instead of shipping the raw
157// mp3, point at our embeddable player (/embed?post=slug) so Mastodon shows an
158// inline player that streams via the gated /audio/stream (no downloadable file).
159const _postAudio = !!(typeof post !== 'undefined' && post
[30271e6]160 && typeof postHasPlayableAudio !== 'undefined' && postHasPlayableAudio
[4c9c60b]161 && typeof premiumUnlocked !== 'undefined' && premiumUnlocked);
162const _embedUrl = _postAudio
163 ? ((typeof ogOrigin !== 'undefined' && ogOrigin ? ogOrigin : '') + safeUrlBase + '/embed?post=' + encodeURIComponent(post.slug))
164 : '';
165%>
166<% if (_postAudio) { %>
167<meta property="og:video" content="<%= _e(_embedUrl) %>">
168<meta property="og:video:secure_url" content="<%= _e(_embedUrl) %>">
169<meta property="og:video:type" content="text/html">
170<meta property="og:video:width" content="480">
[98b7fdd]171<meta property="og:video:height" content="480">
[4c9c60b]172<% } %>
[7bc636b]173<% if (typeof post !== 'undefined' && post && post.published_at) { %>
174<meta property="article:published_time" content="<%= _e(post.published_at) %>">
175<% if (post.author_username) { %><meta property="article:author" content="<%= _e(post.author_username) %>"><% } %>
176<% } %>
177<% if (safeSite.facebook_app_id) { %><meta property="fb:app_id" content="<%= _e(safeSite.facebook_app_id) %>"><% } %>
178
179<!-- Twitter Cards -->
[4c9c60b]180<meta name="twitter:card" content="<%= _postAudio ? 'player' : (_socialImage ? 'summary_large_image' : 'summary') %>">
181<% if (_postAudio) { %>
182<meta name="twitter:player" content="<%= _e(_embedUrl) %>">
183<meta name="twitter:player:width" content="480">
[98b7fdd]184<meta name="twitter:player:height" content="480">
[4c9c60b]185<% } %>
[7bc636b]186<meta name="twitter:title" content="<%= _e(_socialTitle) %>">
187<meta name="twitter:description" content="<%= _e(_socialDescr) %>">
188<% if (_socialImage) { %><meta name="twitter:image" content="<%= _e(_socialImage) %>"><% } %>
189<% if (safeSite.twitter) { %><meta name="twitter:creator" content="<%= _e(safeSite.twitter) %>"><meta name="twitter:site" content="<%= _e(safeSite.twitter) %>"><% } %>
190
191<% if (_jsonLd) { %>
192<script type="application/ld+json"><%- JSON.stringify(_jsonLd) %></script>
193<% } %>
194
195<!-- Self-hosted fonts (privacy-first) -->
196<link rel="preload" href="/assets/fonts/literata-latin-opsz-normal.woff2" as="font" type="font/woff2" crossorigin>
197<link rel="preload" href="/assets/fonts/fraunces-latin-full-normal.woff2" as="font" type="font/woff2" crossorigin>
198
199<!-- v9 stylesheet (full palette system) -->
[a036251]200<link rel="stylesheet" href="/assets/css/style.css?v=54">
201<script>
[76f0e61]202/* iOS safe-area, built by hand. env(safe-area-inset-top) resolves to 0 on this iOS in
203 BOTH Safari and the installed PWA (standalone), even with viewport-fit=cover, so the
204 masthead can't clear the camera. We measure env directly and, when it comes back empty
205 on a notched iPhone, fall back to a fixed inset (a bit larger in standalone for the
206 Dynamic Island). We set --ios-safe-top AND force the masthead padding inline — the
207 latter survives a stale cached stylesheet that lacks the var. Re-applied after htmx
208 chrome swaps (the top-nav is out-of-band swapped on navigation). */
[a036251]209(function(){
210 var ua = navigator.userAgent || '';
211 var isIOS = /iP(hone|od|ad)/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
212 if (!isIOS) return;
[76f0e61]213 var standalone = (window.matchMedia && window.matchMedia('(display-mode: standalone)').matches) || navigator.standalone === true;
214 function apply(){
[a036251]215 if (!document.body) return;
216 var p = document.createElement('div');
217 p.style.cssText = 'position:fixed;top:0;left:0;width:0;height:0;padding-top:env(safe-area-inset-top,0px);visibility:hidden;pointer-events:none';
218 document.body.appendChild(p);
[b8bbe77]219 var rawEnv = parseFloat(getComputedStyle(p).paddingTop) || 0;
[a036251]220 p.remove();
[b8bbe77]221 var i = rawEnv;
[76f0e61]222 if (i < 20 && Math.max(screen.width, screen.height) >= 812) i = standalone ? 59 : 47;
[a036251]223 document.documentElement.style.setProperty('--ios-safe-top', i + 'px');
[76f0e61]224 var mh = document.querySelector('.masthead');
[f6b2c68]225 var mhHidden = !mh || getComputedStyle(mh).display === 'none' || mh.offsetHeight === 0;
226 if (mhHidden) {
227 /* Mobile: the masthead is hidden (bottom-tab replaces it ≤767px) so it can't carry
228 the inset. Pad the body instead → the profile-header clears the island/notch. */
229 document.body.style.paddingTop = i + 'px';
230 if (mh) mh.style.paddingTop = '';
231 } else {
232 /* Desktop/landscape: the sticky masthead carries the inset in its own padding. */
233 document.body.style.paddingTop = '';
234 mh.style.paddingTop = 'calc(.55rem + ' + i + 'px)';
235 }
[a036251]236 }
[76f0e61]237 if (document.body) apply(); else document.addEventListener('DOMContentLoaded', apply);
238 document.addEventListener('htmx:afterSettle', apply);
239 window.addEventListener('orientationchange', function(){ setTimeout(apply, 250); });
[a036251]240})();
241</script>
[7bc636b]242
243<!-- Audio player styles: loaded on every page so the mini-player works
244 anywhere (admin previews, post embeds, etc). The player itself is
245 a singleton — see the script tag near </body>. -->
[903f10b]246<link rel="stylesheet" href="/assets/css/audio.css?v=11">
[4c9f29a]247<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) in huisstijl. -->
[fef781e]248<link rel="stylesheet" href="/assets/css/embed.css?v=8">
[7bc636b]249
250<%- include('partials/shared-styles') %>
251
252<!-- v1 P55 — Inline the saved site accent. The base stylesheet only sets a
253 fallback (#c2410c orange) and palette blocks don't define --accent at
254 all, so without this override the saved accent never reaches the page.
255 :root + [data-palette] hits both unscoped and palette-scoped variants;
256 source-order wins on equal specificity, and this comes after style.css. -->
257<style id="pcms-site-accent">
258 :root,
259 [data-palette] {
260 --accent: <%= _e(safeAccent) %>;
261 --accent-soft: color-mix(in srgb, <%= _e(safeAccent) %> 80%, white);
262 --accent-tint: color-mix(in srgb, <%= _e(safeAccent) %> 12%, transparent);
263 }
264</style>
265
266<!-- Per-site custom CSS injection -->
267<% if (safeSite.custom_css) { %>
268<style id="pcms-custom-css"><%- safeSite.custom_css %></style>
269<% } %>
270
271<!-- Apply theme ASAP, before paint. Precedence (first match wins):
272 1. localStorage override (visitor toggled earlier on this browser)
273 2. Site default (theme_override + palette) — what new visitors see
274 3. Device prefers-color-scheme (only if site default is empty/auto)
275 4. 'dark' as last-ditch fallback
276 Note: PALETTE never has a localStorage layer anymore. There's no UI for
277 visitors to pick a palette, so any cached pcms-palette is stale data
278 from old code paths and gets cleaned up here. Site default always wins
279 for palette. -->
280<script>
281 (function() {
282 try {
283 var siteDefault = '<%= safeSite.theme_override || "" %>';
[9cc0f9f]284 var sitePalette = '<%= (typeof palette !== 'undefined' && palette) ? palette : (safeSite.palette || 'klonkt') %>';
[7bc636b]285
286 // One-time cleanup: drop the orphan pcms-palette key set by P43-P57
287 // bootstrap. After this it never re-appears because nothing writes it.
288 try { localStorage.removeItem('pcms-palette'); } catch(_) {}
289
290 // Theme: localStorage > site override > device pref > dark
291 var storedTheme = null;
292 try { storedTheme = localStorage.getItem('pcms-theme'); } catch(_) {}
293 var deviceDark = window.matchMedia &&
294 window.matchMedia('(prefers-color-scheme: dark)').matches;
295 var t = storedTheme
296 || siteDefault
297 || (deviceDark ? 'dark' : 'light');
298
299 // Palette: site default only.
300 document.documentElement.setAttribute('data-theme', t);
301 document.documentElement.setAttribute('data-palette', sitePalette);
302 } catch(e) {
303 document.documentElement.setAttribute('data-theme', 'dark');
304 }
305 })();
306</script>
307
308<!-- HTMX — bundled locally from node_modules at boot, zero third-party requests -->
309<script src="/assets/js/htmx.min.js"></script>
310
311<!-- Per-site custom <head> HTML (analytics, verification, etc.) -->
312<% if (safeSite.custom_head_html) { %>
313<%- safeSite.custom_head_html %>
314<% } %>
315</head>
316
[3c196f9]317<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 : '') %>">
[7bc636b]318
[8afbdd6]319<% if (typeof isViewer !== 'undefined' && isViewer) { %>
320 <div class="viewer-banner" role="status">
321 <span class="viewer-banner-ico" aria-hidden="true">👁️</span>
322 <span class="viewer-banner-text"><strong>Kijker-modus</strong> — je kunt alles bekijken, maar niets wijzigen.</span>
[640b39c]323 </div>
[8afbdd6]324 <style>
325 .viewer-banner {
326 position: sticky; top: 0; z-index: 60;
327 display: flex; align-items: center; justify-content: center; gap: 0.5rem;
328 padding: 0.5rem 1rem;
329 background: linear-gradient(90deg,
330 color-mix(in srgb, var(--accent) 88%, #000) 0%,
331 var(--accent) 100%);
332 color: #fff;
333 font-size: 0.85rem; line-height: 1.3;
334 box-shadow: 0 1px 6px color-mix(in srgb, var(--accent) 45%, transparent);
335 }
336 .viewer-banner-ico { font-size: 1rem; }
337 .viewer-banner-text strong { font-weight: 700; }
338 </style>
[640b39c]339<% } %>
340
[3cd1aaa]341<%# Site-chrome (topnav + profielkop + view-switcher) in één vaste slot #pcms-chrome.
342 Bij htmx-navigatie wordt dit slot out-of-band ververst (zie chrome.ejs +
343 render.js), zodat de kop ALTIJD bij de nieuwe pagina/artiest hoort terwijl de
344 audioplayer (los in document.body) blijft leven → geen verspringen. Op de
345 hub-landing is het slot leeg: de hero is daar de header. %>
346<%- include('partials/chrome') %>
[7bc636b]347
[85d9fda]348<%# Geen hx-history-elt: htmx' eigen history staat uit (zie de link-boost).
349 Back/forward wordt door onze popstate-listener gedaan, die de partial
350 her-fetcht (incl. correcte OOB-chrome). Met hx-history-elt + htmx-history
351 aan dumpte htmx de partial ongefilterd hier → dubbele kop. %>
352<main id="pcms-main" class="pcms-main">
[7bc636b]353 <div id="pcms-loading" class="pcms-loading" aria-hidden="true"></div>
354 <%- pageContent %>
355</main>
356
357<%- include('partials/footer') %>
358
[6224462]359<!-- Mobile bottom-tab navigation (auto-hidden ≥768px). Toont overal — óók op de
360 hub-landing (zodat mobiel altijd Home/Zoek/Inloggen heeft) — behalve op de
361 auth-focusschermen. -->
362<% if (!(typeof bodyClass === 'string' && bodyClass.indexOf('on-auth') >= 0)) { %>
[7bc636b]363<%- include('partials/bottom-tab') %>
[4c5169f]364<% } %>
[7bc636b]365
366<!-- Mobile profile sheet (auto-hidden ≥768px; only rendered when logged in) -->
367<% if (user) { %>
368<%- include('partials/profile-sheet') %>
369<% } %>
370
371<!-- Audio player: load on every page (admin + public) so window.pcmsAudioPlayer
372 is always available. The PCMS_SITE_TRACKS bootstrap is still gated on
373 enable_audio_player since it's a public-page concept (auto-discovered
[cf96890]374 tracks from rendered post embeds).
375
376 ?v=N — cache-buster: bump bij elke audio-player.js wijziging zodat
377 Cloudflare (max-age=1y) niet de oude versie blijft serveren. -->
[6a51968]378<script src="/assets/js/audio-player.js?v=30"></script>
[4c9f29a]379<!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) via de echte
380 player-API's + gedeelde mutual-exclusion registry met de site-speler. -->
[fef781e]381<script src="/assets/js/embed-player.js?v=16" defer></script>
[7bc636b]382<% if (site && site.enable_audio_player && audioTracks && audioTracks.length > 0) { %>
383 <script>window.PCMS_SITE_TRACKS = <%- JSON.stringify(audioTracks) %>;</script>
384<% } %>
385
386<!-- Install-app button: detects platform + shows install instructions modal -->
[942028f]387<script src="/assets/js/install-app.js?v=2" defer></script>
[7bc636b]388
389<!-- Service Worker registration -->
390<script>
391 if ('serviceWorker' in navigator) {
392 navigator.serviceWorker.register('/sw.js').catch(() => {});
393 }
394</script>
395
396<!-- HTMX navigation: keep body class in sync with the swapped page.
397 The server emits HX-Trigger-After-Settle: { pcmsNav: { bodyClass } } via
398 renderPage() in middleware/render.js. Without this listener the body
399 class stays whatever the initial page-load set, so the profile-header
400 never collapses/expands when navigating home → post → home via HTMX. -->
401<script>
402(function() {
[441f5d6]403 // De page-context body-classes. Bij pcmsNav strippen we ze allemaal en zetten
404 // we opnieuw wat de server stuurde. 'on-auth' staat erbij zodat het login-
405 // focusscherm óók via htmx z'n styling krijgt (geen chrome, geen tab, audio op 0).
[da4387b]406 var PAGE_CLASSES = ['on-home','on-post','on-special','on-archive','on-search','on-admin','on-auth',
407 'on-shows','on-downloads','on-download','on-epk','on-linkbio','on-newsletter',
408 'on-tag','on-type','on-user','on-cirkel','on-hub','on-chat'];
[7bc636b]409
410 document.body.addEventListener('pcmsNav', function(ev) {
[a3e2f17]411 var d = ev.detail || {};
412 // Per-site accent + palette bijwerken (head wordt niet mee-geswapt bij htmx-nav,
413 // dus zonder dit erft een artiest de kleuren van de vorige pagina).
414 if (d.accent && /^#[0-9a-fA-F]{6}$/.test(d.accent)) {
415 var sa = document.getElementById('pcms-site-accent');
416 if (sa) {
417 sa.textContent =
418 ':root,[data-palette]{--accent:' + d.accent +
419 ';--accent-soft:color-mix(in srgb,' + d.accent + ' 80%,white)' +
420 ';--accent-tint:color-mix(in srgb,' + d.accent + ' 12%,transparent);}';
421 }
422 }
423 if (d.palette && /^[a-z0-9-]+$/i.test(d.palette)) {
424 document.documentElement.setAttribute('data-palette', d.palette);
425 }
426
427 var next = d.bodyClass;
[7bc636b]428 if (!next) return;
[441f5d6]429 // De server kan meerdere page-classes sturen ("on-special on-auth"). Strip
430 // alle bekende en zet ALLE meegestuurde page-classes terug (niet alleen de
431 // eerste) — anders mist 'on-auth' bij htmx-nav en blijft het login-scherm
432 // de chrome/tab van de vorige pagina houden.
433 var matched = String(next).split(/\s+/).filter(function(c) {
[7bc636b]434 return PAGE_CLASSES.indexOf(c) >= 0;
435 });
[441f5d6]436 if (!matched.length) return;
[7bc636b]437 PAGE_CLASSES.forEach(function(c) { document.body.classList.remove(c); });
[441f5d6]438 matched.forEach(function(c) { document.body.classList.add(c); });
[7bc636b]439 });
[6a2abb1]440
[85d9fda]441 // (Back/forward wordt afgehandeld door de popstate-listener in de link-boost
442 // hieronder — die her-fetcht de partial via htmx.ajax, wat de OOB-chrome +
443 // de pcmsNav-trigger (accent/palette/bodyClass) correct toepast. De vroegere
444 // htmx:historyRestore-handler is vervallen nu htmx-history uitstaat.)
[7bc636b]445})();
446</script>
447
448<!-- View switcher + grid-cols persistence (event delegation: works for switcher
449 elements rendered later by HTMX, e.g. when navigating back to home). -->
450<script>
451(function() {
452 var body = document.body;
453 // Restore feed view + grid cols from localStorage (overrides server default)
454 try {
455 var v = localStorage.getItem('pcms-feed-view');
456 if (v === 'timeline' || v === 'grid') body.dataset.feedView = v;
457 var c = parseInt(localStorage.getItem('pcms-grid-cols'), 10);
458 if (c === 2 || c === 3 || c === 4) body.dataset.gridCols = String(c);
459 } catch (e) {}
460
461 function syncAria() {
[1c6d61c]462 // Alleen op een feed-pagina hoort Tijdlijn/Grid 'actief' (wit) te zijn; op
463 // agenda/downloads/post/etc. beide grijs. Inline feed-check (FEED_PAGE_CLASSES
464 // staat verderop, maar deze functie draait al bij init).
465 var _feedC = ['on-home','on-tag','on-type','on-user','on-cirkel'];
466 var _onFeed = _feedC.some(function(c){ return body.classList.contains(c); });
[7bc636b]467 document.querySelectorAll('.view-switch-btn').forEach(function(b) {
[1c6d61c]468 b.setAttribute('aria-selected', (_onFeed && b.dataset.view === body.dataset.feedView) ? 'true' : 'false');
[7bc636b]469 });
470 document.querySelectorAll('.grid-cols-btn').forEach(function(b) {
471 b.classList.toggle('is-active', b.dataset.cols === body.dataset.gridCols);
472 });
473 }
474 syncAria();
[cf0de0c]475 // Re-sync after HTMX brings in new content (e.g. navigating back to home).
476 // pcmsNav vuurt ná de body-class-update (zie de pcmsNav-listener hierboven), dus
477 // dáár weet syncAria de juiste pagina-class — los van de afterSettle-timing.
478 // Een vertraagde herhaling wint eventuele resterende races (OOB-chrome-swap).
479 document.body.addEventListener('htmx:afterSettle', function(){ syncAria(); setTimeout(syncAria, 60); });
480 document.body.addEventListener('pcmsNav', function(){ syncAria(); setTimeout(syncAria, 60); });
[7bc636b]481
482 // Pages where the body actually has a feed to toggle. On these the
483 // click stays put — it just flips body[data-feed-view] and CSS does
484 // the rest. Anywhere else (post detail, account, search, auth) we
485 // navigate to home in the chosen view, so the switcher is never
486 // a dead control.
[ec2e358]487 // NB: 'on-archive' staat hier bewust NIET tussen — op het archief is er geen
488 // in-place timeline/grid-toggle; een klik op de switcher springt terug naar de
489 // feed in de gekozen weergave (zie de !isFeedPage()-tak hieronder).
490 var FEED_PAGE_CLASSES = ['on-home', 'on-tag', 'on-type', 'on-user', 'on-cirkel'];
[7bc636b]491 function isFeedPage() {
492 for (var i = 0; i < FEED_PAGE_CLASSES.length; i++) {
493 if (body.classList.contains(FEED_PAGE_CLASSES[i])) return true;
494 }
495 return false;
496 }
497
498 // Event delegation — single listener handles current and future buttons.
499 document.addEventListener('click', function(e) {
500 var sw = e.target.closest('.view-switch-btn');
501 if (sw) {
502 var view = sw.dataset.view;
503 body.dataset.feedView = view;
504 try { localStorage.setItem('pcms-feed-view', view); } catch(_) {}
505 syncAria();
506 // On non-feed pages the switcher acts as a navigation: take the
507 // user back to home in the chosen view. Use HTMX if available so
508 // the page transition matches the rest of the site's nav.
509 if (!isFeedPage()) {
[3c196f9]510 // Naar de SITE-home in de gekozen view (siteUrlBase), niet de globale '/'
511 // — in hub is '/' de hub-overview, niet de tijdlijn van deze artiest.
512 var base = body.dataset.siteBase || '';
[7bc636b]513 if (window.htmx) {
[3c196f9]514 window.htmx.ajax('GET', base + '/?partial=1', { target: '#pcms-main', swap: 'innerHTML' });
515 history.pushState({}, '', base + '/');
[7bc636b]516 } else {
[3c196f9]517 location.href = base + '/';
[7bc636b]518 }
519 }
520 return;
521 }
522 var gc = e.target.closest('.grid-cols-btn');
523 if (gc) {
524 body.dataset.gridCols = gc.dataset.cols;
525 try { localStorage.setItem('pcms-grid-cols', gc.dataset.cols); } catch(_) {}
526 syncAria();
527 }
528 });
529})();
530</script>
531
[79bba6e]532<!-- Globale link-boost: alle interne navigatie-links lopen via htmx in #pcms-main,
533 zodat de audioplayer (los in document.body) blijft spelen i.p.v. te verspringen
534 bij een full page-load. Werkt overal — Beheer, Account, posts, sites — zonder
535 elke link los htmx te maken. Links die écht een volledige load nodig hebben
536 (uitloggen/auth, downloads, feeds, media, assets, bestanden) worden overgeslagen,
537 net als links die al hun eigen hx-* hebben. -->
538<script>
539(function () {
540 if (!window.htmx) return;
[85d9fda]541 // htmx' EIGEN history-afhandeling volledig uitzetten. We doen back/forward zelf
542 // via de popstate-listener hieronder (htmx.ajax → verwerkt de OOB-chrome netjes).
543 // Lieten we htmx z'n gang gaan, dan herstelde 'ie #pcms-main door de partial
544 // (inclusief de <div id=pcms-chrome hx-swap-oob>) ONGEFILTERD in #pcms-main te
545 // dumpen → een tweede, geneste kop = de pagina dubbel. Eén mechanisme nu.
546 try { window.htmx.config.historyEnabled = false; } catch (_) {}
[79bba6e]547
548 function fullLoad(a, url) {
549 if (a.hasAttribute('download') || a.hasAttribute('data-full-load')) return true;
550 if (a.hasAttribute('hx-get') || a.hasAttribute('hx-post') || a.hasAttribute('hx-boost')) return true;
551 if (a.target && a.target !== '_self') return true;
552 if (a.getAttribute('rel') === 'external') return true;
553 var p = url.pathname;
[7990e00]554 // Sessie/redirect-acties → volledige navigatie (cookies, Google-redirect).
555 // Maar de auth-FORMULIERpagina's (/auth/admin, /auth/login, /auth/register,
556 // /auth/reset…) mogen wél via htmx, zodat de audiospeler blijft doorspelen
557 // i.p.v. te herstarten/verspringen bij een volledige page-load.
558 if (/^\/(logout|oauth)(?:\/|$)/.test(p)) return true;
559 if (/^\/auth\/(logout|google)(?:\/|$)/.test(p)) return true;
[79bba6e]560 // Feeds, PWA, service-worker, statics, media-streams, downloads.
561 if (/^\/(feed|atom|sitemap|manifest|robots|sw\.js|assets|media|audio|uploads)(?:\/|\.|$)/.test(p)) return true;
562 if (/\.[a-z0-9]{2,5}$/i.test(p)) return true; // bestandsextensie → laat de browser 't halen
563 return false;
564 }
565
566 var lastPath = location.pathname + location.search;
[389aa99]567 var navTimer = null;
568
569 // Eén plek voor alle programmatische navigatie-swaps. Annuleert eerst een nog
570 // lopende request op #pcms-main (anti-race: bij snel klikken/terug-gaan kan een
571 // trage oude response anders een nieuwe pagina overschrijven → "kale content").
572 function doNav(dest) {
573 try { window.htmx.trigger('#pcms-main', 'htmx:abort'); } catch (_) {}
574 window.htmx.ajax('GET', dest, { target: '#pcms-main', swap: 'innerHTML' });
575 }
[79bba6e]576
577 document.addEventListener('click', function (e) {
578 if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
579 var a = e.target.closest('a[href]');
580 if (!a) return;
581 var href = a.getAttribute('href');
582 if (!href || href.charAt(0) === '#') return;
583 var url; try { url = new URL(a.href, location.href); } catch (_) { return; }
584 if (url.origin !== location.origin) return;
585 if (fullLoad(a, url)) return;
586 e.preventDefault();
587 var dest = url.pathname + url.search;
588 if (dest !== lastPath) history.pushState({ b: 1 }, '', dest);
589 lastPath = dest;
[389aa99]590 if (navTimer) { clearTimeout(navTimer); navTimer = null; }
591 doNav(dest);
[79bba6e]592 try { window.scrollTo(0, 0); } catch (_) {}
593 });
594
595 window.addEventListener('popstate', function () {
596 var here = location.pathname + location.search;
597 if (here === lastPath) return;
598 lastPath = here;
[389aa99]599 // Debounce: bij heel snel/herhaald terug-vooruit niet elke tussenpagina ophalen,
600 // alleen de LAATSTE bestemming. Voorkomt overlappende swaps ("kale content").
601 if (navTimer) clearTimeout(navTimer);
602 navTimer = setTimeout(function () {
603 navTimer = null;
604 doNav(location.pathname + location.search);
605 }, 90);
[79bba6e]606 });
[6b8afb1]607
608 // Links MÉT eigen hx-get + hx-push-url (post-card/post-tile/topnav/…) lopen NIET
609 // via de boost hierboven, en hx-push-url is een no-op nu htmx-history uitstaat.
610 // Doe daarom de adresbalk-update hier zelf zodra htmx swapt. Programmatische
611 // htmx.ajax-calls (boost/popstate) hebben geen elt met hx-push-url → geen dubbel.
[9b3e12c]612 document.body.addEventListener('htmx:beforeRequest', function (evt) {
[6b8afb1]613 try {
[9b3e12c]614 var elt = evt.detail && evt.detail.elt; // het TRIGGERENDE element (de link)
615 if (!elt || !elt.closest) return;
616 var node = elt.closest('[hx-push-url]');
617 if (!node) return;
618 var u = node.getAttribute('hx-push-url');
[6b8afb1]619 if (!u || u === 'false') return;
[9b3e12c]620 if (u !== (location.pathname + location.search)) history.pushState({ b: 1 }, '', u);
[6b8afb1]621 lastPath = u;
622 } catch (_) {}
623 });
[1080d14]624
625 // Spring naar boven na ELKE navigatie-swap van #pcms-main. De boost hierboven
626 // scrollt al, maar links met hun eigen hx-get (post-nav Newer/Older, post-kaarten)
627 // lopen NIET via de boost → zonder dit blijf je op de oude scrollpositie hangen
628 // bij het openen van een gerelateerde/volgende post. Alleen #pcms-main, zodat
629 // in-page swaps (comments e.d.) en de OOB-chrome-swap niet meescrollen.
630 document.body.addEventListener('htmx:afterSwap', function (evt) {
631 var t = evt.detail && evt.detail.target;
632 if (t && t.id === 'pcms-main') { try { window.scrollTo(0, 0); } catch (_) {} }
633 });
[79bba6e]634})();
635</script>
636
[9ef3c56]637<!-- Mobiel toetsenbord vs. site-layout: zet body.kb-open zodra het toetsenbord
638 open is (visual viewport fors korter dan het venster) ÉN er een invoerveld
639 focus heeft. CSS verbergt dan de vaste onderbalken (bottom-tab + mini-speler)
640 zodat ze niet over het invoerveld zweven. -->
641<script>
642(function () {
643 var vv = window.visualViewport;
644 if (!vv) return;
645 function isField(el) {
646 if (!el) return false;
647 var t = el.tagName;
648 return t === 'INPUT' || t === 'TEXTAREA' || el.isContentEditable;
649 }
650 function update() {
651 var open = (window.innerHeight - vv.height) > 150 && isField(document.activeElement);
652 document.body.classList.toggle('kb-open', open);
653 }
654 vv.addEventListener('resize', update);
655 vv.addEventListener('scroll', update);
656 document.addEventListener('focusin', function () { setTimeout(update, 60); });
657 document.addEventListener('focusout', function () { setTimeout(update, 60); });
658})();
659</script>
660
[d188736]661<!-- Afbeeldingen lastiger op te slaan: rechtsklik-menu + slepen blokkeren op <img>.
662 Frictie, geen echte beveiliging (DevTools/screenshot blijven kunnen). -->
663<script>
664(function () {
665 document.addEventListener('contextmenu', function (e) {
666 if (e.target && e.target.tagName === 'IMG') e.preventDefault();
667 });
668 document.addEventListener('dragstart', function (e) {
669 if (e.target && e.target.tagName === 'IMG') e.preventDefault();
670 });
671})();
672</script>
673
[f3f43df]674<!-- Auto-resize: elk <textarea> groeit mee met de inhoud i.p.v. intern te scrollen
675 (scroll-binnen-scroll is verwarrend). Site-breed; ook na htmx-swaps. -->
676<script>
677(function () {
678 function autoSize(ta) {
679 if (!ta || ta.tagName !== 'TEXTAREA') return;
680 ta.style.overflowY = 'hidden';
681 ta.style.height = 'auto';
682 ta.style.height = ta.scrollHeight + 'px';
683 }
684 function sizeAll(root) {
685 (root || document).querySelectorAll('textarea').forEach(autoSize);
686 }
687 document.addEventListener('input', function (e) { autoSize(e.target); });
688 document.addEventListener('focusin', function (e) { autoSize(e.target); });
689 // Init + opnieuw na htmx-navigatie/partials.
690 sizeAll();
691 document.body.addEventListener('htmx:afterSettle', function () { sizeAll(); });
692 window.addEventListener('load', function () { sizeAll(); });
693})();
694</script>
695
[7bc636b]696<!-- PWA install prompt — show button when browser fires beforeinstallprompt -->
697<script>
698(function() {
699 var btn = document.getElementById('pwa-install-btn');
700 if (!btn) return;
701 var deferred = null;
702 window.addEventListener('beforeinstallprompt', function(e) {
703 e.preventDefault();
704 deferred = e;
705 btn.hidden = false;
706 });
707 btn.addEventListener('click', async function() {
708 if (!deferred) return;
709 btn.hidden = true;
710 deferred.prompt();
711 try { await deferred.userChoice; } catch(e) {}
712 deferred = null;
713 });
714 window.addEventListener('appinstalled', function() {
715 btn.hidden = true;
716 deferred = null;
717 });
718})();
719</script>
720
721<!-- Per-site custom footer HTML -->
722<% if (safeSite.custom_foot_html) { %>
723<%- safeSite.custom_foot_html %>
724<% } %>
725
726</body>
727</html>
Note: See TracBrowser for help on using the repository browser.