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 <noreply@anthropic.com>
This commit is contained in:
1 parent
a9b14af8bf
commit
945fc94e77
4 files changed
+55
-1
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ Dashboard-Fragmente, Farbschema, Textformatierung, Vollbild. CSP-Regeln stehen i
|
|||||||
## Dashboard ohne Neuladen
|
## Dashboard ohne Neuladen
|
||||||
|
|
||||||
- **Einklappbare Seitenleiste** der Verwaltung: `<details class="card collapsible">` mit `<summary><h2>`. Standard: Teilnahme,
|
- **Einklappbare Seitenleiste** der Verwaltung: `<details class="card collapsible">` mit `<summary><h2>`. 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.
|
Offene Karten trennt eine Linie zwischen Überschrift und Inhalt.
|
||||||
Anker-Links wie `#export` öffnen ihre Karte (`openCollapsible()` in `plenario.js`).
|
Anker-Links wie `#export` öffnen ihre Karte (`openCollapsible()` in `plenario.js`).
|
||||||
|
|
||||||
|
|||||||
@@ -230,7 +230,11 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
|
|||||||
<details class="card collapsible" open>
|
<details class="card collapsible" open>
|
||||||
<summary><h2><?= __('Teilnahme') ?></h2></summary>
|
<summary><h2><?= __('Teilnahme') ?></h2></summary>
|
||||||
<p class="join-code"><?= h($poll->formattedJoinCode()) ?></p>
|
<p class="join-code"><?= h($poll->formattedJoinCode()) ?></p>
|
||||||
|
<div class="qr-wrap">
|
||||||
<img class="qr" src="<?= $this->Url->build($url('admin:qr')) ?>" alt="<?= __('QR-Code zur Teilnahme') ?>" width="160" height="160">
|
<img class="qr" src="<?= $this->Url->build($url('admin:qr')) ?>" alt="<?= __('QR-Code zur Teilnahme') ?>" width="160" height="160">
|
||||||
|
<button type="button" class="button button--small qr-wrap__download" data-qr-download
|
||||||
|
data-filename="plenario-qr-<?= h($poll->join_code) ?>.png" hidden><?= __('Als PNG speichern') ?></button>
|
||||||
|
</div>
|
||||||
<div class="copy-field">
|
<div class="copy-field">
|
||||||
<input type="text" readonly value="<?= h($joinUrl) ?>" aria-label="<?= __('Teilnahme-Link') ?>" data-copy-source>
|
<input type="text" readonly value="<?= h($joinUrl) ?>" aria-label="<?= __('Teilnahme-Link') ?>" data-copy-source>
|
||||||
<button type="button" class="button button--small" data-copy><?= __('Kopieren') ?></button>
|
<button type="button" class="button button--small" data-copy><?= __('Kopieren') ?></button>
|
||||||
|
|||||||
@@ -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; }
|
.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 { 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 { display: flex; gap: 8px; }
|
||||||
.copy-field input { font-size: .85rem; }
|
.copy-field input { font-size: .85rem; }
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Modules (auto-initialised by data attributes):
|
* Modules (auto-initialised by data attributes):
|
||||||
* - [data-copy] copy the value of the sibling [data-copy-source]
|
* - [data-copy] copy the value of the sibling [data-copy-source]
|
||||||
|
* - [data-qr-download] save the sibling QR <img> (SVG) as PNG via canvas
|
||||||
* - [data-share] native share sheet (Web Share API), fallback: copy like [data-copy]
|
* - [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-youtube-form] slide form: "Link prüfen" for YouTube slides (status + preview)
|
||||||
* - [data-presenter] presenter screen, polls /admin/{token}/state;
|
* - [data-presenter] presenter screen, polls /admin/{token}/state;
|
||||||
@@ -1165,6 +1166,49 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ QR download
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [data-qr-download]: renders the SVG QR code (the sibling <img>) 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
|
// ------------------------------------------------------------------ share
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3121,6 +3165,7 @@
|
|||||||
document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch);
|
document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch);
|
||||||
initWidgets(document);
|
initWidgets(document);
|
||||||
initShare();
|
initShare();
|
||||||
|
initQrDownload();
|
||||||
initAdminDashboard();
|
initAdminDashboard();
|
||||||
document.querySelectorAll('[data-presenter]').forEach(initPresenter);
|
document.querySelectorAll('[data-presenter]').forEach(initPresenter);
|
||||||
document.querySelectorAll('[data-participant]').forEach(initParticipant);
|
document.querySelectorAll('[data-participant]').forEach(initParticipant);
|
||||||
|
|||||||
Reference in new issue
Block a user