source: Klonkt/src/views/pages/post-edit.ejs@ 2149f5a

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

chore(editor): label "Excerpt" → "Samenvatting & Cirkel Preview"

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

  • Property mode set to 100644
File size: 72.3 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">
17 <h1><%= isNew ? 'Nieuwe post' : 'Post bewerken' %></h1>
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">
24 <span>Titel</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">
29 <span>Slug (URL)</span>
30 <input type="text" name="slug" value="<%= post.slug %>" placeholder="auto van titel als leeg">
31 </label>
32 <label class="pe-field">
33 <span>Tags <small>(komma-gescheiden)</small></span>
34 <input type="text" name="tags" value="<%= Array.isArray(post.tags) ? post.tags.join(', ') : '' %>">
35 </label>
36 </div>
37 <label class="pe-field">
[bc83cc8]38 <span>Samenvatting &amp; Cirkel Preview</span>
[7bc636b]39 <textarea name="excerpt" rows="2"><%= post.excerpt %></textarea>
[7eb35ae]40 <small class="pe-hint" style="opacity:.7">Wordt ook gebruikt als samenvatting in <strong>Cirkels</strong> (andere sites die je post tonen). Leeg laten = begin van de post.</small>
[7bc636b]41 </label>
42 </section>
43
44 <%# ── COVER ────────────────────────────────────────────────── %>
45 <section class="pe-card">
46 <div class="pe-section-title">Cover</div>
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">
54 <span>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"
58 placeholder="/media/… of https://… (of upload met de knop)">
[7bc636b]59 </label>
60 <div class="pe-cover-upload">
61 <button type="button" class="pe-btn pe-btn-secondary" id="cover-upload-trigger">
62 📷 Upload nieuwe cover
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">
74 Content
[254872f]75 <small class="pe-content-hint">Sleep een afbeelding om in te voegen · selecteer tekst om op te maken</small>
[7bc636b]76 </div>
77 <div class="pe-editor-frame">
78 <div class="pe-toolbar" id="pe-toolbar" role="toolbar" aria-label="Format">
[b12e20d]79 <button type="button" id="pe-fs-done" class="pe-fs-done" title="Klaar met bewerken">✓ Klaar</button>
[7bc636b]80 <button type="button" data-cmd="bold" title="Vet (Ctrl+B)" aria-label="Vet">
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>
83 <button type="button" data-cmd="italic" title="Cursief (Ctrl+I)" aria-label="Cursief">
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>
86 <button type="button" data-cmd="underline" title="Onderstreept" aria-label="Onderstreept">
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>
90 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="h2" title="Kop">H2</button>
91 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="h3" title="Subkop">H3</button>
92 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="p" title="Paragraaf">¶</button>
93 <span class="pe-toolbar-sep" aria-hidden="true"></span>
94 <button type="button" data-cmd="insertUnorderedList" title="Lijst" aria-label="Lijst">
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>
97 <button type="button" data-cmd="insertOrderedList" title="Genummerde lijst" aria-label="Genummerde lijst">
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>
100 <button type="button" data-cmd="formatBlock" data-arg="blockquote" title="Quote" aria-label="Quote">
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>
103 <button type="button" data-cmd="link-prompt" title="Link (Ctrl+K)" aria-label="Link">
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>
106 <button type="button" data-cmd="code-wrap" title="Code (inline)" aria-label="Code">
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>
110 <button type="button" id="insert-image-btn" title="Afbeelding invoegen" aria-label="Afbeelding">
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>
113 <button type="button" id="insert-track-btn" title="Track invoegen" aria-label="Track">
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>
116 <button type="button" id="insert-playlist-btn" title="Playlist invoegen" aria-label="Playlist">
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>
[1907a18]119 <button type="button" id="insert-embed-btn" title="Embed (YouTube, Spotify, SoundCloud, Vimeo…)" aria-label="Media embedden">
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>
123 <button type="button" data-cmd="removeFormat" title="Wis opmaak" aria-label="Wis opmaak">
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>
[d2078f4]126 <button type="button" id="pe-fullscreen-btn" title="Volledig scherm" aria-label="Volledig scherm" aria-pressed="false">
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"
137 aria-label="Content"
138 data-placeholder="Begin met schrijven…"></div>
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. %>
142 <div class="pe-edit-hint" aria-hidden="true">✎ Tik om te bewerken</div>
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>
155 <span class="pe-char-count"><span id="char-count">0</span> tekens</span>
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">
164 <div class="pe-section-title">Publicatie</div>
165 <div class="pe-row pe-row-2">
166 <label class="pe-field">
167 <span>Status</span>
[edc462d]168 <% var _st = isNew ? 'published' : (post.status || 'draft'); %>
[7bc636b]169 <select name="status">
[edc462d]170 <option value="published" <%= _st === 'published' ? 'selected' : '' %>>Gepubliceerd</option>
171 <option value="draft" <%= _st === 'draft' ? 'selected' : '' %>>Concept</option>
172 <option value="archived" <%= _st === 'archived' ? 'selected' : '' %>>Gearchiveerd</option>
[7bc636b]173 </select>
174 </label>
175 <label class="pe-field">
176 <span>Type</span>
177 <select name="type">
178 <% var ptype = post.type || 'post'; %>
179 <option value="post" <%= ptype === 'post' ? 'selected' : '' %>>Post</option>
180 <option value="foto" <%= ptype === 'foto' ? 'selected' : '' %>>Foto</option>
181 <option value="video" <%= ptype === 'video' ? 'selected' : '' %>>Video</option>
182 <option value="audio" <%= ptype === 'audio' ? 'selected' : '' %>>Audio</option>
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' : '' %>>
190 <span>📌 Vastpinnen bovenaan</span>
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">
195 <button type="button" class="pe-pin-btn" id="pin-up" aria-label="Hoger zetten">▲</button>
196 <button type="button" class="pe-pin-btn" id="pin-down" aria-label="Lager zetten">▼</button>
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' : '' %>>
203 <span>🚫 noindex (verberg voor zoekmachines)</span>
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' : '' %>>
208 <span>🔒 Alleen voor ingelogde fans</span>
209 </label>
210 <div style="margin-top:8px">
211 <label style="display:block;font-size:12.5px;opacity:.8;margin-bottom:4px">📅 Publiceren op (laat leeg = direct)</label>
212 <input type="datetime-local" name="publish_at" value="<%= post.publish_at ? String(post.publish_at).replace(' ','T').slice(0,16) : '' %>" style="padding:8px 10px;border-radius:8px;border:1px solid var(--rule,rgba(128,128,128,.4));background:transparent;color:inherit">
213 <% if (post.status === 'scheduled' && post.publish_at) { %><div style="font-size:12px;opacity:.7;margin-top:4px">⏳ Ingepland voor <%= post.publish_at %></div><% } %>
214 </div>
215 <% } %>
[7bc636b]216 </div>
217 </section>
218
219 <%# ── ACTIONS (sticky at bottom) ──────────────────────────── %>
220 <div class="pe-actions">
[851239c]221 <a href="<%= _base %><%= isNew ? '/' : '/' + post.slug %>" class="pe-btn">Annuleren</a>
[7bc636b]222 <div class="pe-actions-spacer"></div>
223 <% if (!isNew && post.status !== 'published') { %>
224 <button type="submit" name="action" value="publish" class="pe-btn pe-btn-success">📤 Publish</button>
225 <% } %>
226 <button type="submit" class="pe-btn pe-btn-primary">💾 Opslaan</button>
227 </div>
228 </form>
229</div>
230
231<style>
232/* ─── Page wrapper ──────────────────────────────────────────────── */
233.post-edit-page {
234 max-width: 880px;
235 margin: 1.5rem auto 6rem; /* extra bottom for sticky-actions clearance */
236 padding: 0 1rem;
237}
238.post-edit-page h1 {
239 font-family: var(--font-display, serif);
240 margin: 0 0 1.25rem;
241 font-size: 1.75rem;
242}
243
244.post-edit-form {
245 display: flex; flex-direction: column;
246 gap: 1rem;
247}
248
249/* ─── Card sections ─────────────────────────────────────────────── */
250.pe-card {
251 background: var(--paper);
252 border: 1px solid var(--rule);
253 border-radius: 12px;
254 padding: 1.25rem;
255 display: flex; flex-direction: column;
256 gap: 0.85rem;
257}
258.pe-card-content { padding-bottom: 0; overflow: hidden; } /* editor flush to bottom */
259.pe-section-title {
260 font-size: 0.8rem;
261 font-weight: 600;
262 text-transform: uppercase;
263 letter-spacing: 0.05em;
264 color: var(--ink-soft);
265 display: flex; align-items: baseline; gap: 0.5rem;
266 flex-wrap: wrap;
267}
268.pe-section-title small {
269 font-size: 0.75rem; font-weight: 400;
270 letter-spacing: 0; text-transform: none;
271 color: var(--ink-muted, var(--ink-soft));
272}
273
274/* ─── Field primitives ──────────────────────────────────────────── */
275.pe-field {
276 display: flex; flex-direction: column;
277 gap: 0.35rem;
278 min-width: 0; /* allow grid items to shrink */
279}
280.pe-field > span {
281 font-size: 0.8rem;
282 font-weight: 600;
283 color: var(--ink-soft);
284 display: flex; align-items: baseline; gap: 0.4rem;
285}
286.pe-field > span small {
287 font-weight: 400; color: var(--ink-muted);
288}
289.pe-field input,
290.pe-field textarea,
291.pe-field select {
292 width: 100%;
293 box-sizing: border-box;
294 display: block;
295 padding: 0.6rem 0.75rem;
296 border: 1px solid var(--rule);
297 border-radius: 6px;
298 background: var(--paper-2);
299 color: var(--ink);
300 font-family: var(--font-ui, system-ui), sans-serif;
301 font-size: 0.95rem;
302 -webkit-appearance: none;
303 appearance: none;
304 transition: border-color 120ms;
305}
306.pe-field input:focus,
307.pe-field textarea:focus,
308.pe-field select:focus {
309 outline: 2px solid var(--accent);
310 outline-offset: -1px;
311 border-color: var(--accent);
312}
313.pe-field textarea {
314 font-family: var(--font-mono, monospace);
315 resize: vertical;
316}
317.pe-field select {
318 /* Restore the dropdown arrow we removed with appearance:none */
319 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>");
320 background-repeat: no-repeat;
321 background-position: right 0.75rem center;
322 padding-right: 2rem;
323}
324
325.pe-row {
326 display: grid;
327 gap: 0.75rem;
328}
329.pe-row-2 { grid-template-columns: 1fr 1fr; }
330@media (max-width: 600px) {
331 .pe-row-2 { grid-template-columns: 1fr; }
332}
333
334/* ─── Cover field ───────────────────────────────────────────────── */
335.pe-cover-row {
336 display: grid;
337 grid-template-columns: 120px 1fr;
338 gap: 1rem;
339 align-items: start;
340}
341.pe-cover-thumb {
342 width: 120px; height: 120px;
343 border-radius: 10px;
344 overflow: hidden;
345 background: var(--paper-2);
346 border: 1px solid var(--rule);
347 display: flex; align-items: center; justify-content: center;
348 position: relative;
349}
350.pe-cover-thumb[data-empty] {
351 border-style: dashed;
352}
353.pe-cover-thumb img {
354 width: 100%; height: 100%;
355 object-fit: cover; display: block;
356}
357/* Honor HTML hidden — our display:block above otherwise renders an empty
358 broken-image icon when no cover is set. */
359.pe-cover-thumb img[hidden] { display: none; }
360.pe-cover-empty {
361 font-size: 2rem;
362 color: var(--ink-muted, var(--ink-soft));
363 opacity: 0.5;
364}
365.pe-cover-actions {
366 display: flex; flex-direction: column;
367 gap: 0.6rem;
368 min-width: 0;
369}
370.pe-cover-upload {
371 display: flex; align-items: center; gap: 0.6rem;
372 flex-wrap: wrap;
373}
374@media (max-width: 600px) {
375 .pe-cover-row { grid-template-columns: 88px 1fr; }
376 .pe-cover-thumb { width: 88px; height: 88px; }
377}
378
379/* ─── Editor frame (WYSIWYG: top toolbar, contenteditable body, status bar) ─── */
380.pe-editor-frame {
381 margin: 0 -1.25rem -1.25rem; /* break out of card padding for flush edges */
382 border-top: 1px solid var(--rule);
383 background: var(--paper);
384 display: flex; flex-direction: column;
385}
386
387/* Top toolbar — sticks to the top of the viewport while editing */
388.pe-toolbar {
389 display: flex; align-items: center; gap: .15rem;
390 flex-wrap: wrap;
391 padding: .4rem .75rem;
392 background: color-mix(in srgb, var(--paper) 92%, transparent);
393 backdrop-filter: blur(10px);
394 -webkit-backdrop-filter: blur(10px);
395 border-bottom: 1px solid var(--rule);
396 position: sticky;
397 top: 0;
398 z-index: 10;
399}
400.pe-toolbar button {
401 display: inline-flex; align-items: center; justify-content: center;
402 width: 32px; height: 32px;
403 padding: 0;
[a7e8e19]404 touch-action: manipulation; /* snappy taps op mobiel, geen dubbeltik-zoom */
405 -webkit-user-select: none; user-select: none;
[7bc636b]406 background: transparent;
407 border: 1px solid transparent;
408 border-radius: 6px;
409 color: var(--ink);
410 cursor: pointer;
411 font-family: var(--font-ui, system-ui), sans-serif;
412 font-weight: 600; font-size: .85rem;
413 transition: background var(--transition), color var(--transition), border-color var(--transition);
414 -webkit-tap-highlight-color: transparent;
415}
[16ce669]416/* Hover alleen op echte hover-apparaten — op touch blijft :hover anders "plakken"
417 na een tik, waardoor de actief/inactief-staat onleesbaar wordt. */
418@media (hover: hover) {
419 .pe-toolbar button:hover {
420 background: var(--paper-2);
421 color: var(--accent);
422 }
[7bc636b]423}
424.pe-toolbar button:active { transform: scale(.94); }
[16ce669]425/* Actieve opmaak = onmiskenbaar gevuld met de accentkleur. Zo is op mobiel
426 meteen duidelijk dat bv. vet AAN staat (tik nogmaals = uit). */
[7bc636b]427.pe-toolbar button.is-active {
[16ce669]428 background: var(--accent);
429 color: #fff;
430 border-color: var(--accent);
[7bc636b]431}
[16ce669]432.pe-toolbar button.is-active svg { color: #fff; }
[7bc636b]433.pe-toolbar button svg { width: 16px; height: 16px; }
434.pe-toolbar button.pe-tb-text { font-family: var(--font-display, serif); font-weight: 700; }
435.pe-toolbar-sep {
436 width: 1px; height: 18px;
437 background: var(--rule);
438 margin: 0 .35rem;
439 flex-shrink: 0;
440}
441.pe-toolbar-spacer { flex: 1; }
442
[d2078f4]443/* ─── Volledig-scherm schrijfmodus ─── */
444.fs-icon-compress { display: none; }
445.pe-editor-frame.pe-fs .fs-icon-expand { display: none; }
446.pe-editor-frame.pe-fs .fs-icon-compress { display: inline; }
447.pe-editor-frame.pe-fs {
448 position: fixed; inset: 0; z-index: 1000;
449 margin: 0; border-top: 0;
450 height: 100dvh;
451 background: var(--paper);
[de21a3b]452 overflow: hidden; /* alléén het tekstveld scrollt, niet het frame zelf */
[d2078f4]453}
[859bace0]454/* In fullscreen vult het schrijfveld de resterende ruimte en scrollt het zelf
455 (max-height: none overschrijft de mobiele box-begrenzing hieronder). */
[d2078f4]456.pe-editor-frame.pe-fs .pe-editor {
[859bace0]457 flex: 1 1 auto; min-height: 0; height: auto; max-height: none;
[d2078f4]458}
[c1a4147]459/* NB: bewust GEEN overflow:hidden op html/body in fullscreen — dat kon blijven
460 hangen (bv. fullscreen verlaten via navigatie) en blokkeerde dan het scrollen van
461 de hele pagina. Het fullscreen-frame (position:fixed, inset:0) dekt de pagina al
462 af, en op touch zijn de scrollbalken verborgen → geen dubbele balk nodig. */
[d2078f4]463
[b12e20d]464/* "Klaar"-knop: alleen in fullscreen zichtbaar (links in de toolbar), duidelijke
465 accent-pill i.p.v. een vierkant icoontje. */
[b988c96]466/* Verberg-regel specifieker dan ".pe-toolbar button" (anders wint die en zie je
467 de Klaar-knop ook inline als kleine knop). Alleen in fullscreen tonen → groot. */
468.pe-toolbar button.pe-fs-done { display: none; }
[b12e20d]469.pe-editor-frame.pe-fs .pe-fs-done {
[43fea32]470 display: inline-flex; align-items: center; gap: .35rem;
471 width: auto !important; height: auto !important; min-height: 40px;
472 padding: .55rem 1.3rem !important; margin-right: .5rem;
[b12e20d]473 background: var(--accent); color: #fff;
[43fea32]474 font-weight: 700; font-size: 1.05rem; border-radius: 999px;
[b12e20d]475}
476.pe-editor-frame.pe-fs .pe-fs-done:hover { background: var(--accent); color: #fff; }
477
[7bc636b]478/* Editor body — looks like prose, behaves like a textarea */
479.pe-editor {
480 width: 100%;
481 box-sizing: border-box;
482 min-height: 420px;
483 padding: 1.25rem 1.5rem;
484 border: 0;
485 background: transparent;
486 color: var(--ink);
487 font-family: var(--font-body, system-ui), serif;
488 font-size: 1.0625rem;
489 line-height: 1.65;
490 outline: none;
491 overflow-y: auto;
492}
493.pe-editor:focus { outline: none; }
[f3f43df]494/* Inline (niet-fullscreen) groeit het schrijfveld gewoon mee met de inhoud — geen
495 interne scroll-box (scroll-binnen-scroll is verwarrend). Op mobiel/tablet gaat
496 typen sowieso fullscreen (zie JS), waar het veld de pagina vult en als enige
497 scrollt. */
498.pe-editor-frame:not(.pe-fs) .pe-editor { overflow: visible; }
[61bb585]499
500/* Touch: het inline content-veld is geen tekstveld maar een tap-vlak → fullscreen
[a623e7e]501 bewerken. Een "✎ Tik om te bewerken"-pill plakt sticky onderaan de container,
502 zodat de hint altijd in beeld is zonder midden in de tekst te staan. */
[61bb585]503.pe-editor.pe-tap-to-edit { cursor: pointer; }
[a623e7e]504.pe-edit-hint { display: none; }
[61bb585]505@media (pointer: coarse) {
[a623e7e]506 .pe-editor-frame:not(.pe-fs) .pe-edit-hint {
507 display: block;
508 position: sticky;
509 bottom: 4.5rem; /* boven de sticky Opslaan/Annuleren-balk */
510 width: max-content;
511 max-width: calc(100% - 2rem);
512 margin: .4rem auto;
[61bb585]513 background: var(--accent); color: #fff;
[a623e7e]514 font-size: .9rem; font-weight: 700; padding: .5rem 1.1rem; border-radius: 999px;
515 box-shadow: 0 4px 14px rgba(0,0,0,.35);
516 pointer-events: none; text-align: center; white-space: nowrap;
[61bb585]517 }
[254872f]518 /* Niet relevant op touch (slepen/selecteren hoort bij inline-bewerken op desktop). */
519 .pe-content-hint { display: none; }
[9163b15]520 /* Inline (niet-fullscreen) op touch: simpel houden — je bewerkt hier toch niet,
521 dus geen opmaak-toolbar en geen losse rand. Alleen de content-preview + de
522 "tik om te bewerken"-pill. De toolbar verschijnt pas in fullscreen. */
523 .pe-editor-frame:not(.pe-fs) .pe-toolbar { display: none; }
524 .pe-editor-frame:not(.pe-fs) { border-top: 0; }
525 .pe-editor-frame:not(.pe-fs) .pe-editor { min-height: 8rem; }
[61bb585]526}
[7bc636b]527.pe-editor.is-dragover {
528 outline: 2px dashed var(--accent);
529 outline-offset: -10px;
530}
531.pe-editor[data-placeholder]:empty::before,
532.pe-editor[data-placeholder]:has(br:only-child)::before {
533 content: attr(data-placeholder);
534 color: var(--ink-muted, #999);
535 pointer-events: none;
536 opacity: .55;
537}
538/* Inline prose styles inside the editor — match the public post styling so
539 what you see is roughly what you'll get. Margins are tighter than on the
540 live site since this is a confined writing space. */
541.pe-editor h1, .pe-editor h2, .pe-editor h3, .pe-editor h4 {
542 font-family: var(--font-display, serif);
543 line-height: 1.2;
544 margin: 1.1rem 0 .35rem;
545}
546.pe-editor h1 { font-size: 1.85rem; }
547.pe-editor h2 { font-size: 1.45rem; }
548.pe-editor h3 { font-size: 1.2rem; }
549.pe-editor p { margin: 0 0 .85em; }
550.pe-editor ul, .pe-editor ol { margin: 0 0 .85em 1.4em; padding: 0; }
551.pe-editor li { margin: .15em 0; }
552.pe-editor blockquote {
553 margin: 1em 0;
554 padding: .15em 0 .15em 1em;
555 border-left: 3px solid var(--accent);
556 color: var(--ink-soft, var(--ink));
557 font-style: italic;
558}
559.pe-editor code {
560 background: var(--paper-2);
561 border: 1px solid var(--rule);
562 border-radius: 4px;
563 padding: .1em .35em;
564 font-family: var(--font-mono, ui-monospace, monospace);
565 font-size: .92em;
566}
567.pe-editor a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
568.pe-editor img {
569 max-width: 100%; height: auto;
570 border-radius: 6px;
571 display: block;
572 margin: 1em auto;
573}
574
575/* Shortcode chips — visible inline placeholder in the editor for
576 [[track:UUID]] / [[album:Name]] / [[playlist:slug]]. They serialize back
577 to plain shortcode text on submit. */
578.sc-chip {
579 display: inline-flex; align-items: center; gap: .3rem;
580 padding: .15em .5em;
581 margin: 0 .15em;
582 background: color-mix(in srgb, var(--accent) 10%, var(--paper-2));
583 border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--rule));
584 border-radius: 999px;
585 color: var(--accent);
586 font-family: var(--font-ui, system-ui), sans-serif;
587 font-size: .85em;
588 font-weight: 600;
589 font-style: normal;
590 white-space: nowrap;
591 user-select: none;
592 cursor: default;
593 vertical-align: baseline;
594}
595.sc-chip-icon { display: inline-flex; opacity: .8; }
596.sc-chip-icon svg { width: 12px; height: 12px; }
597
598/* Status bar below the editor */
599.pe-editor-status {
600 display: flex; align-items: center; justify-content: space-between;
601 gap: .75rem;
602 padding: .45rem 1rem;
603 border-top: 1px solid var(--rule);
604 background: var(--paper-2);
605 color: var(--ink-muted, var(--ink-soft));
606 font-size: .78rem;
607}
608.pe-char-count { font-variant-numeric: tabular-nums; }
609
610/* ─── Track picker modal (P59) ─────────────────────────────────
611 Mobile-first: full-screen bottom-sheet on phones, centered card
612 on desktop. Lock body scroll while open via .tp-locked on body. */
613.tp-modal {
614 position: fixed; inset: 0;
615 z-index: 1000;
616 display: flex; align-items: stretch; justify-content: center;
617 /* Avoid the iOS home-indicator + the keyboard when search is focused */
618 padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
619}
620.tp-modal[hidden] { display: none; }
621.tp-backdrop {
622 position: absolute; inset: 0;
623 background: color-mix(in srgb, var(--ink) 55%, transparent);
624 backdrop-filter: blur(4px);
625 -webkit-backdrop-filter: blur(4px);
626 animation: tp-bd-in .18s ease-out;
627}
628@keyframes tp-bd-in { from { opacity: 0 } to { opacity: 1 } }
629
630/* Mobile: sheet docks to the bottom and fills viewport almost completely */
631.tp-sheet {
632 position: relative;
633 margin-top: auto;
634 width: 100%;
635 max-height: calc(100dvh - env(safe-area-inset-top) - 1rem);
636 background: var(--paper);
637 border-top: 1px solid var(--rule);
638 border-radius: 16px 16px 0 0;
639 box-shadow:
640 0 -2px 8px color-mix(in srgb, var(--ink) 8%, transparent),
641 0 -16px 48px color-mix(in srgb, var(--ink) 18%, transparent);
642 display: flex; flex-direction: column;
643 animation: tp-sheet-up .22s cubic-bezier(.2, .8, .25, 1);
644 overflow: hidden;
645}
646@keyframes tp-sheet-up {
647 from { transform: translateY(100%); opacity: .8; }
648 to { transform: translateY(0); opacity: 1; }
649}
650
651/* Header — title + close, with a small grab-handle bar on mobile */
652.tp-header {
653 display: flex; align-items: center; justify-content: space-between;
654 gap: .75rem;
655 padding: .85rem 1rem .65rem;
656 border-bottom: 1px solid var(--rule);
657 position: relative;
658}
659.tp-header::before {
660 /* Grab-handle: visible on mobile only */
661 content: '';
662 position: absolute;
663 top: .35rem; left: 50%;
664 transform: translateX(-50%);
665 width: 38px; height: 4px;
666 background: var(--rule-2, var(--rule));
667 border-radius: 2px;
668}
669.tp-h2 {
670 margin: .35rem 0 0;
671 font-family: var(--font-display, serif);
672 font-size: 1.15rem; font-weight: 600;
673 color: var(--ink);
674 line-height: 1.1;
675}
676.tp-close {
677 width: 32px; height: 32px; border-radius: 8px;
678 display: inline-flex; align-items: center; justify-content: center;
679 background: transparent; border: 1px solid transparent;
680 color: var(--ink-muted, var(--ink-soft));
681 cursor: pointer;
682 transition: background var(--transition), color var(--transition), border-color var(--transition);
683 -webkit-tap-highlight-color: transparent;
684 margin-top: .35rem;
685}
686.tp-close:hover, .tp-close:focus-visible {
687 background: var(--paper-2);
688 color: var(--ink);
689 outline: none;
690}
691.tp-close svg { width: 18px; height: 18px; }
692
693/* Search row — sticky just below header so list scrolls underneath */
694.tp-search-row {
695 position: relative;
696 padding: .65rem 1rem;
697 border-bottom: 1px solid var(--rule);
698 background: var(--paper);
699}
700.tp-search-icon {
701 position: absolute;
702 top: 50%; left: 1.65rem;
703 transform: translateY(-50%);
704 color: var(--ink-muted, var(--ink-soft));
705 pointer-events: none;
706 display: inline-flex;
707}
708.tp-search-icon svg { width: 16px; height: 16px; }
709.tp-search {
710 width: 100%; box-sizing: border-box;
711 padding: .65rem .85rem .65rem 2.4rem;
712 font-family: var(--font-ui, system-ui), sans-serif;
713 font-size: 1rem;
714 background: var(--paper-2);
715 color: var(--ink);
716 border: 1px solid var(--rule);
717 border-radius: 9px;
718 -webkit-appearance: none;
719 appearance: none;
720}
721.tp-search:focus {
722 outline: none;
723 border-color: var(--accent);
724 box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
725}
726
727/* List — vertically scrollable, takes remaining sheet height */
728.tp-list {
729 flex: 1 1 auto;
730 overflow-y: auto;
731 -webkit-overflow-scrolling: touch;
732 padding: .35rem .35rem 1rem;
733}
734.tp-empty {
735 padding: 1.5rem 1rem;
736 text-align: center;
737 color: var(--ink-muted, var(--ink-soft));
738 font-size: .9rem;
739}
740
741/* Track row — tap target ≥ 56px for mobile */
742.tp-row {
743 display: grid;
744 grid-template-columns: 44px 1fr auto;
745 align-items: center;
746 gap: .75rem;
747 width: 100%;
748 padding: .55rem .65rem;
749 border: 0; background: transparent;
750 border-radius: 10px;
751 text-align: left;
752 cursor: pointer;
753 color: inherit;
754 font: inherit;
755 transition: background var(--transition);
756 -webkit-tap-highlight-color: transparent;
757}
758.tp-row:hover, .tp-row:focus-visible {
759 background: color-mix(in srgb, var(--accent) 8%, var(--paper-2));
760 outline: none;
761}
762.tp-row:active { transform: scale(.98); }
763.tp-row[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
764
765.tp-cover {
766 width: 44px; height: 44px;
767 border-radius: 6px;
768 background-size: cover; background-position: center;
769 background-color: var(--rule);
770 display: inline-flex; align-items: center; justify-content: center;
771 flex-shrink: 0;
772}
773.tp-cover-empty {
774 background: linear-gradient(135deg,
775 color-mix(in srgb, var(--accent) 30%, var(--paper-2)),
776 color-mix(in srgb, var(--accent) 8%, var(--paper-2)));
777 color: var(--accent);
778}
779.tp-cover-empty svg { width: 18px; height: 18px; opacity: .8; }
780
781.tp-meta {
782 display: flex; flex-direction: column;
783 min-width: 0;
784 line-height: 1.25;
785}
786.tp-row-title {
787 font-weight: 600; font-size: .94rem;
788 color: var(--ink);
789 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
790}
791.tp-row-artist {
792 font-size: .8rem;
793 color: var(--ink-muted, var(--ink-soft));
794 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
795 margin-top: .1rem;
796}
797.tp-duration {
798 font-variant-numeric: tabular-nums;
799 font-size: .8rem;
800 color: var(--ink-muted, var(--ink-soft));
801 flex-shrink: 0;
802}
803
804/* Body lock when modal open */
805body.tp-locked { overflow: hidden; touch-action: none; }
806
807/* Desktop: centered card, max-width ~520px */
808@media (min-width: 640px) {
809 .tp-modal {
810 align-items: center;
811 padding: 1.5rem;
812 }
813 .tp-sheet {
814 margin-top: 0;
815 width: 100%;
816 max-width: 520px;
817 max-height: 80dvh;
818 border-radius: 14px;
819 border: 1px solid var(--rule);
820 animation: tp-sheet-pop .2s cubic-bezier(.2, .8, .25, 1);
821 }
822 .tp-header::before { display: none; } /* hide grab-handle on desktop */
823 .tp-header { padding: 1rem 1.25rem .75rem; }
824 .tp-h2 { margin-top: 0; font-size: 1.25rem; }
825 .tp-close { margin-top: 0; }
826 @keyframes tp-sheet-pop {
827 from { transform: translateY(-8px) scale(.97); opacity: 0; }
828 to { transform: translateY(0) scale(1); opacity: 1; }
829 }
830}
831
832/* ─── Buttons ───────────────────────────────────────────────────── */
833.pe-btn {
834 display: inline-flex; align-items: center; gap: 0.4rem;
835 padding: 0.55rem 1rem;
836 border: 1px solid var(--rule);
837 background: var(--paper-2);
838 color: var(--ink);
839 font-family: var(--font-ui, system-ui), sans-serif;
840 font-size: 0.9rem; font-weight: 500;
841 text-decoration: none;
842 border-radius: 6px;
843 cursor: pointer;
844 transition: background 120ms, border-color 120ms;
845 min-height: 40px;
846 -webkit-tap-highlight-color: transparent;
847}
848.pe-btn:hover { border-color: var(--accent); }
849.pe-btn:active { transform: scale(0.97); }
850.pe-btn-tiny {
851 padding: 0.35rem 0.7rem;
852 font-size: 0.85rem;
853 min-height: 32px;
854}
855.pe-btn-secondary { background: var(--paper-2); }
856.pe-btn-primary {
857 background: var(--accent); color: white;
858 border-color: var(--accent);
859}
860.pe-btn-primary:hover { opacity: 0.92; border-color: var(--accent); }
861.pe-btn-success {
862 background: #16a34a; color: white;
863 border-color: #16a34a;
864}
865.pe-btn-success:hover { opacity: 0.92; border-color: #16a34a; }
866
867.pe-status {
868 color: var(--ink-muted, var(--ink-soft));
869 font-size: 0.8rem;
870}
871.pe-status.is-error { color: #dc2626; }
872
873/* ─── Checkboxes (clean inline row) ─────────────────────────────── */
874.pe-checkboxes {
875 display: flex; flex-direction: column;
876 gap: 0.5rem;
877 padding-top: 0.25rem;
878}
879.pe-checkbox {
880 display: inline-flex; align-items: center; gap: 0.5rem;
881 cursor: pointer;
882 font-size: 0.95rem;
883 color: var(--ink);
884 user-select: none;
885}
886.pe-checkbox input[type="checkbox"] {
887 width: 18px; height: 18px;
888 margin: 0;
889 cursor: pointer;
890 accent-color: var(--accent);
891}
892
[edc462d]893/* Vastpinnen: checkbox + ▲▼-stepper met beschrijving (i.p.v. een ruw rang-getal). */
894.pe-pin { display: flex; flex-direction: column; gap: 0.45rem; }
895.pe-pin-pos { display: flex; align-items: center; gap: 0.55rem; padding-left: 1.65rem; }
896.pe-pin-pos[hidden] { display: none; }
897.pe-pin-steps { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
898.pe-pin-btn {
899 width: 30px; height: 28px; padding: 0;
900 border: none; background: var(--paper-2); color: var(--ink);
901 cursor: pointer; font-size: 0.68rem; line-height: 1;
902 display: inline-flex; align-items: center; justify-content: center;
[7bc636b]903}
[edc462d]904.pe-pin-btn + .pe-pin-btn { border-left: 1px solid var(--rule); }
905.pe-pin-btn:hover { background: color-mix(in srgb, var(--accent) 14%, var(--paper-2)); color: var(--accent); }
906.pe-pin-btn:disabled { opacity: 0.35; cursor: default; }
907.pe-pin-label { font-size: 0.85rem; color: var(--accent); font-weight: 600; }
[7bc636b]908
909/* ─── Sticky action footer ──────────────────────────────────────── */
910.pe-actions {
911 position: sticky;
912 bottom: 0;
913 display: flex; align-items: center;
914 gap: 0.5rem;
915 padding: 0.85rem 1rem;
916 margin: 0.5rem -1rem 0; /* extend to viewport edges on tight container */
917 background: color-mix(in srgb, var(--paper) 94%, transparent);
918 -webkit-backdrop-filter: blur(8px);
919 backdrop-filter: blur(8px);
920 border-top: 1px solid var(--rule);
921 z-index: 10;
922}
923.pe-actions-spacer { flex: 1; }
924
[2beef82]925/* De editor is een focus-scherm: verberg de mobiele site-tabbalk (Home/Zoek/…)
926 zodat er niet twee balken onderaan stapelen (Opslaan-balk + tabbalk). De
927 Opslaan/Annuleren-balk wordt dan de enige onderbalk → gewoon op bottom:0,
928 geen tab-offset meer nodig. Op desktop is de tabbalk toch al verborgen. */
929body:has(.post-edit-page) .bottom-tab { display: none; }
930/* Audiospeler (indien aan het spelen) niet meer 56px optillen voor de nu-verborgen
931 tabbalk, anders zou die zweven boven de actiebalk. */
932body:has(.post-edit-page) .audio-player { bottom: 0; }
[7bc636b]933</style>
934
935<script>
936(function() {
937
938 // ── Cover upload ────────────────────────────────────────────────
939 const coverField = document.getElementById('cover-upload-field');
940 const coverTrigger = document.getElementById('cover-upload-trigger');
941 const coverUrl = document.getElementById('cover-url-field');
942 const coverStatus = document.getElementById('cover-upload-status');
943 const coverWrap = document.getElementById('cover-preview-wrap');
944 const coverImg = document.getElementById('cover-preview-img');
945
946 async function uploadImage(file) {
947 const fd = new FormData();
948 fd.append('image', file);
949 const res = await fetch('/posts/upload-image', { method: 'POST', body: fd });
950 if (!res.ok) {
951 const j = await res.json().catch(() => ({}));
952 throw new Error(j.error || ('Upload failed (' + res.status + ')'));
953 }
954 return await res.json(); // {url, size, mime}
955 }
956
957 function showCoverPreview(url) {
958 if (!coverWrap || !coverImg) return;
959 if (url) {
960 coverImg.src = url;
961 coverImg.hidden = false;
962 coverWrap.removeAttribute('data-empty');
963 const emptyIcon = coverWrap.querySelector('.pe-cover-empty');
964 if (emptyIcon) emptyIcon.remove();
965 } else {
966 coverImg.hidden = true;
967 coverImg.src = '';
968 coverWrap.setAttribute('data-empty', '');
969 if (!coverWrap.querySelector('.pe-cover-empty')) {
970 const span = document.createElement('span');
971 span.className = 'pe-cover-empty';
972 span.textContent = '🖼';
973 coverWrap.appendChild(span);
974 }
975 }
976 }
977
978 if (coverTrigger && coverField) {
979 coverTrigger.addEventListener('click', () => coverField.click());
980 }
981 if (coverField) {
982 coverField.addEventListener('change', async () => {
983 if (!coverField.files[0]) return;
984 coverStatus.classList.remove('is-error');
985 coverStatus.textContent = 'Uploaden…';
986 try {
987 const j = await uploadImage(coverField.files[0]);
988 coverUrl.value = j.url;
989 showCoverPreview(j.url);
990 coverStatus.textContent = 'Geüpload ✓';
991 setTimeout(() => { coverStatus.textContent = ''; }, 2000);
992 } catch (e) {
993 coverStatus.classList.add('is-error');
994 coverStatus.textContent = 'Mislukt: ' + e.message;
995 }
996 });
997 }
998 // Live-update preview when user pastes a URL manually
999 if (coverUrl) {
1000 coverUrl.addEventListener('input', () => {
1001 const v = coverUrl.value.trim();
1002 if (v) showCoverPreview(v); else showCoverPreview('');
1003 });
1004 }
1005
1006 // ── WYSIWYG editor (P58) ────────────────────────────────────────
1007 // Architecture:
1008 // - Visible <div contenteditable> (`#content-editor`) is what the user
1009 // types in; it shows real HTML (formatted, not raw markup).
1010 // - Hidden <input name="content"> (`#content-hidden`) is what submits.
1011 // On submit we serialize the editor's HTML into it, with shortcode
1012 // chips reduced back to their [[track:UUID]]/[[album:Name]]/[[playlist:slug]] text.
1013 // - Initial content comes from a <script type="application/json"> tag
1014 // to avoid HTML-escape-into-DOM issues; we set innerHTML once on load
1015 // and walk text nodes to render shortcode tokens as chips.
1016 const contentField = document.getElementById('content-upload-field');
1017 const contentBtn = document.getElementById('insert-image-btn');
1018 const contentStatus = document.getElementById('content-upload-status');
1019 const editor = document.getElementById('content-editor');
1020 const hiddenField = document.getElementById('content-hidden');
1021 const charCountEl = document.getElementById('char-count');
1022 const initialEl = document.getElementById('initial-content');
1023 const toolbar = document.getElementById('pe-toolbar');
1024 const form = editor && editor.closest('form');
1025
1026 if (!editor) return;
1027
[a0bff44]1028 // Titel alleen automatisch focussen op desktop (muis/trackpad). Op touch zou
1029 // dit meteen het toetsenbord openen bij het openen van de editor — niet gewenst.
1030 try {
1031 const titleInput = form && form.querySelector('input[name="title"]');
1032 if (titleInput && window.matchMedia && window.matchMedia('(hover: hover) and (pointer: fine)').matches) {
1033 titleInput.focus({ preventScroll: true });
1034 }
1035 } catch (_) {}
1036
[7bc636b]1037 // ── Shortcode chip rendering / serialization ────────────────────
1038 // Pattern matches [[track:UUID]] / [[album:any text]] / [[playlist:slug]]
1039 // — but we DON'T want to chipify text the user is mid-typing inside an
1040 // HTML attribute; since chipify only walks text nodes (never attribute
1041 // values) that's already safe.
[1907a18]1042 const SC_RE = /\[\[(track|album|playlist|embed):([^\]]+)\]\]/g;
[7bc636b]1043
1044 const SC_ICONS = {
1045 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>',
1046 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>',
1047 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]1048 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]1049 };
1050
1051 function chipLabel(kind, value) {
1052 if (kind === 'track') {
1053 // UUIDs are noisy — show a 6-char prefix for visual hint
1054 const v = String(value || '');
1055 return 'Track ' + (v.length > 8 ? v.slice(0, 6) + '…' : v);
1056 }
1057 if (kind === 'album') return 'Album: ' + value;
1058 if (kind === 'playlist') return 'Playlist: ' + value;
[1907a18]1059 if (kind === 'embed') {
1060 const clean = String(value || '').replace(/^https?:\/\/(www\.)?/, '');
1061 return '▶ ' + (clean.length > 36 ? clean.slice(0, 34) + '…' : clean);
1062 }
[7bc636b]1063 return value;
1064 }
1065
1066 function makeChip(kind, value) {
1067 const span = document.createElement('span');
1068 span.className = 'sc-chip';
1069 span.contentEditable = 'false';
1070 span.setAttribute('data-sc', kind + ':' + value);
1071 span.innerHTML =
1072 '<span class="sc-chip-icon" aria-hidden="true">' + (SC_ICONS[kind] || '') + '</span>' +
1073 '<span class="sc-chip-label"></span>';
1074 span.querySelector('.sc-chip-label').textContent = chipLabel(kind, value);
1075 return span;
1076 }
1077
1078 // Walk text nodes inside `root` and replace [[type:value]] tokens with chips.
1079 function chipifyShortcodes(root) {
1080 const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
1081 const targets = [];
1082 while (walker.nextNode()) {
1083 const n = walker.currentNode;
1084 // Skip text inside existing chips (their .sc-chip-label is set via .textContent so the [[...]] text never appears)
1085 if (n.parentElement && n.parentElement.closest('.sc-chip')) continue;
1086 if (SC_RE.test(n.nodeValue)) targets.push(n);
1087 SC_RE.lastIndex = 0;
1088 }
1089 for (const node of targets) {
1090 const txt = node.nodeValue;
1091 const frag = document.createDocumentFragment();
1092 let last = 0;
1093 let m;
1094 SC_RE.lastIndex = 0;
1095 while ((m = SC_RE.exec(txt)) !== null) {
1096 if (m.index > last) frag.appendChild(document.createTextNode(txt.slice(last, m.index)));
1097 frag.appendChild(makeChip(m[1], m[2].trim()));
1098 last = m.index + m[0].length;
1099 }
1100 if (last < txt.length) frag.appendChild(document.createTextNode(txt.slice(last)));
1101 node.parentNode.replaceChild(frag, node);
1102 }
1103 }
1104
1105 // Inverse of chipify: clone the editor, replace every chip with its text.
1106 function serializeChips(rootClone) {
1107 const chips = rootClone.querySelectorAll('.sc-chip[data-sc]');
1108 for (const c of chips) {
1109 const txt = '[[' + c.getAttribute('data-sc') + ']]';
1110 c.replaceWith(document.createTextNode(txt));
1111 }
1112 }
1113
1114 // ── Boot: load initial content as HTML, then render shortcodes as chips
1115 try {
1116 const initial = JSON.parse(initialEl.textContent || '""');
1117 editor.innerHTML = initial || '';
1118 chipifyShortcodes(editor);
1119 } catch (e) {
1120 console.error('[editor] could not parse initial content', e);
1121 editor.innerHTML = '';
1122 }
1123
1124 // ── Char counter
1125 function updateCharCount() {
1126 const text = (editor.innerText || '').replace(/\s+/g, ' ').trim();
1127 if (charCountEl) charCountEl.textContent = String(text.length);
1128 }
1129 updateCharCount();
1130 editor.addEventListener('input', updateCharCount);
1131
1132 // ── Toolbar wiring
[cbfbf88]1133 // Houd de scrollpositie vast rond een edit-commando. execCommand/insert scrollt
1134 // standaard de caret in beeld → het beeld "verspringt" bij het aanklikken van een
[f8e8f9e]1135 // opmaakknop. We leggen ALLE scrollbare voorouders (editor, frame, #pcms-main, …)
1136 // + de pagina vast en zetten ze terug — sync én over een paar frames, want Chrome
1137 // scrollt soms pas een frame later. De gebruiker scrollt zo zelf.
1138 function scrollableAncestors(el) {
1139 const list = [];
1140 let node = el;
1141 while (node && node !== document.body && node !== document.documentElement) {
1142 const oy = getComputedStyle(node).overflowY;
1143 if (oy === 'auto' || oy === 'scroll' || oy === 'overlay') list.push(node);
1144 node = node.parentElement;
1145 }
1146 return list;
1147 }
[cbfbf88]1148 function keepScroll(fn) {
[e22230e]1149 // In fullscreen staat de pagina vast (body overflow:hidden) en mag het veld
1150 // gewoon naar de caret scrollen — geen pagina-sprong mogelijk, dus niets fixen.
1151 const frame = document.querySelector('.pe-editor-frame');
1152 if (frame && frame.classList.contains('pe-fs')) { fn(); return; }
[f8e8f9e]1153 const wx = window.scrollX, wy = window.scrollY;
1154 const anc = scrollableAncestors(editor).map(function (n) { return [n, n.scrollTop, n.scrollLeft]; });
1155 const restore = function () {
1156 window.scrollTo(wx, wy);
1157 anc.forEach(function (e) { e[0].scrollTop = e[1]; e[0].scrollLeft = e[2]; });
1158 };
[cbfbf88]1159 fn();
[f8e8f9e]1160 restore();
[e22230e]1161 requestAnimationFrame(restore);
[cbfbf88]1162 }
[7bc636b]1163 function execCmd(cmd, arg) {
[cbfbf88]1164 keepScroll(function () {
1165 editor.focus({ preventScroll: true });
1166 document.execCommand(cmd, false, arg);
1167 });
[7bc636b]1168 updateToolbarState();
1169 updateCharCount();
1170 }
1171 function wrapCode() {
1172 const sel = window.getSelection();
1173 if (!sel || sel.rangeCount === 0 || sel.isCollapsed) return;
[cbfbf88]1174 keepScroll(function () {
1175 const range = sel.getRangeAt(0);
1176 const code = document.createElement('code');
1177 code.textContent = sel.toString();
1178 range.deleteContents();
1179 range.insertNode(code);
1180 // Move caret after the new node
1181 range.setStartAfter(code);
1182 range.collapse(true);
1183 sel.removeAllRanges();
1184 sel.addRange(range);
1185 editor.focus({ preventScroll: true });
1186 });
[7bc636b]1187 }
1188 function linkPrompt() {
1189 const url = window.prompt('Link URL (https://… of /pad)');
1190 if (!url) return;
1191 execCmd('createLink', url);
1192 }
[91d948c]1193 // De huidige selectie zit in een <blockquote> binnen de editor? Geef 'm terug.
1194 function blockquoteAncestor() {
1195 const sel = window.getSelection();
1196 if (!sel || sel.rangeCount === 0) return null;
1197 let node = sel.anchorNode;
1198 while (node && node !== editor) {
1199 if (node.nodeType === 1 && node.tagName === 'BLOCKQUOTE') return node;
1200 node = node.parentNode;
1201 }
1202 return null;
1203 }
1204 // Echte toggle: execCommand('formatBlock','blockquote') zet 'm wél AAN maar
1205 // krijgt 'm nooit meer UIT (browser-quirk). Staat de caret al in een quote →
1206 // pak de wrapper uit; anders pas blockquote toe.
1207 function toggleBlockquote() {
[cbfbf88]1208 keepScroll(function () {
1209 editor.focus({ preventScroll: true });
1210 const bq = blockquoteAncestor();
1211 if (bq) {
1212 const parent = bq.parentNode;
1213 // Inhoud uit de quote halen, op z'n plek, en de lege wrapper verwijderen.
1214 const ref = bq;
1215 let firstMoved = null;
1216 while (bq.firstChild) {
1217 const child = bq.firstChild;
1218 if (!firstMoved) firstMoved = child;
1219 parent.insertBefore(child, ref);
1220 }
1221 parent.removeChild(bq);
1222 // Caret terugzetten in de uitgepakte inhoud.
1223 if (firstMoved) {
1224 const sel = window.getSelection();
1225 const range = document.createRange();
1226 range.selectNodeContents(firstMoved.nodeType === 1 ? firstMoved : parent);
1227 range.collapse(false);
1228 sel.removeAllRanges();
1229 sel.addRange(range);
1230 }
1231 } else {
1232 document.execCommand('formatBlock', false, 'blockquote');
[91d948c]1233 }
[cbfbf88]1234 });
[91d948c]1235 updateToolbarState();
1236 updateCharCount();
1237 }
[7bc636b]1238
1239 if (toolbar) {
[a7e8e19]1240 // CRUCIAAL (mobiel + desktop): voorkom dat een toolbar-knop de focus/selectie
1241 // uit het editor-veld steelt. Zonder dit raakt de selectie kwijt bij het tikken
1242 // → execCommand werkt op een lege selectie (vet kan niet meer UIT) én de browser
1243 // scrollt de caret opnieuw in beeld (de "sprong naar beneden"). preventDefault op
1244 // mousedown houdt de focus in de editor; de click blijft gewoon vuren.
1245 toolbar.addEventListener('mousedown', (e) => {
1246 if (e.target.closest('button')) e.preventDefault();
1247 });
[7bc636b]1248 toolbar.addEventListener('click', (e) => {
1249 const btn = e.target.closest('button[data-cmd]');
1250 if (!btn) return;
1251 e.preventDefault();
1252 const cmd = btn.dataset.cmd;
1253 const arg = btn.dataset.arg || null;
1254 if (cmd === 'link-prompt') linkPrompt();
1255 else if (cmd === 'code-wrap') wrapCode();
[91d948c]1256 else if (cmd === 'formatBlock' && arg === 'blockquote') toggleBlockquote();
[7bc636b]1257 else execCmd(cmd, arg);
1258 });
1259 }
1260
[d2078f4]1261 // ── Volledig-scherm schrijfmodus: het schrijfveld vult de hele pagina.
1262 const fsBtn = document.getElementById('pe-fullscreen-btn');
1263 const editorFrame = document.querySelector('.pe-editor-frame');
[61bb585]1264 const isTouch = !!(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
[06f3791]1265
1266 // Op mobiel duwt het toetsenbord de zichtbare (visual) viewport omhoog terwijl
1267 // een position:fixed-frame aan de LAYOUT-viewport blijft hangen → de toolbar
1268 // schuift uit beeld. Houd het fullscreen-frame daarom gelijk aan de visual
1269 // viewport (top + hoogte), zodat de toolbar altijd bovenaan zichtbaar blijft.
1270 function syncFsViewport() {
1271 if (!editorFrame || !editorFrame.classList.contains('pe-fs')) return;
1272 const vv = window.visualViewport;
1273 if (!vv) return;
1274 editorFrame.style.top = vv.offsetTop + 'px';
1275 editorFrame.style.height = vv.height + 'px';
1276 }
1277 function clearFsViewport() {
1278 if (!editorFrame) return;
1279 editorFrame.style.top = '';
1280 editorFrame.style.height = '';
1281 }
[b12e20d]1282 function isFs() { return !!(editorFrame && editorFrame.classList.contains('pe-fs')); }
1283 function applyFs(on) {
[d2078f4]1284 if (!editorFrame) return;
[b12e20d]1285 editorFrame.classList.toggle('pe-fs', on);
[d2078f4]1286 document.body.classList.toggle('pe-fs-open', on);
[de21a3b]1287 document.documentElement.classList.toggle('pe-fs-open', on);
[d2078f4]1288 if (fsBtn) {
1289 fsBtn.setAttribute('aria-pressed', on ? 'true' : 'false');
[b12e20d]1290 fsBtn.title = on ? 'Klaar' : 'Volledig scherm';
[d2078f4]1291 }
[06f3791]1292 if (window.visualViewport) {
1293 if (on) {
1294 window.visualViewport.addEventListener('resize', syncFsViewport);
1295 window.visualViewport.addEventListener('scroll', syncFsViewport);
1296 syncFsViewport();
1297 } else {
1298 window.visualViewport.removeEventListener('resize', syncFsViewport);
1299 window.visualViewport.removeEventListener('scroll', syncFsViewport);
1300 clearFsViewport();
1301 }
1302 }
[61bb585]1303 // Op touch is het veld inline NIET bewerkbaar; alleen in fullscreen wel.
1304 if (isTouch) editor.setAttribute('contenteditable', on ? 'true' : 'false');
[a4f6827]1305 if (on) {
1306 editor.focus({ preventScroll: true });
1307 } else {
1308 if (isTouch) editor.blur();
[b12e20d]1309 // Bij sluiten: naar de TOP van de content scrollen i.p.v. ergens onderaan
[a4f6827]1310 // (footer) te blijven hangen.
1311 requestAnimationFrame(function () {
1312 try { editorFrame.scrollIntoView({ block: 'start' }); } catch (_) {}
1313 });
1314 }
[d2078f4]1315 }
[b12e20d]1316 // De fullscreen schrijf-"pagina": openen pusht een history-state zodat de browser-
1317 // back-knop (en de Klaar-knop) 'm sluit en je terug bent in het formulier — voelt
1318 // als een aparte pagina, maar álle formuliervelden blijven intact (zelfde DOM).
1319 function openFs() {
1320 if (isFs()) return;
1321 try { history.pushState({ peFs: true }, ''); } catch (_) {}
1322 applyFs(true);
1323 }
1324 function closeFs() {
1325 if (!isFs()) return;
1326 if (history.state && history.state.peFs) history.back(); // → popstate sluit af
1327 else applyFs(false);
1328 }
1329 function toggleFullscreen() { if (isFs()) closeFs(); else openFs(); }
1330 window.addEventListener('popstate', function () { if (isFs()) applyFs(false); });
[d2078f4]1331 if (fsBtn) fsBtn.addEventListener('click', toggleFullscreen);
[b12e20d]1332 var fsDoneBtn = document.getElementById('pe-fs-done');
1333 if (fsDoneBtn) fsDoneBtn.addEventListener('click', closeFs);
[d2078f4]1334 document.addEventListener('keydown', (e) => {
[b12e20d]1335 if (e.key === 'Escape' && isFs()) { e.preventDefault(); closeFs(); }
[d2078f4]1336 });
1337
[61bb585]1338 // Op mobiel/tablet (touch): het content-veld is INLINE NIET bewerkbaar — het is
1339 // dan geen tekstveld. Eén tik → fullscreen, waar het wél bewerkbaar wordt
1340 // (toggleFullscreen zet contenteditable aan/uit). Zo kun je nooit inline typen.
[c01f471]1341 if (isTouch) {
[61bb585]1342 editor.setAttribute('contenteditable', 'false');
1343 editor.classList.add('pe-tap-to-edit');
1344 editor.setAttribute('data-placeholder', 'Tik om te schrijven…');
1345 editor.addEventListener('click', function () {
[b12e20d]1346 if (!isFs()) openFs();
[61bb585]1347 });
[c01f471]1348 }
1349
[7bc636b]1350 // Reflect bold/italic/list state on the toolbar buttons
1351 function updateToolbarState() {
1352 if (!toolbar) return;
1353 const cmds = ['bold', 'italic', 'underline', 'insertUnorderedList', 'insertOrderedList'];
1354 for (const cmd of cmds) {
1355 const btn = toolbar.querySelector('button[data-cmd="' + cmd + '"]');
1356 if (!btn) continue;
1357 try { btn.classList.toggle('is-active', document.queryCommandState(cmd)); } catch(_) {}
1358 }
[91d948c]1359 // Quote-knop: actief als de caret in een <blockquote> staat (toggle-feedback).
1360 const bqBtn = toolbar.querySelector('button[data-cmd="formatBlock"][data-arg="blockquote"]');
1361 if (bqBtn) bqBtn.classList.toggle('is-active', !!blockquoteAncestor());
[7bc636b]1362 }
1363 document.addEventListener('selectionchange', () => {
1364 if (document.activeElement === editor) updateToolbarState();
1365 });
1366
1367 // Keyboard shortcuts: Ctrl/Cmd + B/I/U/K
1368 editor.addEventListener('keydown', (e) => {
1369 const mod = e.ctrlKey || e.metaKey;
1370 if (!mod) return;
1371 const k = e.key.toLowerCase();
1372 if (k === 'b') { e.preventDefault(); execCmd('bold'); }
1373 else if (k === 'i') { e.preventDefault(); execCmd('italic'); }
1374 else if (k === 'u') { e.preventDefault(); execCmd('underline'); }
1375 else if (k === 'k') { e.preventDefault(); linkPrompt(); }
1376 });
1377
1378 // Paste: keep it simple — strip formatting unless user wants it. Default
1379 // execCommand 'paste' includes Word/Google-Docs garbage. We accept inline
1380 // styles from clipboard only when shift is held — otherwise plain text.
1381 editor.addEventListener('paste', (e) => {
1382 if (e.shiftKey) return; // user wants formatted paste
1383 const text = (e.clipboardData || window.clipboardData).getData('text/plain');
1384 if (text == null) return;
1385 e.preventDefault();
1386 document.execCommand('insertText', false, text);
1387 });
1388
1389 // ── Image upload (button + drag-drop into the editor)
1390 async function uploadAndInsertImage(file) {
1391 contentStatus.classList.remove('is-error');
1392 contentStatus.textContent = 'Uploaden…';
1393 try {
1394 const j = await uploadImage(file);
1395 const img = '<img src="' + j.url + '" alt="">';
[a7e8e19]1396 editor.focus({ preventScroll: true });
[7bc636b]1397 document.execCommand('insertHTML', false, img);
1398 contentStatus.textContent = 'Ingevoegd ✓';
1399 setTimeout(() => { contentStatus.textContent = ''; }, 2000);
1400 updateCharCount();
1401 } catch (e) {
1402 contentStatus.classList.add('is-error');
1403 contentStatus.textContent = 'Mislukt: ' + e.message;
1404 }
1405 }
1406
1407 if (contentBtn && contentField) {
1408 contentBtn.addEventListener('click', () => contentField.click());
1409 contentField.addEventListener('change', () => {
1410 if (contentField.files[0]) uploadAndInsertImage(contentField.files[0]);
1411 contentField.value = '';
1412 });
1413
1414 editor.addEventListener('dragover', (e) => {
1415 if (e.dataTransfer && e.dataTransfer.types.includes('Files')) {
1416 e.preventDefault();
1417 editor.classList.add('is-dragover');
1418 }
1419 });
1420 editor.addEventListener('dragleave', () => editor.classList.remove('is-dragover'));
1421 editor.addEventListener('drop', async (e) => {
1422 editor.classList.remove('is-dragover');
1423 const files = e.dataTransfer && e.dataTransfer.files;
1424 if (!files || !files.length) return;
1425 e.preventDefault();
1426 for (const f of files) {
1427 if (f.type.startsWith('image/')) await uploadAndInsertImage(f);
1428 }
1429 });
1430 }
1431
1432 // ── Insert chip helpers (track / playlist)
1433 function insertChip(kind, value) {
[a7e8e19]1434 editor.focus({ preventScroll: true });
[7bc636b]1435 const chip = makeChip(kind, value);
1436 // Insert at caret using the Selection API (execCommand insertNode)
1437 const sel = window.getSelection();
1438 if (sel && sel.rangeCount > 0) {
1439 const range = sel.getRangeAt(0);
1440 range.deleteContents();
1441 range.insertNode(chip);
1442 // Insert a trailing space so the user can keep typing after the chip
1443 const space = document.createTextNode('\u00A0');
1444 chip.after(space);
1445 range.setStartAfter(space);
1446 range.collapse(true);
1447 sel.removeAllRanges();
1448 sel.addRange(range);
1449 } else {
1450 editor.appendChild(chip);
1451 editor.appendChild(document.createTextNode('\u00A0'));
1452 }
1453 updateCharCount();
1454 }
1455
[1907a18]1456 // ── Embed insert: plak een platform-URL -> [[embed:url]]-chip die server-side
1457 // een iframe wordt (YouTube/Spotify/SoundCloud/Vimeo/Apple Music/Bandcamp).
1458 const embedBtn = document.getElementById('insert-embed-btn');
1459 if (embedBtn) {
1460 embedBtn.addEventListener('click', () => {
1461 const raw = window.prompt('Plak een media-URL om in te sluiten\n(YouTube, Spotify, SoundCloud, Vimeo, Apple Music, Bandcamp):');
1462 if (!raw) return;
1463 const url = raw.trim();
1464 if (!/^https?:\/\//i.test(url)) { alert('Geef een volledige URL (https://…).'); return; }
[fef781e]1465 insertChip('embed', url);
[1907a18]1466 });
1467 }
1468
[7bc636b]1469 // ── Track insert: opens the track-picker modal (P59)
1470 const trackBtn = document.getElementById('insert-track-btn');
1471 const trackPicker = document.getElementById('track-picker');
1472 if (trackBtn && trackPicker) {
1473 const tpList = document.getElementById('tp-list');
1474 const tpEmpty = document.getElementById('tp-empty');
1475 const tpSearch = document.getElementById('tp-search');
1476 let tpCache = null; // cached tracks list (fetched once per page load)
1477 let tpLastFocus = null; // element to restore focus to on close
1478
1479 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>';
1480
1481 function fmtDur(sec) {
1482 sec = Math.max(0, Math.floor(sec || 0));
1483 const m = Math.floor(sec / 60), s = sec % 60;
1484 return m + ':' + String(s).padStart(2, '0');
1485 }
1486 function escAttr(s) {
1487 return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({
1488 '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'
1489 }[c]));
1490 }
1491
1492 function renderList(filter) {
1493 if (!Array.isArray(tpCache)) return;
1494 const q = (filter || '').trim().toLowerCase();
1495 const filtered = q
1496 ? tpCache.filter(t =>
1497 (t.title || '').toLowerCase().includes(q) ||
1498 (t.artist || '').toLowerCase().includes(q))
1499 : tpCache;
1500
1501 if (!filtered.length) {
1502 tpList.innerHTML = '';
1503 tpEmpty.textContent = q ? 'Geen tracks gevonden voor "' + q + '"' : 'Nog geen tracks. Upload via Beheer → Audio.';
1504 tpList.appendChild(tpEmpty);
1505 return;
1506 }
1507
1508 tpList.innerHTML = filtered.map(t => {
1509 const cov = t.cover
1510 ? '<span class="tp-cover" style="background-image:url(\'' + escAttr(t.cover) + '\')"></span>'
1511 : '<span class="tp-cover tp-cover-empty">' + SVG_NOTE + '</span>';
1512 const dis = t.playable ? '' : ' aria-disabled="true"';
1513 const sub = t.artist ? '<span class="tp-row-artist">' + escAttr(t.artist) + '</span>' : '';
1514 return (
1515 '<button type="button" class="tp-row" role="option" data-track-id="' + escAttr(t.id) + '"' + dis + '>' +
1516 cov +
1517 '<span class="tp-meta">' +
1518 '<span class="tp-row-title">' + escAttr(t.title) + '</span>' +
1519 sub +
1520 '</span>' +
1521 '<span class="tp-duration">' + fmtDur(t.duration) + '</span>' +
1522 '</button>'
1523 );
1524 }).join('');
1525 }
1526
1527 async function loadTracks() {
1528 if (Array.isArray(tpCache)) return tpCache;
1529 tpEmpty.textContent = 'Tracks laden…';
1530 try {
1531 const r = await fetch('/admin/playlists/api/tracks', { credentials: 'same-origin' });
1532 const j = await r.json();
1533 tpCache = (j && j.ok && Array.isArray(j.tracks)) ? j.tracks : [];
1534 } catch (e) {
1535 tpCache = [];
1536 tpEmpty.textContent = 'Kon tracks niet laden: ' + e.message;
1537 }
1538 return tpCache;
1539 }
1540
1541 function openPicker() {
1542 tpLastFocus = document.activeElement;
1543 trackPicker.hidden = false;
1544 trackPicker.setAttribute('aria-hidden', 'false');
1545 document.body.classList.add('tp-locked');
1546 tpSearch.value = '';
1547 renderList('');
1548 // Defer focus so the open animation doesn't get jumped
1549 setTimeout(() => tpSearch.focus(), 30);
1550 }
1551 function closePicker() {
1552 trackPicker.hidden = true;
1553 trackPicker.setAttribute('aria-hidden', 'true');
1554 document.body.classList.remove('tp-locked');
1555 if (tpLastFocus && typeof tpLastFocus.focus === 'function') {
1556 try { tpLastFocus.focus(); } catch(_) {}
1557 }
1558 }
1559
1560 trackBtn.addEventListener('click', async () => {
1561 openPicker();
1562 await loadTracks();
1563 renderList(tpSearch.value);
1564 });
1565
1566 // Close: backdrop click, [data-tp-close], or Escape
1567 trackPicker.addEventListener('click', (e) => {
1568 if (e.target.closest('[data-tp-close]')) {
1569 closePicker();
1570 return;
1571 }
1572 const row = e.target.closest('.tp-row[data-track-id]');
1573 if (row) {
1574 if (row.getAttribute('aria-disabled') === 'true') return;
1575 const id = row.dataset.trackId;
1576 if (id) {
1577 insertChip('track', id);
1578 closePicker();
1579 }
1580 }
1581 });
1582 document.addEventListener('keydown', (e) => {
1583 if (!trackPicker.hidden && e.key === 'Escape') {
1584 e.preventDefault();
1585 closePicker();
1586 }
1587 });
1588
1589 // Live filter
1590 tpSearch.addEventListener('input', () => renderList(tpSearch.value));
1591 }
1592
1593 // ── Playlist insert (open existing or create new via modal)
1594 const playlistBtn = document.getElementById('insert-playlist-btn');
1595 if (playlistBtn) {
1596 playlistBtn.addEventListener('click', async () => {
1597 if (typeof window.openPlaylistEditor !== 'function') {
1598 alert('Playlist editor niet geladen');
1599 return;
1600 }
1601 try {
1602 const r = await fetch('/admin/playlists/api/list', { credentials: 'same-origin' });
1603 const j = await r.json();
1604 if (j.ok && Array.isArray(j.playlists) && j.playlists.length > 0) {
1605 const choice = prompt(
1606 'Bestaande playlists:\n\n' +
1607 j.playlists.map((p, i) => `${i + 1}. ${p.title} (${p.track_count} tracks)`).join('\n') +
1608 '\n\nKies een nummer om in te voegen, leeg = nieuwe maken:'
1609 );
1610 if (choice && /^\d+$/.test(choice.trim())) {
1611 const idx = parseInt(choice.trim(), 10) - 1;
1612 if (idx >= 0 && idx < j.playlists.length) {
1613 insertChip('playlist', j.playlists[idx].id);
1614 return;
1615 }
1616 }
1617 if (choice === null) return;
1618 }
1619 } catch (_) { /* fall through to create */ }
1620
1621 window.openPlaylistEditor({
1622 mode: 'create',
1623 onSaved: ({ id }) => insertChip('playlist', id),
1624 });
1625 });
1626 }
1627
1628 // ── Submit: serialize editor contents into the hidden field
1629 if (form && hiddenField) {
1630 form.addEventListener('submit', () => {
1631 const clone = editor.cloneNode(true);
1632 serializeChips(clone);
1633 hiddenField.value = clone.innerHTML;
1634 });
1635 }
1636})();
1637</script>
1638
1639<%# ── Track picker modal (P59). Mobile-first: full-screen sheet on small
1640 viewports, centered modal on ≥640px. Populated lazily on first open. %>
1641<% if (typeof user !== 'undefined' && user) { %>
1642<div id="track-picker" class="tp-modal" hidden aria-hidden="true">
1643 <div class="tp-backdrop" data-tp-close></div>
1644 <div class="tp-sheet" role="dialog" aria-modal="true" aria-labelledby="tp-title">
1645 <header class="tp-header">
1646 <h2 id="tp-title" class="tp-h2">Track invoegen</h2>
1647 <button type="button" class="tp-close" data-tp-close aria-label="Sluiten">
1648 <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>
1649 </button>
1650 </header>
1651 <div class="tp-search-row">
1652 <span class="tp-search-icon" aria-hidden="true">
1653 <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>
1654 </span>
1655 <input type="search" class="tp-search" id="tp-search" placeholder="Zoek op titel of artiest…" autocomplete="off" inputmode="search">
1656 </div>
1657 <div class="tp-list" id="tp-list" role="listbox" aria-label="Tracks">
1658 <div class="tp-empty" id="tp-empty">Tracks laden…</div>
1659 </div>
1660 </div>
1661</div>
1662<% } %>
1663
1664<%# Playlist editor modal — included so its global window.openPlaylistEditor
1665 is available when the toolbar button fires. Only renders if user can post. %>
1666<% if (typeof user !== 'undefined' && user) { %>
1667 <%- include('../partials/playlist-editor', { csrfToken: (typeof csrfToken !== 'undefined' ? csrfToken : '') }) %>
1668<% } %>
[edc462d]1669
1670<script>
1671(function () {
1672 // Vastpinnen: checkbox toggelt het verborgen rang-veld (0 = niet gepind),
1673 // ▲▼ verschuift de plek, met een leesbare beschrijving i.p.v. een ruw getal.
1674 var toggle = document.getElementById('pin-toggle');
1675 var rank = document.getElementById('pin-rank');
1676 var pos = document.getElementById('pin-pos');
1677 var label = document.getElementById('pin-label');
1678 var up = document.getElementById('pin-up'); // hoger = lager getal (richting 1/bovenaan)
1679 var down = document.getElementById('pin-down');
1680 if (!toggle || !rank || !pos) return;
1681
1682 function descr(n) {
1683 n = Number(n) || 0;
1684 if (n <= 1) return 'bovenaan';
1685 return n + 'e van boven';
1686 }
1687 function render() {
1688 var on = toggle.checked;
1689 pos.hidden = !on;
1690 if (on && Number(rank.value) < 1) rank.value = 1;
1691 if (!on) rank.value = 0;
1692 if (label) label.textContent = on ? descr(rank.value) : '';
1693 if (up) up.disabled = Number(rank.value) <= 1;
1694 }
1695 toggle.addEventListener('change', render);
1696 if (up) up.addEventListener('click', function () { rank.value = Math.max(1, (Number(rank.value) || 1) - 1); render(); });
1697 if (down) down.addEventListener('click', function () { rank.value = (Number(rank.value) || 0) + 1; render(); });
1698 render();
1699})();
[d3e2987]1700
1701(function () {
[5f7dba2]1702 // De Opslaan/Annuleren-balk (position: sticky; bottom:0) net boven twee mogelijke
1703 // obstakels houden door een dynamische bottom-offset te zetten = het grootste van:
1704 // 1) de hoogte van het toetsenbord-deel dat de layout-viewport NIET dekt
1705 // (op iOS verschuift de visual viewport; op Android verkleint de layout-
1706 // viewport door interactive-widget=resizes-content → offset ≈ 0);
1707 // 2) de hoogte van de spelende audiospeler (fixed, z-index 1000).
1708 // We blijven bij sticky (geen fixed/top-gegoochel → geen balk midden in beeld).
[d3e2987]1709 var bar = document.querySelector('.pe-actions');
1710 if (!bar) return;
[408afc1]1711 var vv = window.visualViewport;
[5f7dba2]1712 function position() {
[d3e2987]1713 var ap = document.querySelector('.audio-player');
1714 var playing = document.body.classList.contains('has-audio-player') &&
1715 ap && getComputedStyle(ap).display !== 'none';
[5f7dba2]1716 var audioOffset = playing ? Math.round(ap.getBoundingClientRect().height) : 0;
1717 var kbCovered = vv ? Math.max(0, Math.round(window.innerHeight - vv.height - vv.offsetTop)) : 0;
1718 var offset = Math.max(audioOffset, kbCovered);
1719 bar.style.bottom = offset ? offset + 'px' : '';
[408afc1]1720 }
1721 position();
1722 window.addEventListener('resize', position);
1723 if (vv) { vv.addEventListener('resize', position); vv.addEventListener('scroll', position); }
[5f7dba2]1724 // has-audio-player wisselt via een body-class → daarop reageren.
[408afc1]1725 try { new MutationObserver(position).observe(document.body, { attributes: true, attributeFilter: ['class'] }); } catch (_) {}
[d3e2987]1726})();
[edc462d]1727</script>
Note: See TracBrowser for help on using the repository browser.