source: Klonkt/src/views/pages/post-edit.ejs@ 9effb80

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

fix(editor): CSP blocked blob: image → empty edit dialog

img-src was missing blob:, so the Cropper <img> (URL.createObjectURL → blob:)
was silently blocked by CSP → no image visible. Added blob: to img-src (media-src
already had it for audio). + onerror fallback in the editor: if the image fails
to load, the original is uploaded instead of getting stuck.

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

  • Property mode set to 100644
File size: 83.1 KB
RevLine 
[7bc636b]1<%
2// Post editor — split into card sections for visual hierarchy:
3// - Identity : title, slug, excerpt
4// - Cover : thumbnail + URL + custom upload button
5// - Content : markdown textarea with attached toolbar
6// - Meta : status, type, pin, noindex, tags
7//
8// All behavior (IDs, names, upload endpoints) is preserved — only layout
9// and styling changed.
10const _hasCover = !!post.cover_image_url;
[851239c]11// In hub-modus moeten save/create/cancel de /user/<slug>/-prefix dragen, anders
12// valt de request terug op de primaire site (siteUrlBase leeg) en rendert de
13// post na opslaan headerless (bareChrome). In solo is _base leeg.
14const _base = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
[7bc636b]15%>
16<div class="container post-edit-page">
[4885eab]17 <h1><%= isNew ? t('pedit.title_new') : t('pedit.title_edit') %></h1>
[7bc636b]18
[851239c]19 <form method="post" action="<%= _base %><%= isNew ? '/posts/create' : '/posts/' + post.slug + '/save' %>" class="post-edit-form">
[7bc636b]20
21 <%# ── IDENTITY ─────────────────────────────────────────────── %>
22 <section class="pe-card">
23 <label class="pe-field">
[4885eab]24 <span><%= t('pedit.f_title') %></span>
[a0bff44]25 <input type="text" name="title" value="<%= post.title %>" required>
[7bc636b]26 </label>
27 <div class="pe-row pe-row-2">
28 <label class="pe-field">
[4885eab]29 <span><%= t('pedit.f_slug') %></span>
30 <input type="text" name="slug" value="<%= post.slug %>" placeholder="<%= t('pedit.slug_placeholder') %>">
[7bc636b]31 </label>
32 <label class="pe-field">
[4885eab]33 <span><%= t('pedit.f_tags') %> <small><%= t('pedit.tags_hint') %></small></span>
[7bc636b]34 <input type="text" name="tags" value="<%= Array.isArray(post.tags) ? post.tags.join(', ') : '' %>">
35 </label>
36 </div>
37 <label class="pe-field">
[4885eab]38 <span><%= t('pedit.f_excerpt') %></span>
[7bc636b]39 <textarea name="excerpt" rows="2"><%= post.excerpt %></textarea>
[4885eab]40 <small class="pe-hint" style="opacity:.7"><%- t('pedit.excerpt_hint') %></small>
[7bc636b]41 </label>
42 </section>
43
44 <%# ── COVER ────────────────────────────────────────────────── %>
45 <section class="pe-card">
[4885eab]46 <div class="pe-section-title"><%= t('pedit.s_cover') %></div>
[7bc636b]47 <div class="pe-cover-row">
48 <div class="pe-cover-thumb" id="cover-preview-wrap" <%= _hasCover ? '' : 'data-empty' %>>
49 <img src="<%= _hasCover ? post.cover_image_url : '' %>" alt="" id="cover-preview-img" <%= _hasCover ? '' : 'hidden' %>>
50 <% if (!_hasCover) { %><span class="pe-cover-empty">🖼</span><% } %>
51 </div>
52 <div class="pe-cover-actions">
53 <label class="pe-field">
[4885eab]54 <span><%= t('pedit.f_cover_url') %></span>
[b50a885]55 <input type="text" name="cover_image_url" id="cover-url-field"
[7bc636b]56 value="<%= post.cover_image_url || '' %>"
[b50a885]57 inputmode="url" autocapitalize="none" spellcheck="false"
[4885eab]58 placeholder="<%= t('pedit.cover_url_placeholder') %>">
[7bc636b]59 </label>
60 <div class="pe-cover-upload">
61 <button type="button" class="pe-btn pe-btn-secondary" id="cover-upload-trigger">
[4885eab]62 📷 <%= t('pedit.cover_upload_btn') %>
[7bc636b]63 </button>
64 <input type="file" id="cover-upload-field" accept="image/jpeg,image/png,image/webp,image/gif" hidden>
65 <small id="cover-upload-status" class="pe-status"></small>
66 </div>
67 </div>
68 </div>
69 </section>
70
71 <%# ── CONTENT ──────────────────────────────────────────────── %>
72 <section class="pe-card pe-card-content">
73 <div class="pe-section-title">
[4885eab]74 <%= t('pedit.s_content') %>
75 <small class="pe-content-hint"><%= t('pedit.content_hint') %></small>
[7bc636b]76 </div>
77 <div class="pe-editor-frame">
78 <div class="pe-toolbar" id="pe-toolbar" role="toolbar" aria-label="Format">
[4885eab]79 <button type="button" id="pe-fs-done" class="pe-fs-done" title="<%= t('pedit.tb_done_title') %>">✓ <%= t('pedit.tb_done') %></button>
80 <button type="button" data-cmd="bold" title="<%= t('pedit.tb_bold_title') %>" aria-label="<%= t('pedit.tb_bold') %>">
[7bc636b]81 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4h8a4 4 0 0 1 0 8H6z"/><path d="M6 12h9a4 4 0 0 1 0 8H6z"/></svg>
82 </button>
[4885eab]83 <button type="button" data-cmd="italic" title="<%= t('pedit.tb_italic_title') %>" aria-label="<%= t('pedit.tb_italic') %>">
[7bc636b]84 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>
85 </button>
[4885eab]86 <button type="button" data-cmd="underline" title="<%= t('pedit.tb_underline') %>" aria-label="<%= t('pedit.tb_underline') %>">
[7bc636b]87 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" y1="20" x2="20" y2="20"/></svg>
88 </button>
89 <span class="pe-toolbar-sep" aria-hidden="true"></span>
[4885eab]90 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="h2" title="<%= t('pedit.tb_h2') %>">H2</button>
91 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="h3" title="<%= t('pedit.tb_h3') %>">H3</button>
92 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="p" title="<%= t('pedit.tb_p') %>">¶</button>
[7bc636b]93 <span class="pe-toolbar-sep" aria-hidden="true"></span>
[4885eab]94 <button type="button" data-cmd="insertUnorderedList" title="<%= t('pedit.tb_ul') %>" aria-label="<%= t('pedit.tb_ul') %>">
[7bc636b]95 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1.2"/><circle cx="4.5" cy="12" r="1.2"/><circle cx="4.5" cy="18" r="1.2"/></svg>
96 </button>
[4885eab]97 <button type="button" data-cmd="insertOrderedList" title="<%= t('pedit.tb_ol') %>" aria-label="<%= t('pedit.tb_ol') %>">
[7bc636b]98 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>
99 </button>
[4885eab]100 <button type="button" data-cmd="formatBlock" data-arg="blockquote" title="<%= t('pedit.tb_quote') %>" aria-label="<%= t('pedit.tb_quote') %>">
[7bc636b]101 <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 21c3 0 7-1 7-8V5c0-1.25-.75-2-2-2H4c-1.25 0-2 .75-2 2v6c0 1.25.75 2 2 2h2.5C6 17.5 4 19 3 19v2z"/><path d="M14 21c3 0 7-1 7-8V5c0-1.25-.75-2-2-2h-4c-1.25 0-2 .75-2 2v6c0 1.25.75 2 2 2h2.5c-.5 4.5-2.5 6-3.5 6v2z"/></svg>
102 </button>
[4885eab]103 <button type="button" data-cmd="link-prompt" title="<%= t('pedit.tb_link_title') %>" aria-label="<%= t('pedit.tb_link') %>">
[7bc636b]104 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
105 </button>
[4885eab]106 <button type="button" data-cmd="code-wrap" title="<%= t('pedit.tb_code_title') %>" aria-label="<%= t('pedit.tb_code') %>">
[7bc636b]107 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
108 </button>
109 <span class="pe-toolbar-sep" aria-hidden="true"></span>
[4885eab]110 <button type="button" id="insert-image-btn" title="<%= t('pedit.tb_image_title') %>" aria-label="<%= t('pedit.tb_image') %>">
[7bc636b]111 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>
112 </button>
[4885eab]113 <button type="button" id="insert-track-btn" title="<%= t('pedit.tb_track_title') %>" aria-label="<%= t('pedit.tb_track') %>">
[7bc636b]114 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
115 </button>
[4885eab]116 <button type="button" id="insert-playlist-btn" title="<%= t('pedit.tb_playlist_title') %>" aria-label="<%= t('pedit.tb_playlist') %>">
[7bc636b]117 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="15" y2="18"/><polygon points="3 5 3 13 9 9"/></svg>
118 </button>
[4885eab]119 <button type="button" id="insert-embed-btn" title="<%= t('pedit.tb_embed_title') %>" aria-label="<%= t('pedit.tb_embed') %>">
[1907a18]120 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="4" width="20" height="16" rx="2"/><polygon points="10 9 15.5 12 10 15"/></svg>
121 </button>
[7bc636b]122 <span class="pe-toolbar-spacer"></span>
[4885eab]123 <button type="button" data-cmd="removeFormat" title="<%= t('pedit.tb_clear') %>" aria-label="<%= t('pedit.tb_clear') %>">
[7bc636b]124 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M5 5l14 14" stroke-linecap="round"/></svg>
125 </button>
[4885eab]126 <button type="button" id="pe-fullscreen-btn" title="<%= t('pedit.tb_fullscreen') %>" aria-label="<%= t('pedit.tb_fullscreen') %>" aria-pressed="false">
[d2078f4]127 <svg class="fs-icon-expand" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>
128 <svg class="fs-icon-compress" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="4 14 10 14 10 20"/><polyline points="20 10 14 10 14 4"/><line x1="14" y1="10" x2="21" y2="3"/><line x1="3" y1="21" x2="10" y2="14"/></svg>
129 </button>
[7bc636b]130 </div>
131
132 <div id="content-editor"
133 class="pe-editor"
134 contenteditable="true"
135 role="textbox"
136 aria-multiline="true"
[4885eab]137 aria-label="<%= t('pedit.editor_aria') %>"
138 data-placeholder="<%= t('pedit.editor_placeholder') %>"></div>
[7bc636b]139
[a623e7e]140 <%# Sticky "tik om te bewerken"-hint (alleen zichtbaar op touch + niet-fullscreen
141 via CSS). Puur visueel (pointer-events:none); de tik op het veld opent fullscreen. %>
[4885eab]142 <div class="pe-edit-hint" aria-hidden="true">✎ <%= t('pedit.tap_to_edit') %></div>
[a623e7e]143
[7bc636b]144 <%# Hidden field is what actually submits to the server. The visible
145 contenteditable's serialized HTML is copied here on submit. %>
146 <input type="hidden" name="content" id="content-hidden" value="">
147
148 <%# Initial content is injected as a JSON string in a script tag so we
149 can set innerHTML safely from JS. EJS-escaping HTML directly into
150 the editor would render entity-escaped tags as text. %>
151 <script id="initial-content" type="application/json"><%- JSON.stringify(post.content || '').replace(/</g, '\\u003c') %></script>
152
153 <div class="pe-editor-status">
154 <small id="content-upload-status" class="pe-status"></small>
[4885eab]155 <span class="pe-char-count"><span id="char-count">0</span> <%= t('pedit.chars') %></span>
[7bc636b]156 </div>
157
158 <input type="file" id="content-upload-field" accept="image/jpeg,image/png,image/webp,image/gif" hidden>
159 </div>
160 </section>
161
162 <%# ── META ─────────────────────────────────────────────────── %>
163 <section class="pe-card">
[4885eab]164 <div class="pe-section-title"><%= t('pedit.s_publication') %></div>
[7bc636b]165 <div class="pe-row pe-row-2">
166 <label class="pe-field">
[4885eab]167 <span><%= t('pedit.f_status') %></span>
[edc462d]168 <% var _st = isNew ? 'published' : (post.status || 'draft'); %>
[7bc636b]169 <select name="status">
[4885eab]170 <option value="published" <%= _st === 'published' ? 'selected' : '' %>><%= t('pedit.status_published') %></option>
171 <option value="draft" <%= _st === 'draft' ? 'selected' : '' %>><%= t('pedit.status_draft') %></option>
172 <option value="archived" <%= _st === 'archived' ? 'selected' : '' %>><%= t('pedit.status_archived') %></option>
[7bc636b]173 </select>
174 </label>
175 <label class="pe-field">
[4885eab]176 <span><%= t('pedit.f_type') %></span>
[7bc636b]177 <select name="type">
178 <% var ptype = post.type || 'post'; %>
[4885eab]179 <option value="post" <%= ptype === 'post' ? 'selected' : '' %>><%= t('pedit.type_post') %></option>
180 <option value="foto" <%= ptype === 'foto' ? 'selected' : '' %>><%= t('pedit.type_foto') %></option>
181 <option value="video" <%= ptype === 'video' ? 'selected' : '' %>><%= t('pedit.type_video') %></option>
182 <option value="audio" <%= ptype === 'audio' ? 'selected' : '' %>><%= t('pedit.type_audio') %></option>
[7bc636b]183 </select>
184 </label>
185 </div>
186 <div class="pe-checkboxes">
[edc462d]187 <div class="pe-pin">
188 <label class="pe-checkbox">
189 <input type="checkbox" id="pin-toggle" <%= (Number(post.pinned) > 0) ? 'checked' : '' %>>
[4885eab]190 <span>📌 <%= t('pedit.pin_label') %></span>
[edc462d]191 </label>
192 <input type="hidden" name="pinned" id="pin-rank" value="<%= post.pinned || 0 %>">
193 <div class="pe-pin-pos" id="pin-pos" <%= (Number(post.pinned) > 0) ? '' : 'hidden' %>>
194 <span class="pe-pin-steps">
[4885eab]195 <button type="button" class="pe-pin-btn" id="pin-up" aria-label="<%= t('pedit.pin_up') %>">▲</button>
196 <button type="button" class="pe-pin-btn" id="pin-down" aria-label="<%= t('pedit.pin_down') %>">▼</button>
[edc462d]197 </span>
198 <span class="pe-pin-label" id="pin-label"></span>
199 </div>
200 </div>
[7bc636b]201 <label class="pe-checkbox">
202 <input type="checkbox" name="noindex" value="1" <%= post.noindex ? 'checked' : '' %>>
[4885eab]203 <span>🚫 <%= t('pedit.noindex_label') %></span>
[7bc636b]204 </label>
[b9dc94c]205 <% if (typeof premiumUnlocked === 'undefined' || premiumUnlocked) { %>
206 <label class="pe-checkbox">
207 <input type="checkbox" name="fan_only" value="1" <%= post.fan_only ? 'checked' : '' %>>
[4885eab]208 <span>🔒 <%= t('pedit.fan_only_label') %></span>
[b9dc94c]209 </label>
[11b3ba5]210 <% var _scheduled = !!(post.publish_at && (post.status === 'scheduled' || Date.parse(String(post.publish_at).replace(' ', 'T')) > Date.now())); %>
211 <label class="pe-checkbox" style="margin-top:8px">
212 <input type="checkbox" name="schedule_enabled" value="1" id="pe-sched-toggle" <%= _scheduled ? 'checked' : '' %>>
213 <span>📅 <%= t('pedit.schedule_label') %></span>
214 </label>
215 <div id="pe-sched-fields" style="margin-top:6px;<%= _scheduled ? '' : 'display:none' %>">
216 <label style="display:block;font-size:12.5px;opacity:.8;margin-bottom:4px"><%= t('pedit.publish_at_label') %></label>
[015ce46]217 <input type="datetime-local" id="pe-publish-at" name="publish_at" <%= _scheduled ? '' : 'disabled' %> data-iso="<%= post.publish_at || '' %>" value="" style="padding:8px 10px;border-radius:8px;border:1px solid var(--rule,rgba(128,128,128,.4));background:transparent;color:inherit">
218 <% if (post.status === 'scheduled' && post.publish_at) { %><div style="font-size:12px;opacity:.7;margin-top:4px"><span id="pe-sched-when" data-iso="<%= post.publish_at %>" data-label="<%= t('pedit.scheduled_prefix') %>">⏳ <%= t('pedit.scheduled_for', { d: post.publish_at }) %></span></div><% } %>
[11b3ba5]219 <div style="font-size:11.5px;opacity:.65;margin-top:4px"><%= t('pedit.schedule_hint') %></div>
[b9dc94c]220 </div>
[11b3ba5]221 <script>
222 (function () {
223 var cb = document.getElementById('pe-sched-toggle');
224 var box = document.getElementById('pe-sched-fields');
225 if (!cb || !box) return;
[015ce46]226 var inp = document.getElementById('pe-publish-at');
227 var pad = function (n) { return String(n).padStart(2, '0'); };
228 // Prefill: opgeslagen UTC → lokale datetime-local-waarde (zodat je je
229 // eigen tijdzone ziet, niet UTC).
230 if (inp && inp.dataset.iso) {
231 var d0 = new Date(inp.dataset.iso);
232 if (!isNaN(d0)) inp.value = d0.getFullYear() + '-' + pad(d0.getMonth() + 1) + '-' + pad(d0.getDate()) + 'T' + pad(d0.getHours()) + ':' + pad(d0.getMinutes());
233 }
234 // "Ingepland voor" in leesbare lokale tijd i.p.v. ruwe UTC-ISO.
235 var when = document.getElementById('pe-sched-when');
236 if (when && when.dataset.iso) {
237 var dw = new Date(when.dataset.iso);
238 if (!isNaN(dw)) when.textContent = '⏳ ' + when.dataset.label + ' ' + dw.toLocaleString();
239 }
[11b3ba5]240 function sync() { box.style.display = cb.checked ? '' : 'none'; if (inp) inp.disabled = !cb.checked; }
241 cb.addEventListener('change', sync); sync();
[015ce46]242 // Bij opslaan: lokale invoer → UTC-ISO via een hidden veld, zodat de
243 // server de juiste tijd opslaat (datetime-local heeft geen tijdzone).
244 var form = cb.closest('form');
245 if (form) {
246 form.addEventListener('submit', function () {
247 if (inp) inp.removeAttribute('name');
248 var old = form.querySelector('input[data-pa-utc]');
249 if (old) old.remove();
250 if (cb.checked && inp && inp.value) {
251 var d2 = new Date(inp.value); // geïnterpreteerd in browser-tijdzone
252 if (!isNaN(d2)) {
253 var h = document.createElement('input');
254 h.type = 'hidden'; h.name = 'publish_at'; h.setAttribute('data-pa-utc', '');
255 h.value = d2.toISOString();
256 form.appendChild(h);
257 }
258 }
259 });
260 }
[11b3ba5]261 })();
262 </script>
[b9dc94c]263 <% } %>
[7bc636b]264 </div>
265 </section>
266
267 <%# ── ACTIONS (sticky at bottom) ──────────────────────────── %>
268 <div class="pe-actions">
[4885eab]269 <a href="<%= _base %><%= isNew ? '/' : '/' + post.slug %>" class="pe-btn"><%= t('pedit.cancel') %></a>
[7bc636b]270 <div class="pe-actions-spacer"></div>
271 <% if (!isNew && post.status !== 'published') { %>
[4885eab]272 <button type="submit" name="action" value="publish" class="pe-btn pe-btn-success">📤 <%= t('pedit.publish') %></button>
[7bc636b]273 <% } %>
[4885eab]274 <button type="submit" class="pe-btn pe-btn-primary">💾 <%= t('pedit.save') %></button>
[7bc636b]275 </div>
276 </form>
277</div>
278
279<style>
280/* ─── Page wrapper ──────────────────────────────────────────────── */
281.post-edit-page {
282 max-width: 880px;
283 margin: 1.5rem auto 6rem; /* extra bottom for sticky-actions clearance */
284 padding: 0 1rem;
285}
286.post-edit-page h1 {
287 font-family: var(--font-display, serif);
288 margin: 0 0 1.25rem;
289 font-size: 1.75rem;
290}
291
292.post-edit-form {
293 display: flex; flex-direction: column;
294 gap: 1rem;
295}
296
297/* ─── Card sections ─────────────────────────────────────────────── */
298.pe-card {
299 background: var(--paper);
300 border: 1px solid var(--rule);
301 border-radius: 12px;
302 padding: 1.25rem;
303 display: flex; flex-direction: column;
304 gap: 0.85rem;
305}
306.pe-card-content { padding-bottom: 0; overflow: hidden; } /* editor flush to bottom */
307.pe-section-title {
308 font-size: 0.8rem;
309 font-weight: 600;
310 text-transform: uppercase;
311 letter-spacing: 0.05em;
312 color: var(--ink-soft);
313 display: flex; align-items: baseline; gap: 0.5rem;
314 flex-wrap: wrap;
315}
316.pe-section-title small {
317 font-size: 0.75rem; font-weight: 400;
318 letter-spacing: 0; text-transform: none;
319 color: var(--ink-muted, var(--ink-soft));
320}
321
322/* ─── Field primitives ──────────────────────────────────────────── */
323.pe-field {
324 display: flex; flex-direction: column;
325 gap: 0.35rem;
326 min-width: 0; /* allow grid items to shrink */
327}
328.pe-field > span {
329 font-size: 0.8rem;
330 font-weight: 600;
331 color: var(--ink-soft);
332 display: flex; align-items: baseline; gap: 0.4rem;
333}
334.pe-field > span small {
335 font-weight: 400; color: var(--ink-muted);
336}
337.pe-field input,
338.pe-field textarea,
339.pe-field select {
340 width: 100%;
341 box-sizing: border-box;
342 display: block;
343 padding: 0.6rem 0.75rem;
344 border: 1px solid var(--rule);
345 border-radius: 6px;
346 background: var(--paper-2);
347 color: var(--ink);
348 font-family: var(--font-ui, system-ui), sans-serif;
349 font-size: 0.95rem;
350 -webkit-appearance: none;
351 appearance: none;
352 transition: border-color 120ms;
353}
354.pe-field input:focus,
355.pe-field textarea:focus,
356.pe-field select:focus {
357 outline: 2px solid var(--accent);
358 outline-offset: -1px;
359 border-color: var(--accent);
360}
361.pe-field textarea {
362 font-family: var(--font-mono, monospace);
363 resize: vertical;
364}
365.pe-field select {
366 /* Restore the dropdown arrow we removed with appearance:none */
367 background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
368 background-repeat: no-repeat;
369 background-position: right 0.75rem center;
370 padding-right: 2rem;
371}
372
373.pe-row {
374 display: grid;
375 gap: 0.75rem;
376}
377.pe-row-2 { grid-template-columns: 1fr 1fr; }
378@media (max-width: 600px) {
379 .pe-row-2 { grid-template-columns: 1fr; }
380}
381
382/* ─── Cover field ───────────────────────────────────────────────── */
383.pe-cover-row {
384 display: grid;
385 grid-template-columns: 120px 1fr;
386 gap: 1rem;
387 align-items: start;
388}
389.pe-cover-thumb {
390 width: 120px; height: 120px;
391 border-radius: 10px;
392 overflow: hidden;
393 background: var(--paper-2);
394 border: 1px solid var(--rule);
395 display: flex; align-items: center; justify-content: center;
396 position: relative;
397}
398.pe-cover-thumb[data-empty] {
399 border-style: dashed;
400}
401.pe-cover-thumb img {
402 width: 100%; height: 100%;
403 object-fit: cover; display: block;
404}
405/* Honor HTML hidden — our display:block above otherwise renders an empty
406 broken-image icon when no cover is set. */
407.pe-cover-thumb img[hidden] { display: none; }
408.pe-cover-empty {
409 font-size: 2rem;
410 color: var(--ink-muted, var(--ink-soft));
411 opacity: 0.5;
412}
413.pe-cover-actions {
414 display: flex; flex-direction: column;
415 gap: 0.6rem;
416 min-width: 0;
417}
418.pe-cover-upload {
419 display: flex; align-items: center; gap: 0.6rem;
420 flex-wrap: wrap;
421}
422@media (max-width: 600px) {
423 .pe-cover-row { grid-template-columns: 88px 1fr; }
424 .pe-cover-thumb { width: 88px; height: 88px; }
425}
426
427/* ─── Editor frame (WYSIWYG: top toolbar, contenteditable body, status bar) ─── */
428.pe-editor-frame {
429 margin: 0 -1.25rem -1.25rem; /* break out of card padding for flush edges */
430 border-top: 1px solid var(--rule);
431 background: var(--paper);
432 display: flex; flex-direction: column;
433}
434
435/* Top toolbar — sticks to the top of the viewport while editing */
436.pe-toolbar {
437 display: flex; align-items: center; gap: .15rem;
438 flex-wrap: wrap;
439 padding: .4rem .75rem;
440 background: color-mix(in srgb, var(--paper) 92%, transparent);
441 backdrop-filter: blur(10px);
442 -webkit-backdrop-filter: blur(10px);
443 border-bottom: 1px solid var(--rule);
444 position: sticky;
445 top: 0;
446 z-index: 10;
447}
448.pe-toolbar button {
449 display: inline-flex; align-items: center; justify-content: center;
450 width: 32px; height: 32px;
451 padding: 0;
[a7e8e19]452 touch-action: manipulation; /* snappy taps op mobiel, geen dubbeltik-zoom */
453 -webkit-user-select: none; user-select: none;
[7bc636b]454 background: transparent;
455 border: 1px solid transparent;
456 border-radius: 6px;
457 color: var(--ink);
458 cursor: pointer;
459 font-family: var(--font-ui, system-ui), sans-serif;
460 font-weight: 600; font-size: .85rem;
461 transition: background var(--transition), color var(--transition), border-color var(--transition);
462 -webkit-tap-highlight-color: transparent;
463}
[16ce669]464/* Hover alleen op echte hover-apparaten — op touch blijft :hover anders "plakken"
465 na een tik, waardoor de actief/inactief-staat onleesbaar wordt. */
466@media (hover: hover) {
467 .pe-toolbar button:hover {
468 background: var(--paper-2);
469 color: var(--accent);
470 }
[7bc636b]471}
472.pe-toolbar button:active { transform: scale(.94); }
[16ce669]473/* Actieve opmaak = onmiskenbaar gevuld met de accentkleur. Zo is op mobiel
474 meteen duidelijk dat bv. vet AAN staat (tik nogmaals = uit). */
[7bc636b]475.pe-toolbar button.is-active {
[16ce669]476 background: var(--accent);
477 color: #fff;
478 border-color: var(--accent);
[7bc636b]479}
[16ce669]480.pe-toolbar button.is-active svg { color: #fff; }
[7bc636b]481.pe-toolbar button svg { width: 16px; height: 16px; }
482.pe-toolbar button.pe-tb-text { font-family: var(--font-display, serif); font-weight: 700; }
483.pe-toolbar-sep {
484 width: 1px; height: 18px;
485 background: var(--rule);
486 margin: 0 .35rem;
487 flex-shrink: 0;
488}
489.pe-toolbar-spacer { flex: 1; }
490
[d2078f4]491/* ─── Volledig-scherm schrijfmodus ─── */
492.fs-icon-compress { display: none; }
493.pe-editor-frame.pe-fs .fs-icon-expand { display: none; }
494.pe-editor-frame.pe-fs .fs-icon-compress { display: inline; }
495.pe-editor-frame.pe-fs {
496 position: fixed; inset: 0; z-index: 1000;
497 margin: 0; border-top: 0;
498 height: 100dvh;
499 background: var(--paper);
[de21a3b]500 overflow: hidden; /* alléén het tekstveld scrollt, niet het frame zelf */
[d2078f4]501}
[859bace0]502/* In fullscreen vult het schrijfveld de resterende ruimte en scrollt het zelf
503 (max-height: none overschrijft de mobiele box-begrenzing hieronder). */
[d2078f4]504.pe-editor-frame.pe-fs .pe-editor {
[859bace0]505 flex: 1 1 auto; min-height: 0; height: auto; max-height: none;
[d2078f4]506}
[c1a4147]507/* NB: bewust GEEN overflow:hidden op html/body in fullscreen — dat kon blijven
508 hangen (bv. fullscreen verlaten via navigatie) en blokkeerde dan het scrollen van
509 de hele pagina. Het fullscreen-frame (position:fixed, inset:0) dekt de pagina al
510 af, en op touch zijn de scrollbalken verborgen → geen dubbele balk nodig. */
[d2078f4]511
[b12e20d]512/* "Klaar"-knop: alleen in fullscreen zichtbaar (links in de toolbar), duidelijke
513 accent-pill i.p.v. een vierkant icoontje. */
[b988c96]514/* Verberg-regel specifieker dan ".pe-toolbar button" (anders wint die en zie je
515 de Klaar-knop ook inline als kleine knop). Alleen in fullscreen tonen → groot. */
516.pe-toolbar button.pe-fs-done { display: none; }
[b12e20d]517.pe-editor-frame.pe-fs .pe-fs-done {
[43fea32]518 display: inline-flex; align-items: center; gap: .35rem;
519 width: auto !important; height: auto !important; min-height: 40px;
520 padding: .55rem 1.3rem !important; margin-right: .5rem;
[b12e20d]521 background: var(--accent); color: #fff;
[43fea32]522 font-weight: 700; font-size: 1.05rem; border-radius: 999px;
[b12e20d]523}
524.pe-editor-frame.pe-fs .pe-fs-done:hover { background: var(--accent); color: #fff; }
525
[7bc636b]526/* Editor body — looks like prose, behaves like a textarea */
527.pe-editor {
528 width: 100%;
529 box-sizing: border-box;
530 min-height: 420px;
531 padding: 1.25rem 1.5rem;
532 border: 0;
533 background: transparent;
534 color: var(--ink);
535 font-family: var(--font-body, system-ui), serif;
536 font-size: 1.0625rem;
537 line-height: 1.65;
538 outline: none;
539 overflow-y: auto;
540}
541.pe-editor:focus { outline: none; }
[f3f43df]542/* Inline (niet-fullscreen) groeit het schrijfveld gewoon mee met de inhoud — geen
543 interne scroll-box (scroll-binnen-scroll is verwarrend). Op mobiel/tablet gaat
544 typen sowieso fullscreen (zie JS), waar het veld de pagina vult en als enige
545 scrollt. */
546.pe-editor-frame:not(.pe-fs) .pe-editor { overflow: visible; }
[61bb585]547
548/* Touch: het inline content-veld is geen tekstveld maar een tap-vlak → fullscreen
[a623e7e]549 bewerken. Een "✎ Tik om te bewerken"-pill plakt sticky onderaan de container,
550 zodat de hint altijd in beeld is zonder midden in de tekst te staan. */
[61bb585]551.pe-editor.pe-tap-to-edit { cursor: pointer; }
[a623e7e]552.pe-edit-hint { display: none; }
[61bb585]553@media (pointer: coarse) {
[a623e7e]554 .pe-editor-frame:not(.pe-fs) .pe-edit-hint {
555 display: block;
556 position: sticky;
557 bottom: 4.5rem; /* boven de sticky Opslaan/Annuleren-balk */
558 width: max-content;
559 max-width: calc(100% - 2rem);
560 margin: .4rem auto;
[61bb585]561 background: var(--accent); color: #fff;
[a623e7e]562 font-size: .9rem; font-weight: 700; padding: .5rem 1.1rem; border-radius: 999px;
563 box-shadow: 0 4px 14px rgba(0,0,0,.35);
564 pointer-events: none; text-align: center; white-space: nowrap;
[61bb585]565 }
[254872f]566 /* Niet relevant op touch (slepen/selecteren hoort bij inline-bewerken op desktop). */
567 .pe-content-hint { display: none; }
[9163b15]568 /* Inline (niet-fullscreen) op touch: simpel houden — je bewerkt hier toch niet,
569 dus geen opmaak-toolbar en geen losse rand. Alleen de content-preview + de
570 "tik om te bewerken"-pill. De toolbar verschijnt pas in fullscreen. */
571 .pe-editor-frame:not(.pe-fs) .pe-toolbar { display: none; }
572 .pe-editor-frame:not(.pe-fs) { border-top: 0; }
573 .pe-editor-frame:not(.pe-fs) .pe-editor { min-height: 8rem; }
[61bb585]574}
[7bc636b]575.pe-editor.is-dragover {
576 outline: 2px dashed var(--accent);
577 outline-offset: -10px;
578}
579.pe-editor[data-placeholder]:empty::before,
580.pe-editor[data-placeholder]:has(br:only-child)::before {
581 content: attr(data-placeholder);
582 color: var(--ink-muted, #999);
583 pointer-events: none;
584 opacity: .55;
585}
586/* Inline prose styles inside the editor — match the public post styling so
587 what you see is roughly what you'll get. Margins are tighter than on the
588 live site since this is a confined writing space. */
589.pe-editor h1, .pe-editor h2, .pe-editor h3, .pe-editor h4 {
590 font-family: var(--font-display, serif);
591 line-height: 1.2;
592 margin: 1.1rem 0 .35rem;
593}
594.pe-editor h1 { font-size: 1.85rem; }
595.pe-editor h2 { font-size: 1.45rem; }
596.pe-editor h3 { font-size: 1.2rem; }
597.pe-editor p { margin: 0 0 .85em; }
598.pe-editor ul, .pe-editor ol { margin: 0 0 .85em 1.4em; padding: 0; }
599.pe-editor li { margin: .15em 0; }
600.pe-editor blockquote {
601 margin: 1em 0;
602 padding: .15em 0 .15em 1em;
603 border-left: 3px solid var(--accent);
604 color: var(--ink-soft, var(--ink));
605 font-style: italic;
606}
607.pe-editor code {
608 background: var(--paper-2);
609 border: 1px solid var(--rule);
610 border-radius: 4px;
611 padding: .1em .35em;
612 font-family: var(--font-mono, ui-monospace, monospace);
613 font-size: .92em;
614}
615.pe-editor a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
616.pe-editor img {
617 max-width: 100%; height: auto;
618 border-radius: 6px;
619 display: block;
620 margin: 1em auto;
621}
622
623/* Shortcode chips — visible inline placeholder in the editor for
624 [[track:UUID]] / [[album:Name]] / [[playlist:slug]]. They serialize back
625 to plain shortcode text on submit. */
626.sc-chip {
627 display: inline-flex; align-items: center; gap: .3rem;
628 padding: .15em .5em;
629 margin: 0 .15em;
630 background: color-mix(in srgb, var(--accent) 10%, var(--paper-2));
631 border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--rule));
632 border-radius: 999px;
633 color: var(--accent);
634 font-family: var(--font-ui, system-ui), sans-serif;
635 font-size: .85em;
636 font-weight: 600;
637 font-style: normal;
638 white-space: nowrap;
639 user-select: none;
640 cursor: default;
641 vertical-align: baseline;
642}
643.sc-chip-icon { display: inline-flex; opacity: .8; }
644.sc-chip-icon svg { width: 12px; height: 12px; }
645
646/* Status bar below the editor */
647.pe-editor-status {
648 display: flex; align-items: center; justify-content: space-between;
649 gap: .75rem;
650 padding: .45rem 1rem;
651 border-top: 1px solid var(--rule);
652 background: var(--paper-2);
653 color: var(--ink-muted, var(--ink-soft));
654 font-size: .78rem;
655}
656.pe-char-count { font-variant-numeric: tabular-nums; }
657
658/* ─── Track picker modal (P59) ─────────────────────────────────
659 Mobile-first: full-screen bottom-sheet on phones, centered card
660 on desktop. Lock body scroll while open via .tp-locked on body. */
661.tp-modal {
662 position: fixed; inset: 0;
663 z-index: 1000;
664 display: flex; align-items: stretch; justify-content: center;
665 /* Avoid the iOS home-indicator + the keyboard when search is focused */
666 padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
667}
668.tp-modal[hidden] { display: none; }
669.tp-backdrop {
670 position: absolute; inset: 0;
671 background: color-mix(in srgb, var(--ink) 55%, transparent);
672 backdrop-filter: blur(4px);
673 -webkit-backdrop-filter: blur(4px);
674 animation: tp-bd-in .18s ease-out;
675}
676@keyframes tp-bd-in { from { opacity: 0 } to { opacity: 1 } }
677
678/* Mobile: sheet docks to the bottom and fills viewport almost completely */
679.tp-sheet {
680 position: relative;
681 margin-top: auto;
682 width: 100%;
683 max-height: calc(100dvh - env(safe-area-inset-top) - 1rem);
684 background: var(--paper);
685 border-top: 1px solid var(--rule);
686 border-radius: 16px 16px 0 0;
687 box-shadow:
688 0 -2px 8px color-mix(in srgb, var(--ink) 8%, transparent),
689 0 -16px 48px color-mix(in srgb, var(--ink) 18%, transparent);
690 display: flex; flex-direction: column;
691 animation: tp-sheet-up .22s cubic-bezier(.2, .8, .25, 1);
692 overflow: hidden;
693}
694@keyframes tp-sheet-up {
695 from { transform: translateY(100%); opacity: .8; }
696 to { transform: translateY(0); opacity: 1; }
697}
698
699/* Header — title + close, with a small grab-handle bar on mobile */
700.tp-header {
701 display: flex; align-items: center; justify-content: space-between;
702 gap: .75rem;
703 padding: .85rem 1rem .65rem;
704 border-bottom: 1px solid var(--rule);
705 position: relative;
706}
707.tp-header::before {
708 /* Grab-handle: visible on mobile only */
709 content: '';
710 position: absolute;
711 top: .35rem; left: 50%;
712 transform: translateX(-50%);
713 width: 38px; height: 4px;
714 background: var(--rule-2, var(--rule));
715 border-radius: 2px;
716}
717.tp-h2 {
718 margin: .35rem 0 0;
719 font-family: var(--font-display, serif);
720 font-size: 1.15rem; font-weight: 600;
721 color: var(--ink);
722 line-height: 1.1;
723}
724.tp-close {
725 width: 32px; height: 32px; border-radius: 8px;
726 display: inline-flex; align-items: center; justify-content: center;
727 background: transparent; border: 1px solid transparent;
728 color: var(--ink-muted, var(--ink-soft));
729 cursor: pointer;
730 transition: background var(--transition), color var(--transition), border-color var(--transition);
731 -webkit-tap-highlight-color: transparent;
732 margin-top: .35rem;
733}
734.tp-close:hover, .tp-close:focus-visible {
735 background: var(--paper-2);
736 color: var(--ink);
737 outline: none;
738}
739.tp-close svg { width: 18px; height: 18px; }
740
741/* Search row — sticky just below header so list scrolls underneath */
742.tp-search-row {
743 position: relative;
744 padding: .65rem 1rem;
745 border-bottom: 1px solid var(--rule);
746 background: var(--paper);
747}
748.tp-search-icon {
749 position: absolute;
750 top: 50%; left: 1.65rem;
751 transform: translateY(-50%);
752 color: var(--ink-muted, var(--ink-soft));
753 pointer-events: none;
754 display: inline-flex;
755}
756.tp-search-icon svg { width: 16px; height: 16px; }
757.tp-search {
758 width: 100%; box-sizing: border-box;
759 padding: .65rem .85rem .65rem 2.4rem;
760 font-family: var(--font-ui, system-ui), sans-serif;
761 font-size: 1rem;
762 background: var(--paper-2);
763 color: var(--ink);
764 border: 1px solid var(--rule);
765 border-radius: 9px;
766 -webkit-appearance: none;
767 appearance: none;
768}
769.tp-search:focus {
770 outline: none;
771 border-color: var(--accent);
772 box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
773}
774
775/* List — vertically scrollable, takes remaining sheet height */
776.tp-list {
777 flex: 1 1 auto;
778 overflow-y: auto;
779 -webkit-overflow-scrolling: touch;
780 padding: .35rem .35rem 1rem;
781}
782.tp-empty {
783 padding: 1.5rem 1rem;
784 text-align: center;
785 color: var(--ink-muted, var(--ink-soft));
786 font-size: .9rem;
787}
788
789/* Track row — tap target ≥ 56px for mobile */
790.tp-row {
791 display: grid;
792 grid-template-columns: 44px 1fr auto;
793 align-items: center;
794 gap: .75rem;
795 width: 100%;
796 padding: .55rem .65rem;
797 border: 0; background: transparent;
798 border-radius: 10px;
799 text-align: left;
800 cursor: pointer;
801 color: inherit;
802 font: inherit;
803 transition: background var(--transition);
804 -webkit-tap-highlight-color: transparent;
805}
806.tp-row:hover, .tp-row:focus-visible {
807 background: color-mix(in srgb, var(--accent) 8%, var(--paper-2));
808 outline: none;
809}
810.tp-row:active { transform: scale(.98); }
811.tp-row[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
812
813.tp-cover {
814 width: 44px; height: 44px;
815 border-radius: 6px;
816 background-size: cover; background-position: center;
817 background-color: var(--rule);
818 display: inline-flex; align-items: center; justify-content: center;
819 flex-shrink: 0;
820}
821.tp-cover-empty {
822 background: linear-gradient(135deg,
823 color-mix(in srgb, var(--accent) 30%, var(--paper-2)),
824 color-mix(in srgb, var(--accent) 8%, var(--paper-2)));
825 color: var(--accent);
826}
827.tp-cover-empty svg { width: 18px; height: 18px; opacity: .8; }
828
829.tp-meta {
830 display: flex; flex-direction: column;
831 min-width: 0;
832 line-height: 1.25;
833}
834.tp-row-title {
835 font-weight: 600; font-size: .94rem;
836 color: var(--ink);
837 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
838}
839.tp-row-artist {
840 font-size: .8rem;
841 color: var(--ink-muted, var(--ink-soft));
842 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
843 margin-top: .1rem;
844}
845.tp-duration {
846 font-variant-numeric: tabular-nums;
847 font-size: .8rem;
848 color: var(--ink-muted, var(--ink-soft));
849 flex-shrink: 0;
850}
851
852/* Body lock when modal open */
853body.tp-locked { overflow: hidden; touch-action: none; }
854
855/* Desktop: centered card, max-width ~520px */
856@media (min-width: 640px) {
857 .tp-modal {
858 align-items: center;
859 padding: 1.5rem;
860 }
861 .tp-sheet {
862 margin-top: 0;
863 width: 100%;
864 max-width: 520px;
865 max-height: 80dvh;
866 border-radius: 14px;
867 border: 1px solid var(--rule);
868 animation: tp-sheet-pop .2s cubic-bezier(.2, .8, .25, 1);
869 }
870 .tp-header::before { display: none; } /* hide grab-handle on desktop */
871 .tp-header { padding: 1rem 1.25rem .75rem; }
872 .tp-h2 { margin-top: 0; font-size: 1.25rem; }
873 .tp-close { margin-top: 0; }
874 @keyframes tp-sheet-pop {
875 from { transform: translateY(-8px) scale(.97); opacity: 0; }
876 to { transform: translateY(0) scale(1); opacity: 1; }
877 }
878}
879
880/* ─── Buttons ───────────────────────────────────────────────────── */
881.pe-btn {
882 display: inline-flex; align-items: center; gap: 0.4rem;
883 padding: 0.55rem 1rem;
884 border: 1px solid var(--rule);
885 background: var(--paper-2);
886 color: var(--ink);
887 font-family: var(--font-ui, system-ui), sans-serif;
888 font-size: 0.9rem; font-weight: 500;
889 text-decoration: none;
890 border-radius: 6px;
891 cursor: pointer;
892 transition: background 120ms, border-color 120ms;
893 min-height: 40px;
894 -webkit-tap-highlight-color: transparent;
895}
896.pe-btn:hover { border-color: var(--accent); }
897.pe-btn:active { transform: scale(0.97); }
898.pe-btn-tiny {
899 padding: 0.35rem 0.7rem;
900 font-size: 0.85rem;
901 min-height: 32px;
902}
903.pe-btn-secondary { background: var(--paper-2); }
904.pe-btn-primary {
905 background: var(--accent); color: white;
906 border-color: var(--accent);
907}
908.pe-btn-primary:hover { opacity: 0.92; border-color: var(--accent); }
909.pe-btn-success {
910 background: #16a34a; color: white;
911 border-color: #16a34a;
912}
913.pe-btn-success:hover { opacity: 0.92; border-color: #16a34a; }
914
915.pe-status {
916 color: var(--ink-muted, var(--ink-soft));
917 font-size: 0.8rem;
918}
919.pe-status.is-error { color: #dc2626; }
920
921/* ─── Checkboxes (clean inline row) ─────────────────────────────── */
922.pe-checkboxes {
923 display: flex; flex-direction: column;
924 gap: 0.5rem;
925 padding-top: 0.25rem;
926}
927.pe-checkbox {
928 display: inline-flex; align-items: center; gap: 0.5rem;
929 cursor: pointer;
930 font-size: 0.95rem;
931 color: var(--ink);
932 user-select: none;
933}
934.pe-checkbox input[type="checkbox"] {
935 width: 18px; height: 18px;
936 margin: 0;
937 cursor: pointer;
938 accent-color: var(--accent);
939}
940
[edc462d]941/* Vastpinnen: checkbox + ▲▼-stepper met beschrijving (i.p.v. een ruw rang-getal). */
942.pe-pin { display: flex; flex-direction: column; gap: 0.45rem; }
943.pe-pin-pos { display: flex; align-items: center; gap: 0.55rem; padding-left: 1.65rem; }
944.pe-pin-pos[hidden] { display: none; }
945.pe-pin-steps { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
946.pe-pin-btn {
947 width: 30px; height: 28px; padding: 0;
948 border: none; background: var(--paper-2); color: var(--ink);
949 cursor: pointer; font-size: 0.68rem; line-height: 1;
950 display: inline-flex; align-items: center; justify-content: center;
[7bc636b]951}
[edc462d]952.pe-pin-btn + .pe-pin-btn { border-left: 1px solid var(--rule); }
953.pe-pin-btn:hover { background: color-mix(in srgb, var(--accent) 14%, var(--paper-2)); color: var(--accent); }
954.pe-pin-btn:disabled { opacity: 0.35; cursor: default; }
955.pe-pin-label { font-size: 0.85rem; color: var(--accent); font-weight: 600; }
[7bc636b]956
957/* ─── Sticky action footer ──────────────────────────────────────── */
958.pe-actions {
959 position: sticky;
960 bottom: 0;
961 display: flex; align-items: center;
962 gap: 0.5rem;
963 padding: 0.85rem 1rem;
964 margin: 0.5rem -1rem 0; /* extend to viewport edges on tight container */
965 background: color-mix(in srgb, var(--paper) 94%, transparent);
966 -webkit-backdrop-filter: blur(8px);
967 backdrop-filter: blur(8px);
968 border-top: 1px solid var(--rule);
969 z-index: 10;
970}
971.pe-actions-spacer { flex: 1; }
972
[2beef82]973/* De editor is een focus-scherm: verberg de mobiele site-tabbalk (Home/Zoek/…)
974 zodat er niet twee balken onderaan stapelen (Opslaan-balk + tabbalk). De
975 Opslaan/Annuleren-balk wordt dan de enige onderbalk → gewoon op bottom:0,
976 geen tab-offset meer nodig. Op desktop is de tabbalk toch al verborgen. */
977body:has(.post-edit-page) .bottom-tab { display: none; }
978/* Audiospeler (indien aan het spelen) niet meer 56px optillen voor de nu-verborgen
979 tabbalk, anders zou die zweven boven de actiebalk. */
980body:has(.post-edit-page) .audio-player { bottom: 0; }
[48ebfa7]981
982/* ── Afbeeldings-editor (draaien / bijsnijden / spiegelen) ── */
983.imed-backdrop {
984 position: fixed; inset: 0; z-index: 9999;
985 display: flex; align-items: center; justify-content: center;
986 background: rgba(0,0,0,.62); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
987 padding: 14px;
988}
989.imed-modal {
990 display: flex; flex-direction: column; gap: 12px;
991 width: 100%; max-width: 640px; max-height: 92vh;
992 background: var(--paper, #fff); color: var(--ink, #111);
993 border: 1px solid var(--rule, rgba(128,128,128,.3)); border-radius: 14px;
994 padding: 14px; box-sizing: border-box;
995}
996.imed-stage {
[5a394e5]997 height: 58vh; flex: 0 0 auto;
[48ebfa7]998 background: var(--paper-2, rgba(128,128,128,.08)); border-radius: 10px; overflow: hidden;
999}
1000.imed-stage img { display: block; max-width: 100%; }
[5a394e5]1001/* Cropper z'n container moet de volle stage-hoogte vullen — anders klapt 'ie dicht
1002 in een flex-kolom zonder expliciete hoogte → leeg bewerk-venster (geen afbeelding). */
1003.imed-stage .cropper-container { width: 100% !important; height: 100% !important; }
[48ebfa7]1004.imed-tools {
1005 display: flex; flex-wrap: wrap; gap: 6px; justify-content: center;
1006}
1007.imed-tools button {
1008 width: 42px; height: 42px; font-size: 18px; line-height: 1;
1009 border: 1px solid var(--rule, rgba(128,128,128,.4)); border-radius: 10px;
1010 background: var(--paper-2, transparent); color: inherit; cursor: pointer;
1011}
1012.imed-tools button:hover { border-color: var(--accent); }
1013.imed-actions { display: flex; gap: 8px; justify-content: flex-end; }
[7bc636b]1014</style>
1015
1016<script>
1017(function() {
1018
1019 // ── Cover upload ────────────────────────────────────────────────
1020 const coverField = document.getElementById('cover-upload-field');
1021 const coverTrigger = document.getElementById('cover-upload-trigger');
1022 const coverUrl = document.getElementById('cover-url-field');
1023 const coverStatus = document.getElementById('cover-upload-status');
1024 const coverWrap = document.getElementById('cover-preview-wrap');
1025 const coverImg = document.getElementById('cover-preview-img');
1026
1027 async function uploadImage(file) {
1028 const fd = new FormData();
1029 fd.append('image', file);
1030 const res = await fetch('/posts/upload-image', { method: 'POST', body: fd });
1031 if (!res.ok) {
1032 const j = await res.json().catch(() => ({}));
1033 throw new Error(j.error || ('Upload failed (' + res.status + ')'));
1034 }
1035 return await res.json(); // {url, size, mime}
1036 }
1037
[48ebfa7]1038 // ── Afbeeldings-editor (draaien / bijsnijden / spiegelen) ──────────
1039 // Lazy-load Cropper.js (lokaal gevendord) pas bij het eerste gebruik.
1040 let _cropperReady = null;
1041 function ensureCropper() {
1042 if (window.Cropper) return Promise.resolve();
1043 if (_cropperReady) return _cropperReady;
1044 _cropperReady = new Promise((resolve, reject) => {
1045 if (!document.querySelector('link[data-cropper-css]')) {
1046 const l = document.createElement('link');
1047 l.rel = 'stylesheet'; l.href = '/assets/vendor/cropper.min.css'; l.setAttribute('data-cropper-css', '');
1048 document.head.appendChild(l);
1049 }
1050 const s = document.createElement('script');
1051 s.src = '/assets/vendor/cropper.min.js';
1052 s.onload = () => resolve();
1053 s.onerror = () => reject(new Error('cropper load failed'));
1054 document.head.appendChild(s);
1055 });
1056 return _cropperReady;
1057 }
1058
1059 // Opent de editor voor een gekozen bestand; resolved met een bewerkt File,
1060 // of null als de gebruiker annuleert. Animatie-GIF's worden niet door de
1061 // canvas-editor gehaald (zouden statisch worden) — die uploaden direct.
1062 async function openImageEditor(file) {
1063 if (!file || !file.type || !file.type.startsWith('image/')) return file;
1064 if (file.type === 'image/gif') return file; // behoud animatie
1065 try { await ensureCropper(); } catch (_) { return file; } // editor onbeschikbaar → direct uploaden
1066
1067 return new Promise((resolve) => {
1068 const back = document.createElement('div');
1069 back.className = 'imed-backdrop';
1070 back.innerHTML =
1071 '<div class="imed-modal" role="dialog" aria-modal="true" aria-label="<%= t('imed.title') %>">' +
1072 '<div class="imed-stage"><img alt=""></div>' +
1073 '<div class="imed-tools">' +
1074 '<button type="button" data-act="rl" title="<%= t('imed.rotate_left') %>">⟲</button>' +
1075 '<button type="button" data-act="rr" title="<%= t('imed.rotate_right') %>">⟳</button>' +
1076 '<button type="button" data-act="fh" title="<%= t('imed.flip_h') %>">⇆</button>' +
1077 '<button type="button" data-act="fv" title="<%= t('imed.flip_v') %>">⇅</button>' +
1078 '<button type="button" data-act="zi" title="<%= t('imed.zoom_in') %>">+</button>' +
1079 '<button type="button" data-act="zo" title="<%= t('imed.zoom_out') %>">-</button>' +
1080 '<button type="button" data-act="reset" title="<%= t('imed.reset') %>">↺</button>' +
1081 '</div>' +
1082 '<div class="imed-actions">' +
1083 '<button type="button" data-act="cancel" class="pe-btn pe-btn-secondary"><%= t('imed.cancel') %></button>' +
1084 '<button type="button" data-act="apply" class="pe-btn pe-btn-primary"><%= t('imed.apply') %></button>' +
1085 '</div>' +
1086 '</div>';
1087 document.body.appendChild(back);
1088 const img = back.querySelector('img');
1089 const url = URL.createObjectURL(file);
1090 let cropper = null, sx = 1, sy = 1;
1091
1092 function cleanup() {
1093 try { if (cropper) cropper.destroy(); } catch (_) {}
1094 URL.revokeObjectURL(url);
1095 back.remove();
1096 document.removeEventListener('keydown', onKey);
1097 }
1098 function onKey(e) { if (e.key === 'Escape') { cleanup(); resolve(null); } }
1099 document.addEventListener('keydown', onKey);
1100
1101 img.onload = () => {
1102 cropper = new Cropper(img, { viewMode: 1, autoCropArea: 1, background: false, responsive: true });
1103 };
[9effb80]1104 img.onerror = () => { cleanup(); resolve(file); }; // kon niet laden → upload het origineel
[48ebfa7]1105 img.src = url;
1106
1107 back.addEventListener('click', (e) => {
1108 const btn = e.target.closest('[data-act]');
1109 if (e.target === back) { cleanup(); resolve(null); return; }
1110 if (!btn || !cropper) return;
1111 const a = btn.getAttribute('data-act');
1112 if (a === 'rl') cropper.rotate(-90);
1113 else if (a === 'rr') cropper.rotate(90);
1114 else if (a === 'fh') { sx = -sx; cropper.scaleX(sx); }
1115 else if (a === 'fv') { sy = -sy; cropper.scaleY(sy); }
1116 else if (a === 'zi') cropper.zoom(0.1);
1117 else if (a === 'zo') cropper.zoom(-0.1);
1118 else if (a === 'reset') { sx = 1; sy = 1; cropper.reset(); }
1119 else if (a === 'cancel') { cleanup(); resolve(null); }
1120 else if (a === 'apply') {
1121 const canvas = cropper.getCroppedCanvas({ maxWidth: 3000, maxHeight: 3000, imageSmoothingEnabled: true, imageSmoothingQuality: 'high' });
1122 const png = (file.type === 'image/png' || file.type === 'image/webp');
1123 const mime = png ? 'image/png' : 'image/jpeg';
1124 const ext = png ? '.png' : '.jpg';
1125 canvas.toBlob((blob) => {
1126 cleanup();
1127 if (!blob) { resolve(file); return; }
1128 const base = (file.name || 'afbeelding').replace(/\.[^.]+$/, '');
1129 resolve(new File([blob], base + ext, { type: mime }));
1130 }, mime, 0.92);
1131 }
1132 });
1133 });
1134 }
1135
[7bc636b]1136 function showCoverPreview(url) {
1137 if (!coverWrap || !coverImg) return;
1138 if (url) {
1139 coverImg.src = url;
1140 coverImg.hidden = false;
1141 coverWrap.removeAttribute('data-empty');
1142 const emptyIcon = coverWrap.querySelector('.pe-cover-empty');
1143 if (emptyIcon) emptyIcon.remove();
1144 } else {
1145 coverImg.hidden = true;
1146 coverImg.src = '';
1147 coverWrap.setAttribute('data-empty', '');
1148 if (!coverWrap.querySelector('.pe-cover-empty')) {
1149 const span = document.createElement('span');
1150 span.className = 'pe-cover-empty';
1151 span.textContent = '🖼';
1152 coverWrap.appendChild(span);
1153 }
1154 }
1155 }
1156
1157 if (coverTrigger && coverField) {
1158 coverTrigger.addEventListener('click', () => coverField.click());
1159 }
1160 if (coverField) {
1161 coverField.addEventListener('change', async () => {
1162 if (!coverField.files[0]) return;
[48ebfa7]1163 const edited = await openImageEditor(coverField.files[0]);
1164 coverField.value = '';
1165 if (!edited) return; // geannuleerd
[7bc636b]1166 coverStatus.classList.remove('is-error');
[4885eab]1167 coverStatus.textContent = '<%= t('pedit.js_uploading') %>';
[7bc636b]1168 try {
[48ebfa7]1169 const j = await uploadImage(edited);
[7bc636b]1170 coverUrl.value = j.url;
1171 showCoverPreview(j.url);
[4885eab]1172 coverStatus.textContent = '<%= t('pedit.js_uploaded') %> ✓';
[7bc636b]1173 setTimeout(() => { coverStatus.textContent = ''; }, 2000);
1174 } catch (e) {
1175 coverStatus.classList.add('is-error');
[4885eab]1176 coverStatus.textContent = '<%= t('pedit.js_failed') %>: ' + e.message;
[7bc636b]1177 }
1178 });
1179 }
1180 // Live-update preview when user pastes a URL manually
1181 if (coverUrl) {
1182 coverUrl.addEventListener('input', () => {
1183 const v = coverUrl.value.trim();
1184 if (v) showCoverPreview(v); else showCoverPreview('');
1185 });
1186 }
1187
1188 // ── WYSIWYG editor (P58) ────────────────────────────────────────
1189 // Architecture:
1190 // - Visible <div contenteditable> (`#content-editor`) is what the user
1191 // types in; it shows real HTML (formatted, not raw markup).
1192 // - Hidden <input name="content"> (`#content-hidden`) is what submits.
1193 // On submit we serialize the editor's HTML into it, with shortcode
1194 // chips reduced back to their [[track:UUID]]/[[album:Name]]/[[playlist:slug]] text.
1195 // - Initial content comes from a <script type="application/json"> tag
1196 // to avoid HTML-escape-into-DOM issues; we set innerHTML once on load
1197 // and walk text nodes to render shortcode tokens as chips.
1198 const contentField = document.getElementById('content-upload-field');
1199 const contentBtn = document.getElementById('insert-image-btn');
1200 const contentStatus = document.getElementById('content-upload-status');
1201 const editor = document.getElementById('content-editor');
1202 const hiddenField = document.getElementById('content-hidden');
1203 const charCountEl = document.getElementById('char-count');
1204 const initialEl = document.getElementById('initial-content');
1205 const toolbar = document.getElementById('pe-toolbar');
1206 const form = editor && editor.closest('form');
1207
1208 if (!editor) return;
1209
[a0bff44]1210 // Titel alleen automatisch focussen op desktop (muis/trackpad). Op touch zou
1211 // dit meteen het toetsenbord openen bij het openen van de editor — niet gewenst.
1212 try {
1213 const titleInput = form && form.querySelector('input[name="title"]');
1214 if (titleInput && window.matchMedia && window.matchMedia('(hover: hover) and (pointer: fine)').matches) {
1215 titleInput.focus({ preventScroll: true });
1216 }
1217 } catch (_) {}
1218
[7bc636b]1219 // ── Shortcode chip rendering / serialization ────────────────────
1220 // Pattern matches [[track:UUID]] / [[album:any text]] / [[playlist:slug]]
1221 // — but we DON'T want to chipify text the user is mid-typing inside an
1222 // HTML attribute; since chipify only walks text nodes (never attribute
1223 // values) that's already safe.
[1907a18]1224 const SC_RE = /\[\[(track|album|playlist|embed):([^\]]+)\]\]/g;
[7bc636b]1225
1226 const SC_ICONS = {
1227 track: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="6 4 20 12 6 20 6 4"/></svg>',
1228 album: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="3"/></svg>',
1229 playlist: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="15" y2="18"/><polygon points="3 5 3 13 9 9"/></svg>',
[1907a18]1230 embed: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><polygon points="10 9 15.5 12 10 15"/></svg>',
[7bc636b]1231 };
1232
1233 function chipLabel(kind, value) {
1234 if (kind === 'track') {
1235 // UUIDs are noisy — show a 6-char prefix for visual hint
1236 const v = String(value || '');
[4885eab]1237 return '<%= t('pedit.chip_track') %> ' + (v.length > 8 ? v.slice(0, 6) + '…' : v);
[7bc636b]1238 }
[4885eab]1239 if (kind === 'album') return '<%= t('pedit.chip_album') %> ' + value;
1240 if (kind === 'playlist') return '<%= t('pedit.chip_playlist') %> ' + value;
[1907a18]1241 if (kind === 'embed') {
1242 const clean = String(value || '').replace(/^https?:\/\/(www\.)?/, '');
1243 return '▶ ' + (clean.length > 36 ? clean.slice(0, 34) + '…' : clean);
1244 }
[7bc636b]1245 return value;
1246 }
1247
1248 function makeChip(kind, value) {
1249 const span = document.createElement('span');
1250 span.className = 'sc-chip';
1251 span.contentEditable = 'false';
1252 span.setAttribute('data-sc', kind + ':' + value);
1253 span.innerHTML =
1254 '<span class="sc-chip-icon" aria-hidden="true">' + (SC_ICONS[kind] || '') + '</span>' +
1255 '<span class="sc-chip-label"></span>';
1256 span.querySelector('.sc-chip-label').textContent = chipLabel(kind, value);
1257 return span;
1258 }
1259
1260 // Walk text nodes inside `root` and replace [[type:value]] tokens with chips.
1261 function chipifyShortcodes(root) {
1262 const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
1263 const targets = [];
1264 while (walker.nextNode()) {
1265 const n = walker.currentNode;
1266 // Skip text inside existing chips (their .sc-chip-label is set via .textContent so the [[...]] text never appears)
1267 if (n.parentElement && n.parentElement.closest('.sc-chip')) continue;
1268 if (SC_RE.test(n.nodeValue)) targets.push(n);
1269 SC_RE.lastIndex = 0;
1270 }
1271 for (const node of targets) {
1272 const txt = node.nodeValue;
1273 const frag = document.createDocumentFragment();
1274 let last = 0;
1275 let m;
1276 SC_RE.lastIndex = 0;
1277 while ((m = SC_RE.exec(txt)) !== null) {
1278 if (m.index > last) frag.appendChild(document.createTextNode(txt.slice(last, m.index)));
1279 frag.appendChild(makeChip(m[1], m[2].trim()));
1280 last = m.index + m[0].length;
1281 }
1282 if (last < txt.length) frag.appendChild(document.createTextNode(txt.slice(last)));
1283 node.parentNode.replaceChild(frag, node);
1284 }
1285 }
1286
1287 // Inverse of chipify: clone the editor, replace every chip with its text.
1288 function serializeChips(rootClone) {
1289 const chips = rootClone.querySelectorAll('.sc-chip[data-sc]');
1290 for (const c of chips) {
1291 const txt = '[[' + c.getAttribute('data-sc') + ']]';
1292 c.replaceWith(document.createTextNode(txt));
1293 }
1294 }
1295
1296 // ── Boot: load initial content as HTML, then render shortcodes as chips
1297 try {
1298 const initial = JSON.parse(initialEl.textContent || '""');
1299 editor.innerHTML = initial || '';
1300 chipifyShortcodes(editor);
1301 } catch (e) {
1302 console.error('[editor] could not parse initial content', e);
1303 editor.innerHTML = '';
1304 }
1305
1306 // ── Char counter
1307 function updateCharCount() {
1308 const text = (editor.innerText || '').replace(/\s+/g, ' ').trim();
1309 if (charCountEl) charCountEl.textContent = String(text.length);
1310 }
1311 updateCharCount();
1312 editor.addEventListener('input', updateCharCount);
1313
1314 // ── Toolbar wiring
[cbfbf88]1315 // Houd de scrollpositie vast rond een edit-commando. execCommand/insert scrollt
1316 // standaard de caret in beeld → het beeld "verspringt" bij het aanklikken van een
[f8e8f9e]1317 // opmaakknop. We leggen ALLE scrollbare voorouders (editor, frame, #pcms-main, …)
1318 // + de pagina vast en zetten ze terug — sync én over een paar frames, want Chrome
1319 // scrollt soms pas een frame later. De gebruiker scrollt zo zelf.
1320 function scrollableAncestors(el) {
1321 const list = [];
1322 let node = el;
1323 while (node && node !== document.body && node !== document.documentElement) {
1324 const oy = getComputedStyle(node).overflowY;
1325 if (oy === 'auto' || oy === 'scroll' || oy === 'overlay') list.push(node);
1326 node = node.parentElement;
1327 }
1328 return list;
1329 }
[cbfbf88]1330 function keepScroll(fn) {
[e22230e]1331 // In fullscreen staat de pagina vast (body overflow:hidden) en mag het veld
1332 // gewoon naar de caret scrollen — geen pagina-sprong mogelijk, dus niets fixen.
1333 const frame = document.querySelector('.pe-editor-frame');
1334 if (frame && frame.classList.contains('pe-fs')) { fn(); return; }
[f8e8f9e]1335 const wx = window.scrollX, wy = window.scrollY;
1336 const anc = scrollableAncestors(editor).map(function (n) { return [n, n.scrollTop, n.scrollLeft]; });
1337 const restore = function () {
1338 window.scrollTo(wx, wy);
1339 anc.forEach(function (e) { e[0].scrollTop = e[1]; e[0].scrollLeft = e[2]; });
1340 };
[cbfbf88]1341 fn();
[f8e8f9e]1342 restore();
[e22230e]1343 requestAnimationFrame(restore);
[cbfbf88]1344 }
[7bc636b]1345 function execCmd(cmd, arg) {
[cbfbf88]1346 keepScroll(function () {
1347 editor.focus({ preventScroll: true });
1348 document.execCommand(cmd, false, arg);
1349 });
[7bc636b]1350 updateToolbarState();
1351 updateCharCount();
1352 }
1353 function wrapCode() {
1354 const sel = window.getSelection();
1355 if (!sel || sel.rangeCount === 0 || sel.isCollapsed) return;
[cbfbf88]1356 keepScroll(function () {
1357 const range = sel.getRangeAt(0);
1358 const code = document.createElement('code');
1359 code.textContent = sel.toString();
1360 range.deleteContents();
1361 range.insertNode(code);
1362 // Move caret after the new node
1363 range.setStartAfter(code);
1364 range.collapse(true);
1365 sel.removeAllRanges();
1366 sel.addRange(range);
1367 editor.focus({ preventScroll: true });
1368 });
[7bc636b]1369 }
1370 function linkPrompt() {
[4885eab]1371 const url = window.prompt('<%= t('pedit.js_link_prompt') %>');
[7bc636b]1372 if (!url) return;
1373 execCmd('createLink', url);
1374 }
[91d948c]1375 // De huidige selectie zit in een <blockquote> binnen de editor? Geef 'm terug.
1376 function blockquoteAncestor() {
1377 const sel = window.getSelection();
1378 if (!sel || sel.rangeCount === 0) return null;
1379 let node = sel.anchorNode;
1380 while (node && node !== editor) {
1381 if (node.nodeType === 1 && node.tagName === 'BLOCKQUOTE') return node;
1382 node = node.parentNode;
1383 }
1384 return null;
1385 }
1386 // Echte toggle: execCommand('formatBlock','blockquote') zet 'm wél AAN maar
1387 // krijgt 'm nooit meer UIT (browser-quirk). Staat de caret al in een quote →
1388 // pak de wrapper uit; anders pas blockquote toe.
1389 function toggleBlockquote() {
[cbfbf88]1390 keepScroll(function () {
1391 editor.focus({ preventScroll: true });
1392 const bq = blockquoteAncestor();
1393 if (bq) {
1394 const parent = bq.parentNode;
1395 // Inhoud uit de quote halen, op z'n plek, en de lege wrapper verwijderen.
1396 const ref = bq;
1397 let firstMoved = null;
1398 while (bq.firstChild) {
1399 const child = bq.firstChild;
1400 if (!firstMoved) firstMoved = child;
1401 parent.insertBefore(child, ref);
1402 }
1403 parent.removeChild(bq);
1404 // Caret terugzetten in de uitgepakte inhoud.
1405 if (firstMoved) {
1406 const sel = window.getSelection();
1407 const range = document.createRange();
1408 range.selectNodeContents(firstMoved.nodeType === 1 ? firstMoved : parent);
1409 range.collapse(false);
1410 sel.removeAllRanges();
1411 sel.addRange(range);
1412 }
1413 } else {
1414 document.execCommand('formatBlock', false, 'blockquote');
[91d948c]1415 }
[cbfbf88]1416 });
[91d948c]1417 updateToolbarState();
1418 updateCharCount();
1419 }
[7bc636b]1420
1421 if (toolbar) {
[a7e8e19]1422 // CRUCIAAL (mobiel + desktop): voorkom dat een toolbar-knop de focus/selectie
1423 // uit het editor-veld steelt. Zonder dit raakt de selectie kwijt bij het tikken
1424 // → execCommand werkt op een lege selectie (vet kan niet meer UIT) én de browser
1425 // scrollt de caret opnieuw in beeld (de "sprong naar beneden"). preventDefault op
1426 // mousedown houdt de focus in de editor; de click blijft gewoon vuren.
1427 toolbar.addEventListener('mousedown', (e) => {
1428 if (e.target.closest('button')) e.preventDefault();
1429 });
[7bc636b]1430 toolbar.addEventListener('click', (e) => {
1431 const btn = e.target.closest('button[data-cmd]');
1432 if (!btn) return;
1433 e.preventDefault();
1434 const cmd = btn.dataset.cmd;
1435 const arg = btn.dataset.arg || null;
1436 if (cmd === 'link-prompt') linkPrompt();
1437 else if (cmd === 'code-wrap') wrapCode();
[91d948c]1438 else if (cmd === 'formatBlock' && arg === 'blockquote') toggleBlockquote();
[7bc636b]1439 else execCmd(cmd, arg);
1440 });
1441 }
1442
[d2078f4]1443 // ── Volledig-scherm schrijfmodus: het schrijfveld vult de hele pagina.
1444 const fsBtn = document.getElementById('pe-fullscreen-btn');
1445 const editorFrame = document.querySelector('.pe-editor-frame');
[61bb585]1446 const isTouch = !!(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
[06f3791]1447
1448 // Op mobiel duwt het toetsenbord de zichtbare (visual) viewport omhoog terwijl
1449 // een position:fixed-frame aan de LAYOUT-viewport blijft hangen → de toolbar
1450 // schuift uit beeld. Houd het fullscreen-frame daarom gelijk aan de visual
1451 // viewport (top + hoogte), zodat de toolbar altijd bovenaan zichtbaar blijft.
1452 function syncFsViewport() {
1453 if (!editorFrame || !editorFrame.classList.contains('pe-fs')) return;
1454 const vv = window.visualViewport;
1455 if (!vv) return;
1456 editorFrame.style.top = vv.offsetTop + 'px';
1457 editorFrame.style.height = vv.height + 'px';
1458 }
1459 function clearFsViewport() {
1460 if (!editorFrame) return;
1461 editorFrame.style.top = '';
1462 editorFrame.style.height = '';
1463 }
[b12e20d]1464 function isFs() { return !!(editorFrame && editorFrame.classList.contains('pe-fs')); }
1465 function applyFs(on) {
[d2078f4]1466 if (!editorFrame) return;
[b12e20d]1467 editorFrame.classList.toggle('pe-fs', on);
[d2078f4]1468 document.body.classList.toggle('pe-fs-open', on);
[de21a3b]1469 document.documentElement.classList.toggle('pe-fs-open', on);
[d2078f4]1470 if (fsBtn) {
1471 fsBtn.setAttribute('aria-pressed', on ? 'true' : 'false');
[4885eab]1472 fsBtn.title = on ? '<%= t('pedit.tb_done') %>' : '<%= t('pedit.tb_fullscreen') %>';
[d2078f4]1473 }
[06f3791]1474 if (window.visualViewport) {
1475 if (on) {
1476 window.visualViewport.addEventListener('resize', syncFsViewport);
1477 window.visualViewport.addEventListener('scroll', syncFsViewport);
1478 syncFsViewport();
1479 } else {
1480 window.visualViewport.removeEventListener('resize', syncFsViewport);
1481 window.visualViewport.removeEventListener('scroll', syncFsViewport);
1482 clearFsViewport();
1483 }
1484 }
[61bb585]1485 // Op touch is het veld inline NIET bewerkbaar; alleen in fullscreen wel.
1486 if (isTouch) editor.setAttribute('contenteditable', on ? 'true' : 'false');
[a4f6827]1487 if (on) {
1488 editor.focus({ preventScroll: true });
1489 } else {
1490 if (isTouch) editor.blur();
[b12e20d]1491 // Bij sluiten: naar de TOP van de content scrollen i.p.v. ergens onderaan
[a4f6827]1492 // (footer) te blijven hangen.
1493 requestAnimationFrame(function () {
1494 try { editorFrame.scrollIntoView({ block: 'start' }); } catch (_) {}
1495 });
1496 }
[d2078f4]1497 }
[b12e20d]1498 // De fullscreen schrijf-"pagina": openen pusht een history-state zodat de browser-
1499 // back-knop (en de Klaar-knop) 'm sluit en je terug bent in het formulier — voelt
1500 // als een aparte pagina, maar álle formuliervelden blijven intact (zelfde DOM).
1501 function openFs() {
1502 if (isFs()) return;
1503 try { history.pushState({ peFs: true }, ''); } catch (_) {}
1504 applyFs(true);
1505 }
1506 function closeFs() {
1507 if (!isFs()) return;
1508 if (history.state && history.state.peFs) history.back(); // → popstate sluit af
1509 else applyFs(false);
1510 }
1511 function toggleFullscreen() { if (isFs()) closeFs(); else openFs(); }
1512 window.addEventListener('popstate', function () { if (isFs()) applyFs(false); });
[d2078f4]1513 if (fsBtn) fsBtn.addEventListener('click', toggleFullscreen);
[b12e20d]1514 var fsDoneBtn = document.getElementById('pe-fs-done');
1515 if (fsDoneBtn) fsDoneBtn.addEventListener('click', closeFs);
[d2078f4]1516 document.addEventListener('keydown', (e) => {
[b12e20d]1517 if (e.key === 'Escape' && isFs()) { e.preventDefault(); closeFs(); }
[d2078f4]1518 });
1519
[61bb585]1520 // Op mobiel/tablet (touch): het content-veld is INLINE NIET bewerkbaar — het is
1521 // dan geen tekstveld. Eén tik → fullscreen, waar het wél bewerkbaar wordt
1522 // (toggleFullscreen zet contenteditable aan/uit). Zo kun je nooit inline typen.
[c01f471]1523 if (isTouch) {
[61bb585]1524 editor.setAttribute('contenteditable', 'false');
1525 editor.classList.add('pe-tap-to-edit');
[4885eab]1526 editor.setAttribute('data-placeholder', '<%= t('pedit.tap_to_write') %>');
[61bb585]1527 editor.addEventListener('click', function () {
[b12e20d]1528 if (!isFs()) openFs();
[61bb585]1529 });
[c01f471]1530 }
1531
[7bc636b]1532 // Reflect bold/italic/list state on the toolbar buttons
1533 function updateToolbarState() {
1534 if (!toolbar) return;
1535 const cmds = ['bold', 'italic', 'underline', 'insertUnorderedList', 'insertOrderedList'];
1536 for (const cmd of cmds) {
1537 const btn = toolbar.querySelector('button[data-cmd="' + cmd + '"]');
1538 if (!btn) continue;
1539 try { btn.classList.toggle('is-active', document.queryCommandState(cmd)); } catch(_) {}
1540 }
[91d948c]1541 // Quote-knop: actief als de caret in een <blockquote> staat (toggle-feedback).
1542 const bqBtn = toolbar.querySelector('button[data-cmd="formatBlock"][data-arg="blockquote"]');
1543 if (bqBtn) bqBtn.classList.toggle('is-active', !!blockquoteAncestor());
[7bc636b]1544 }
1545 document.addEventListener('selectionchange', () => {
1546 if (document.activeElement === editor) updateToolbarState();
1547 });
1548
1549 // Keyboard shortcuts: Ctrl/Cmd + B/I/U/K
1550 editor.addEventListener('keydown', (e) => {
1551 const mod = e.ctrlKey || e.metaKey;
1552 if (!mod) return;
1553 const k = e.key.toLowerCase();
1554 if (k === 'b') { e.preventDefault(); execCmd('bold'); }
1555 else if (k === 'i') { e.preventDefault(); execCmd('italic'); }
1556 else if (k === 'u') { e.preventDefault(); execCmd('underline'); }
1557 else if (k === 'k') { e.preventDefault(); linkPrompt(); }
1558 });
1559
1560 // Paste: keep it simple — strip formatting unless user wants it. Default
1561 // execCommand 'paste' includes Word/Google-Docs garbage. We accept inline
1562 // styles from clipboard only when shift is held — otherwise plain text.
1563 editor.addEventListener('paste', (e) => {
1564 if (e.shiftKey) return; // user wants formatted paste
1565 const text = (e.clipboardData || window.clipboardData).getData('text/plain');
1566 if (text == null) return;
1567 e.preventDefault();
1568 document.execCommand('insertText', false, text);
1569 });
1570
1571 // ── Image upload (button + drag-drop into the editor)
1572 async function uploadAndInsertImage(file) {
[48ebfa7]1573 const edited = await openImageEditor(file);
1574 if (!edited) return; // geannuleerd
[7bc636b]1575 contentStatus.classList.remove('is-error');
[4885eab]1576 contentStatus.textContent = '<%= t('pedit.js_uploading') %>';
[7bc636b]1577 try {
[48ebfa7]1578 const j = await uploadImage(edited);
[7bc636b]1579 const img = '<img src="' + j.url + '" alt="">';
[a7e8e19]1580 editor.focus({ preventScroll: true });
[7bc636b]1581 document.execCommand('insertHTML', false, img);
[4885eab]1582 contentStatus.textContent = '<%= t('pedit.js_inserted') %> ✓';
[7bc636b]1583 setTimeout(() => { contentStatus.textContent = ''; }, 2000);
1584 updateCharCount();
1585 } catch (e) {
1586 contentStatus.classList.add('is-error');
[4885eab]1587 contentStatus.textContent = '<%= t('pedit.js_failed') %>: ' + e.message;
[7bc636b]1588 }
1589 }
1590
1591 if (contentBtn && contentField) {
1592 contentBtn.addEventListener('click', () => contentField.click());
1593 contentField.addEventListener('change', () => {
1594 if (contentField.files[0]) uploadAndInsertImage(contentField.files[0]);
1595 contentField.value = '';
1596 });
1597
1598 editor.addEventListener('dragover', (e) => {
1599 if (e.dataTransfer && e.dataTransfer.types.includes('Files')) {
1600 e.preventDefault();
1601 editor.classList.add('is-dragover');
1602 }
1603 });
1604 editor.addEventListener('dragleave', () => editor.classList.remove('is-dragover'));
1605 editor.addEventListener('drop', async (e) => {
1606 editor.classList.remove('is-dragover');
1607 const files = e.dataTransfer && e.dataTransfer.files;
1608 if (!files || !files.length) return;
1609 e.preventDefault();
1610 for (const f of files) {
1611 if (f.type.startsWith('image/')) await uploadAndInsertImage(f);
1612 }
1613 });
1614 }
1615
1616 // ── Insert chip helpers (track / playlist)
1617 function insertChip(kind, value) {
[a7e8e19]1618 editor.focus({ preventScroll: true });
[7bc636b]1619 const chip = makeChip(kind, value);
1620 // Insert at caret using the Selection API (execCommand insertNode)
1621 const sel = window.getSelection();
1622 if (sel && sel.rangeCount > 0) {
1623 const range = sel.getRangeAt(0);
1624 range.deleteContents();
1625 range.insertNode(chip);
1626 // Insert a trailing space so the user can keep typing after the chip
1627 const space = document.createTextNode('\u00A0');
1628 chip.after(space);
1629 range.setStartAfter(space);
1630 range.collapse(true);
1631 sel.removeAllRanges();
1632 sel.addRange(range);
1633 } else {
1634 editor.appendChild(chip);
1635 editor.appendChild(document.createTextNode('\u00A0'));
1636 }
1637 updateCharCount();
1638 }
1639
[1907a18]1640 // ── Embed insert: plak een platform-URL -> [[embed:url]]-chip die server-side
1641 // een iframe wordt (YouTube/Spotify/SoundCloud/Vimeo/Apple Music/Bandcamp).
1642 const embedBtn = document.getElementById('insert-embed-btn');
1643 if (embedBtn) {
1644 embedBtn.addEventListener('click', () => {
[4885eab]1645 const raw = window.prompt('<%= t('pedit.js_embed_prompt') %>');
[1907a18]1646 if (!raw) return;
1647 const url = raw.trim();
[4885eab]1648 if (!/^https?:\/\//i.test(url)) { alert('<%= t('pedit.js_embed_invalid') %>'); return; }
[fef781e]1649 insertChip('embed', url);
[1907a18]1650 });
1651 }
1652
[7bc636b]1653 // ── Track insert: opens the track-picker modal (P59)
1654 const trackBtn = document.getElementById('insert-track-btn');
1655 const trackPicker = document.getElementById('track-picker');
1656 if (trackBtn && trackPicker) {
1657 const tpList = document.getElementById('tp-list');
1658 const tpEmpty = document.getElementById('tp-empty');
1659 const tpSearch = document.getElementById('tp-search');
1660 let tpCache = null; // cached tracks list (fetched once per page load)
1661 let tpLastFocus = null; // element to restore focus to on close
1662
1663 const SVG_NOTE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 17V5l12-2v12"/><circle cx="6" cy="17" r="3"/><circle cx="18" cy="15" r="3"/></svg>';
1664
1665 function fmtDur(sec) {
1666 sec = Math.max(0, Math.floor(sec || 0));
1667 const m = Math.floor(sec / 60), s = sec % 60;
1668 return m + ':' + String(s).padStart(2, '0');
1669 }
1670 function escAttr(s) {
1671 return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({
1672 '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'
1673 }[c]));
1674 }
1675
1676 function renderList(filter) {
1677 if (!Array.isArray(tpCache)) return;
1678 const q = (filter || '').trim().toLowerCase();
1679 const filtered = q
1680 ? tpCache.filter(t =>
1681 (t.title || '').toLowerCase().includes(q) ||
1682 (t.artist || '').toLowerCase().includes(q))
1683 : tpCache;
1684
1685 if (!filtered.length) {
1686 tpList.innerHTML = '';
[4885eab]1687 tpEmpty.textContent = q ? '<%= t('pedit.js_no_tracks_found') %> ' + q : '<%= t('pedit.js_no_tracks_yet') %>';
[7bc636b]1688 tpList.appendChild(tpEmpty);
1689 return;
1690 }
1691
1692 tpList.innerHTML = filtered.map(t => {
1693 const cov = t.cover
1694 ? '<span class="tp-cover" style="background-image:url(\'' + escAttr(t.cover) + '\')"></span>'
1695 : '<span class="tp-cover tp-cover-empty">' + SVG_NOTE + '</span>';
1696 const dis = t.playable ? '' : ' aria-disabled="true"';
1697 const sub = t.artist ? '<span class="tp-row-artist">' + escAttr(t.artist) + '</span>' : '';
1698 return (
1699 '<button type="button" class="tp-row" role="option" data-track-id="' + escAttr(t.id) + '"' + dis + '>' +
1700 cov +
1701 '<span class="tp-meta">' +
1702 '<span class="tp-row-title">' + escAttr(t.title) + '</span>' +
1703 sub +
1704 '</span>' +
1705 '<span class="tp-duration">' + fmtDur(t.duration) + '</span>' +
1706 '</button>'
1707 );
1708 }).join('');
1709 }
1710
1711 async function loadTracks() {
1712 if (Array.isArray(tpCache)) return tpCache;
[4885eab]1713 tpEmpty.textContent = '<%= t('pedit.js_tracks_loading') %>';
[7bc636b]1714 try {
1715 const r = await fetch('/admin/playlists/api/tracks', { credentials: 'same-origin' });
1716 const j = await r.json();
1717 tpCache = (j && j.ok && Array.isArray(j.tracks)) ? j.tracks : [];
1718 } catch (e) {
1719 tpCache = [];
[4885eab]1720 tpEmpty.textContent = '<%= t('pedit.js_tracks_load_fail') %>: ' + e.message;
[7bc636b]1721 }
1722 return tpCache;
1723 }
1724
1725 function openPicker() {
1726 tpLastFocus = document.activeElement;
1727 trackPicker.hidden = false;
1728 trackPicker.setAttribute('aria-hidden', 'false');
1729 document.body.classList.add('tp-locked');
1730 tpSearch.value = '';
1731 renderList('');
1732 // Defer focus so the open animation doesn't get jumped
1733 setTimeout(() => tpSearch.focus(), 30);
1734 }
1735 function closePicker() {
1736 trackPicker.hidden = true;
1737 trackPicker.setAttribute('aria-hidden', 'true');
1738 document.body.classList.remove('tp-locked');
1739 if (tpLastFocus && typeof tpLastFocus.focus === 'function') {
1740 try { tpLastFocus.focus(); } catch(_) {}
1741 }
1742 }
1743
1744 trackBtn.addEventListener('click', async () => {
1745 openPicker();
1746 await loadTracks();
1747 renderList(tpSearch.value);
1748 });
1749
1750 // Close: backdrop click, [data-tp-close], or Escape
1751 trackPicker.addEventListener('click', (e) => {
1752 if (e.target.closest('[data-tp-close]')) {
1753 closePicker();
1754 return;
1755 }
1756 const row = e.target.closest('.tp-row[data-track-id]');
1757 if (row) {
1758 if (row.getAttribute('aria-disabled') === 'true') return;
1759 const id = row.dataset.trackId;
1760 if (id) {
1761 insertChip('track', id);
1762 closePicker();
1763 }
1764 }
1765 });
1766 document.addEventListener('keydown', (e) => {
1767 if (!trackPicker.hidden && e.key === 'Escape') {
1768 e.preventDefault();
1769 closePicker();
1770 }
1771 });
1772
1773 // Live filter
1774 tpSearch.addEventListener('input', () => renderList(tpSearch.value));
1775 }
1776
1777 // ── Playlist insert (open existing or create new via modal)
1778 const playlistBtn = document.getElementById('insert-playlist-btn');
1779 if (playlistBtn) {
1780 playlistBtn.addEventListener('click', async () => {
1781 if (typeof window.openPlaylistEditor !== 'function') {
[4885eab]1782 alert('<%= t('pedit.js_playlist_editor_missing') %>');
[7bc636b]1783 return;
1784 }
1785 try {
1786 const r = await fetch('/admin/playlists/api/list', { credentials: 'same-origin' });
1787 const j = await r.json();
1788 if (j.ok && Array.isArray(j.playlists) && j.playlists.length > 0) {
1789 const choice = prompt(
[4885eab]1790 '<%= t('pedit.js_playlist_existing') %>\n\n' +
[7bc636b]1791 j.playlists.map((p, i) => `${i + 1}. ${p.title} (${p.track_count} tracks)`).join('\n') +
[4885eab]1792 '\n\n<%= t('pedit.js_playlist_choose') %>'
[7bc636b]1793 );
1794 if (choice && /^\d+$/.test(choice.trim())) {
1795 const idx = parseInt(choice.trim(), 10) - 1;
1796 if (idx >= 0 && idx < j.playlists.length) {
1797 insertChip('playlist', j.playlists[idx].id);
1798 return;
1799 }
1800 }
1801 if (choice === null) return;
1802 }
1803 } catch (_) { /* fall through to create */ }
1804
1805 window.openPlaylistEditor({
1806 mode: 'create',
1807 onSaved: ({ id }) => insertChip('playlist', id),
1808 });
1809 });
1810 }
1811
1812 // ── Submit: serialize editor contents into the hidden field
1813 if (form && hiddenField) {
1814 form.addEventListener('submit', () => {
1815 const clone = editor.cloneNode(true);
1816 serializeChips(clone);
1817 hiddenField.value = clone.innerHTML;
1818 });
1819 }
1820})();
1821</script>
1822
1823<%# ── Track picker modal (P59). Mobile-first: full-screen sheet on small
1824 viewports, centered modal on ≥640px. Populated lazily on first open. %>
1825<% if (typeof user !== 'undefined' && user) { %>
1826<div id="track-picker" class="tp-modal" hidden aria-hidden="true">
1827 <div class="tp-backdrop" data-tp-close></div>
1828 <div class="tp-sheet" role="dialog" aria-modal="true" aria-labelledby="tp-title">
1829 <header class="tp-header">
[4885eab]1830 <h2 id="tp-title" class="tp-h2"><%= t('pedit.tp_title') %></h2>
1831 <button type="button" class="tp-close" data-tp-close aria-label="<%= t('pedit.tp_close') %>">
[7bc636b]1832 <svg 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>
1833 </button>
1834 </header>
1835 <div class="tp-search-row">
1836 <span class="tp-search-icon" aria-hidden="true">
1837 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
1838 </span>
[4885eab]1839 <input type="search" class="tp-search" id="tp-search" placeholder="<%= t('pedit.tp_search_placeholder') %>" autocomplete="off" inputmode="search">
[7bc636b]1840 </div>
[4885eab]1841 <div class="tp-list" id="tp-list" role="listbox" aria-label="<%= t('pedit.tp_list_aria') %>">
1842 <div class="tp-empty" id="tp-empty"><%= t('pedit.js_tracks_loading') %></div>
[7bc636b]1843 </div>
1844 </div>
1845</div>
1846<% } %>
1847
1848<%# Playlist editor modal — included so its global window.openPlaylistEditor
1849 is available when the toolbar button fires. Only renders if user can post. %>
1850<% if (typeof user !== 'undefined' && user) { %>
1851 <%- include('../partials/playlist-editor', { csrfToken: (typeof csrfToken !== 'undefined' ? csrfToken : '') }) %>
1852<% } %>
[edc462d]1853
1854<script>
1855(function () {
1856 // Vastpinnen: checkbox toggelt het verborgen rang-veld (0 = niet gepind),
1857 // ▲▼ verschuift de plek, met een leesbare beschrijving i.p.v. een ruw getal.
1858 var toggle = document.getElementById('pin-toggle');
1859 var rank = document.getElementById('pin-rank');
1860 var pos = document.getElementById('pin-pos');
1861 var label = document.getElementById('pin-label');
1862 var up = document.getElementById('pin-up'); // hoger = lager getal (richting 1/bovenaan)
1863 var down = document.getElementById('pin-down');
1864 if (!toggle || !rank || !pos) return;
1865
1866 function descr(n) {
1867 n = Number(n) || 0;
[4885eab]1868 if (n <= 1) return '<%= t('pedit.pin_top') %>';
1869 return n + '<%= t('pedit.pin_nth_suffix') %>';
[edc462d]1870 }
1871 function render() {
1872 var on = toggle.checked;
1873 pos.hidden = !on;
1874 if (on && Number(rank.value) < 1) rank.value = 1;
1875 if (!on) rank.value = 0;
1876 if (label) label.textContent = on ? descr(rank.value) : '';
1877 if (up) up.disabled = Number(rank.value) <= 1;
1878 }
1879 toggle.addEventListener('change', render);
1880 if (up) up.addEventListener('click', function () { rank.value = Math.max(1, (Number(rank.value) || 1) - 1); render(); });
1881 if (down) down.addEventListener('click', function () { rank.value = (Number(rank.value) || 0) + 1; render(); });
1882 render();
1883})();
[d3e2987]1884
1885(function () {
[5f7dba2]1886 // De Opslaan/Annuleren-balk (position: sticky; bottom:0) net boven twee mogelijke
1887 // obstakels houden door een dynamische bottom-offset te zetten = het grootste van:
1888 // 1) de hoogte van het toetsenbord-deel dat de layout-viewport NIET dekt
1889 // (op iOS verschuift de visual viewport; op Android verkleint de layout-
1890 // viewport door interactive-widget=resizes-content → offset ≈ 0);
1891 // 2) de hoogte van de spelende audiospeler (fixed, z-index 1000).
1892 // We blijven bij sticky (geen fixed/top-gegoochel → geen balk midden in beeld).
[d3e2987]1893 var bar = document.querySelector('.pe-actions');
1894 if (!bar) return;
[408afc1]1895 var vv = window.visualViewport;
[5f7dba2]1896 function position() {
[d3e2987]1897 var ap = document.querySelector('.audio-player');
1898 var playing = document.body.classList.contains('has-audio-player') &&
1899 ap && getComputedStyle(ap).display !== 'none';
[5f7dba2]1900 var audioOffset = playing ? Math.round(ap.getBoundingClientRect().height) : 0;
1901 var kbCovered = vv ? Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop)) : 0;
1902 var offset = Math.max(audioOffset, kbCovered);
1903 bar.style.bottom = offset ? offset + 'px' : '';
[408afc1]1904 }
1905 position();
1906 window.addEventListener('resize', position);
1907 if (vv) { vv.addEventListener('resize', position); vv.addEventListener('scroll', position); }
[5f7dba2]1908 // has-audio-player wisselt via een body-class → daarop reageren.
[408afc1]1909 try { new MutationObserver(position).observe(document.body, { attributes: true, attributeFilter: ['class'] }); } catch (_) {}
[d3e2987]1910})();
[edc462d]1911</script>
Note: See TracBrowser for help on using the repository browser.