Redesign the image section of the slide form

Show a dropzone (with drag and drop) while a slide has no image and a
row with preview, replace and remove buttons otherwise. A newly chosen
file is previewed right away. Placement is picked from tiles with a
small sketch instead of long radio labels, technical details move into
a collapsible help. The section gets full-width dividers, and the modal
a slim scrollbar.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-17 14:21:27 +01:00
1 parent 0ad29aa484
commit c6a92e347f
5 files changed
+257 -92

No files matched your search

+51 -7
View File
@@ -816,6 +816,8 @@ body.present {
.modal::backdrop { background: rgba(10, 12, 30, .55); }
.modal__panel {
max-height: calc(100dvh - 24px); overflow: auto;
/* slim scrollbar in the theme colours instead of the bright system one */
scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 55%, transparent) transparent;
border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
@@ -836,12 +838,54 @@ body:has(dialog[open]) { overflow: hidden; }
/* slide images: participant page and slide form */
.slide-image { margin: 1em 0; }
.slide-image img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px; }
.image-fields, .image-fields__layout { border: 0; padding: 0; margin: 0 0 16px; min-width: 0; }
/* Full width dividers: reach through the 24px padding of .card. */
.image-section { margin: 24px -24px; padding: 16px 24px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.image-fields, .image-layout { border: 0; padding: 0; margin: 0; min-width: 0; }
.image-fields > legend { font-weight: 600; padding: 0; margin-bottom: .5em; }
.image-fields__layout > legend { padding: 0; margin-bottom: .25em; }
.image-fields__current { margin: 0 0 .75em; }
.image-fields__optional { font-weight: 400; color: var(--muted); }
.image-layout { margin-top: 16px; }
.image-layout > legend { font-weight: 600; padding: 0; margin-bottom: .5em; }
.image-layout .hint { margin-bottom: 0; }
/* dropzone (no image yet) */
.image-drop {
display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
padding: 20px 16px; border: 2px dashed var(--border); border-radius: 10px;
color: var(--muted); cursor: pointer;
}
.image-drop[hidden] { display: none; }
.image-drop:hover, .image-drop.is-dragover, .image-fields:has(input[type="file"]:focus-visible) .image-drop {
border-color: var(--primary); background: var(--primary-soft); color: var(--text);
}
.image-fields:has(input[type="file"]:focus-visible) .image-drop { outline: 3px solid var(--primary); outline-offset: 2px; }
.image-drop__title { font-weight: 600; color: var(--text); }
.image-drop__hint { font-size: .875rem; }
/* current or chosen image: thumbnail, info, buttons */
.image-fields__row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; }
.image-fields__row[hidden] { display: none; }
.image-fields__row.is-dragover { border-color: var(--primary); background: var(--primary-soft); }
.image-fields__current { margin: 0; flex: none; }
.image-fields__current img { display: block; max-width: 160px; max-height: 110px; width: auto; height: auto; border-radius: 6px; background: var(--surface-2); }
.image-fields__current.is-removed img { opacity: .3; filter: grayscale(1); }
.image-fields__remove { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 0 0 1em; }
.image-fields__remove .button { display: inline-flex; align-items: center; gap: 6px; }
.image-fields__remove .hint { margin: 0; }
.image-fields__current img { display: block; max-width: 100%; max-height: 180px; width: auto; height: auto; border-radius: 6px; }
.image-fields__side { flex: 1 1 200px; min-width: 0; }
.image-fields__info { margin: 0 0 8px; font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }
.image-fields__buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.image-fields__buttons .button { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.image-fields:has(input[type="file"]:focus-visible) .image-fields__buttons [data-image-pick] { outline: 3px solid var(--primary); outline-offset: 2px; }
.image-fields__remove { margin: 0; }
.image-fields__help { margin-top: 8px; font-size: .875rem; color: var(--muted); }
.image-fields__help summary { cursor: pointer; width: fit-content; }
.image-fields__help .hint { margin: .5em 0 0; }
/* placement tiles (radios) */
.image-layout__tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; max-width: 420px; }
.image-layout__tile {
display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 8px;
border: 2px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--muted); font-size: .9rem;
}
.image-layout__tile svg { max-width: 100%; height: auto; }
.image-layout__tile svg .img { fill: var(--primary); opacity: .45; }
.image-layout__tile:hover { border-color: var(--primary); }
.image-layout__tile:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--text); font-weight: 600; }
.image-layout__tile:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
+118 -38
View File
@@ -2279,51 +2279,132 @@
// ------------------------------------------------------------------ slide form
/** Slide image: a trash button toggles the "remove image" checkbox (the checkbox stays for use without JavaScript). */
function initImageRemove(box) {
var checkbox = box.querySelector('input[type="checkbox"]');
var button = box.querySelector('[data-image-remove-button]');
var status = box.querySelector('[data-image-remove-status]');
var figure = box.parentNode.querySelector('.image-fields__current');
if (!checkbox || !button) {
return;
}
var field = checkbox.closest('.input');
if (field) {
field.hidden = true;
}
button.hidden = false;
button.addEventListener('click', function () {
checkbox.checked = !checkbox.checked;
button.setAttribute('aria-pressed', checkbox.checked ? 'true' : 'false');
button.querySelector('[data-label]').textContent = button.getAttribute(checkbox.checked ? 'data-label-undo' : 'data-label-remove');
if (figure) {
figure.classList.toggle('is-removed', checkbox.checked);
}
if (status) {
status.textContent = checkbox.checked ? 'Das Bild wird beim Speichern entfernt.' : '';
}
});
}
/**
* Slide image: the placement question only makes sense with an image, i.e. an existing one that is not
* marked for removal, or a newly selected file. Without JavaScript it stays visible.
* Slide image section: dropzone (also drag and drop) while there is no image, otherwise a row with
* preview and replace/remove buttons. A newly chosen file is previewed right away. The placement
* question only shows with an image (existing and not marked for removal, or a chosen file).
* Without JavaScript the label opens the file dialog, the checkbox removes and the placement stays visible.
*/
function initImageFields(box) {
var layout = box.querySelector('[data-image-layout]');
var file = box.querySelector('input[type="file"]');
var remove = box.querySelector('input[name="remove_image"]');
if (!layout || !file) {
var layout = box.querySelector('[data-image-layout]');
var drop = box.querySelector('[data-image-drop]');
var row = box.querySelector('[data-image-row]');
var img = box.querySelector('[data-image-figure] img');
var figure = box.querySelector('[data-image-figure]');
var info = box.querySelector('[data-image-info]');
var pick = box.querySelector('[data-image-pick]');
var button = box.querySelector('[data-image-remove-button]');
var checkbox = box.querySelector('input[name="remove_image"]');
if (!file || !layout || !drop || !row || !img || !button) {
return;
}
var hasImage = box.hasAttribute('data-has-image');
function update() {
var removed = !!remove && remove.checked;
layout.hidden = !(file.files && file.files.length > 0) && !(hasImage && !removed);
var original = img.getAttribute('data-image-original') || '';
var width = img.getAttribute('width');
var height = img.getAttribute('height');
var objectUrl = null;
// The checkbox is replaced by the button (it stays in the form and is toggled by it).
var removeBox = box.querySelector('[data-image-remove]');
if (removeBox) {
removeBox.hidden = true;
}
box.addEventListener('change', update);
box.addEventListener('click', update);
var extra = box.querySelector('[data-image-drop-extra]');
if (extra) {
extra.hidden = false;
}
button.hidden = false;
function formatSize(bytes) {
return bytes < 1048576 ? Math.max(1, Math.round(bytes / 1024)) + ' KB' : (bytes / 1048576).toFixed(1).replace('.', ',') + ' MB';
}
function update() {
var chosen = !!file.files && file.files.length > 0;
var removed = !!checkbox && checkbox.checked && !chosen;
if (objectUrl) {
URL.revokeObjectURL(objectUrl);
objectUrl = null;
}
if (chosen) {
objectUrl = URL.createObjectURL(file.files[0]);
img.src = objectUrl;
img.removeAttribute('width');
img.removeAttribute('height');
} else {
img.src = original;
if (width && height) {
img.setAttribute('width', width);
img.setAttribute('height', height);
}
}
var showRow = chosen || hasImage;
var focusLost = row.hidden === false && !showRow;
row.hidden = !showRow;
drop.hidden = showRow;
figure.classList.toggle('is-removed', removed);
if (info) {
info.textContent = chosen
? info.getAttribute('data-text-new') + ' ' + file.files[0].name + ' (' + formatSize(file.files[0].size) + ')'
: (removed ? info.getAttribute('data-text-removed') : (hasImage ? info.getAttribute('data-text-current') : ''));
}
if (pick) {
pick.textContent = pick.getAttribute(chosen || !hasImage ? 'data-label-choose' : 'data-label-replace');
}
button.querySelector('[data-label]').textContent = button.getAttribute(chosen ? 'data-label-discard' : (removed ? 'data-label-undo' : 'data-label-remove'));
if (!chosen && checkbox) {
button.setAttribute('aria-pressed', removed ? 'true' : 'false');
} else {
button.removeAttribute('aria-pressed');
}
layout.hidden = !chosen && !(hasImage && !removed);
if (focusLost) {
file.focus();
}
}
file.addEventListener('change', function () {
if (file.files && file.files.length > 0 && checkbox) {
// A new image replaces the old one, so "remove" no longer applies.
checkbox.checked = false;
}
update();
});
button.addEventListener('click', function () {
if (file.files && file.files.length > 0) {
file.value = '';
} else if (checkbox) {
checkbox.checked = !checkbox.checked;
}
update();
});
[drop, row].forEach(function (zone) {
zone.addEventListener('dragover', function (event) {
event.preventDefault();
zone.classList.add('is-dragover');
});
zone.addEventListener('dragleave', function () {
zone.classList.remove('is-dragover');
});
zone.addEventListener('drop', function (event) {
event.preventDefault();
zone.classList.remove('is-dragover');
var dropped = event.dataTransfer && event.dataTransfer.files;
if (!dropped || dropped.length === 0 || typeof DataTransfer === 'undefined') {
return;
}
try {
var transfer = new DataTransfer();
transfer.items.add(dropped[0]);
file.files = transfer.files;
file.dispatchEvent(new Event('change', {bubbles: true}));
} catch (e) {
// Browser without assignable file lists: the file dialog still works.
}
});
});
update();
}
@@ -2967,7 +3048,6 @@
initCopy(root);
root.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm);
root.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions);
root.querySelectorAll('[data-image-remove]').forEach(initImageRemove);
root.querySelectorAll('[data-image-fields]').forEach(initImageFields);
root.querySelectorAll('[data-sortable]').forEach(initSortable);
root.querySelectorAll('[data-order-options]').forEach(initOrderOptions);