Use a trash button to remove a slide image
CI / Deploy / PHP 8.4 (push) Successful in 1m35s
CI / Deploy / PHP 8.5 (push) Successful in 1m35s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

With JavaScript the "remove image" checkbox is replaced by a button with a
trash icon that toggles the same checkbox, dims the preview and announces
the pending removal. Without JavaScript the checkbox still works.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-15 13:54:13 +01:00
1 parent a395b50894
commit 8522918c75
3 files changed
+51 -7

No files matched your search

+28
View File
@@ -2232,6 +2232,33 @@
// ------------------------------------------------------------------ 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.' : '';
}
});
}
/** Quiz slide form: add further answer rows (the server renders a few already). */
function initQuizOptions(fieldset) {
var list = fieldset.querySelector('[data-quiz-list]');
@@ -2851,6 +2878,7 @@
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-sortable]').forEach(initSortable);
root.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
root.querySelectorAll('[data-scale-style]').forEach(initScaleStyle);