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

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

fix(editor): exit fullscreen scrolls to content top + clearer tap hint

  • On shrink, the content frame scrolls to block:start (top) instead of jumping to the footer.
  • "Tap to edit" is now a centred pill + dashed border around the field (on touch) instead of a small, unobtrusive corner pill.

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

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