From 945fc94e779fa313be8e73ba52b494fe3b9f8e53 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 18 Nov 2026 08:19:58 +0100 Subject: [PATCH] Add PNG download for the participant QR code in the admin A button appears on hover/focus over the QR code (always visible on touch devices) and saves it as a 1024px PNG, rendered client-side from the SVG via canvas. No new dependency or server image library needed. Co-Authored-By: Claude Sonnet 5.5 --- docs/frontend.md | 2 +- templates/Admin/index.php | 6 ++++- webroot/css/plenario.css | 5 +++++ webroot/js/plenario.js | 47 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/docs/frontend.md b/docs/frontend.md index 51aa88c..e84a038 100644 --- a/docs/frontend.md +++ b/docs/frontend.md @@ -5,7 +5,7 @@ Dashboard-Fragmente, Farbschema, Textformatierung, Vollbild. CSP-Regeln stehen i ## Dashboard ohne Neuladen - **Einklappbare Seitenleiste** der Verwaltung: `
` mit `

`. Standard: Teilnahme, - Einstellungen (direkt unter dem QR-Code) offen; „Ergebnisse als PDF“, „In Präsentation einbetten“ und „Sicherheit“ zu. + Einstellungen (direkt unter dem QR-Code; beim Hover/Fokus erscheint „Als PNG speichern“, `data-qr-download` rendert das SVG per Canvas als 1024-px-PNG, nur im Admin) offen; „Ergebnisse als PDF“, „In Präsentation einbetten“ und „Sicherheit“ zu. Offene Karten trennt eine Linie zwischen Überschrift und Inhalt. Anker-Links wie `#export` öffnen ihre Karte (`openCollapsible()` in `plenario.js`). diff --git a/templates/Admin/index.php b/templates/Admin/index.php index d9c201e..245a10d 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -230,7 +230,11 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-

formattedJoinCode()) ?>

- <?= __('QR-Code zur Teilnahme') ?> +
+ <?= __('QR-Code zur Teilnahme') ?> + +
diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index 455a48a..240ab5d 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -347,6 +347,11 @@ textarea { resize: vertical; } .join-code { font-size: 2rem; font-weight: 800; letter-spacing: .12em; text-align: center; margin: 0 0 12px; } .qr { display: block; margin: 0 auto 16px; background: #fff; border-radius: 8px; padding: 6px; } +.qr-wrap { position: relative; width: fit-content; margin: 0 auto; } +.qr-wrap .qr { margin-bottom: 16px; } +.qr-wrap__download { position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); white-space: nowrap; opacity: 0; transition: opacity .15s; } +.qr-wrap:hover .qr-wrap__download, .qr-wrap:focus-within .qr-wrap__download { opacity: 1; } +@media (hover: none) { .qr-wrap__download { opacity: 1; } } .copy-field { display: flex; gap: 8px; } .copy-field input { font-size: .85rem; } diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index d94b4b7..a38b0ce 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -3,7 +3,8 @@ * * Modules (auto-initialised by data attributes): * - [data-copy] copy the value of the sibling [data-copy-source] - * - [data-share] native share sheet (Web Share API), fallback: copy like [data-copy] + * - [data-qr-download] save the sibling QR (SVG) as PNG via canvas + * - [data-share] native share sheet (Web Share API), fallback: copy like [data-copy] * - [data-youtube-form] slide form: "Link prüfen" for YouTube slides (status + preview) * - [data-presenter] presenter screen, polls /admin/{token}/state; * with [data-embed]: one embedded slide (/e/{key}/{id}), goes live while visible @@ -1165,6 +1166,49 @@ }); } + // ------------------------------------------------------------------ QR download + + /** + * [data-qr-download]: renders the SVG QR code (the sibling ) onto a canvas and saves it as PNG. + * data-filename sets the file name. Hidden without JS / canvas support. + */ + function initQrDownload() { + document.querySelectorAll('[data-qr-download]').forEach(function (button) { + var img = button.parentNode.querySelector('img'); + if (!img || !document.createElement('canvas').toBlob) { + return; + } + button.hidden = false; + button.addEventListener('click', function () { + var size = 1024; + // The SVG has only a viewBox; an explicit size keeps Firefox from refusing to draw it. + var source = new Image(size, size); + source.onload = function () { + var canvas = document.createElement('canvas'); + canvas.width = size; + canvas.height = size; + var ctx = canvas.getContext('2d'); + ctx.fillStyle = '#fff'; + ctx.fillRect(0, 0, size, size); + ctx.drawImage(source, 0, 0, size, size); + canvas.toBlob(function (blob) { + if (!blob) { + return; + } + var link = document.createElement('a'); + link.href = URL.createObjectURL(blob); + link.download = button.getAttribute('data-filename') || 'qr-code.png'; + document.body.appendChild(link); + link.click(); + link.remove(); + setTimeout(function () { URL.revokeObjectURL(link.href); }, 1000); + }, 'image/png'); + }; + source.src = img.currentSrc || img.src; + }); + }); + } + // ------------------------------------------------------------------ share /** @@ -3121,6 +3165,7 @@ document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch); initWidgets(document); initShare(); + initQrDownload(); initAdminDashboard(); document.querySelectorAll('[data-presenter]').forEach(initPresenter); document.querySelectorAll('[data-participant]').forEach(initParticipant); -- 2.54.1