Add embeddable slides and pause mode
CI / Deploy / test (push) Successful in 1m4s
CI / Deploy / deploy (push) Skipped

Every slide gets an embed URL /e/{key}/{id} for presentation software
like Canva. The page goes live while it is visible, keeps itself live
with heartbeats and pauses when it disappears; stale embeds are paused
lazily. The embed key is separate from the admin token and only allows
showing, activating, pausing and voting controls of that slide.

Participants see a pause page while no slide is live. The presenter
can pause (P) and resume the paused slide with the arrow keys; the
dashboard has a pause button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:26:05 +01:00
1 parent 58145e9753
commit 07a292d109
19 files changed
+1116 -68

No files matched your search

+106 -14
View File
@@ -5,7 +5,8 @@
* - [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-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;
* with [data-embed]: one embedded slide (/e/{key}/{id}), goes live while visible
* - [data-participant] participant page, polls /p/{code}/state
* - [data-countdown] quiz timer (data-remaining = seconds), fires `plenario:timeup` on document
* - [data-quiz-options] slide form: "add answer" button for quiz slides
@@ -761,6 +762,13 @@
var controlUrl = root.getAttribute('data-control-url');
var interval = parseInt(root.getAttribute('data-interval'), 10) || 2000;
var q = function (selector) { return root.querySelector(selector); };
var embedded = root.hasAttribute('data-embed');
var setText = function (selector, text) {
var node = q(selector);
if (node) {
node.textContent = text;
}
};
var last = '';
var hideResults = false;
var state = null;
@@ -791,23 +799,32 @@
state = newState;
var slide = state.slide;
q('[data-counter]').textContent = state.count === 0
setText('[data-counter]', state.count === 0
? '0 / 0'
: (state.index === null ? '–' : state.index + 1) + ' / ' + state.count;
: (state.index === null ? (state.poll.isPaused ? '⏸' : '–') : state.index + 1) + ' / ' + state.count);
var pauseButton = q('[data-action="stop"]');
if (pauseButton) {
pauseButton.hidden = !slide;
}
if (embedded) {
renderLive();
}
if (!slide) {
q('[data-type]').textContent = '';
q('[data-type]').textContent = state.poll.isPaused ? 'Pause' : '';
q('[data-question]').textContent = state.count === 0
? 'Noch keine Folien angelegt'
: state.poll.title;
q('[data-description]').textContent = state.count === 0
? 'Lege in der Verwaltung Fragen an.'
: 'Drücke → um zu starten.';
: (state.poll.isPaused
? 'Teilnehmende sehen gerade eine Pause-Seite. Drücke → zum Fortsetzen.'
: 'Drücke → um zu starten.');
q('[data-results]').innerHTML = '';
renderMedia(null);
root.classList.remove('stage--video');
q('[data-voting]').hidden = true;
q('[data-participants]').textContent = '';
setText('[data-participants]', '');
return;
}
@@ -834,9 +851,9 @@
: (slide.isVotingOpen ? 'Abstimmung schließen' : 'Abstimmung öffnen'));
var count = qaStage ? state.results.questions.length : (slide.isInteractive ? state.results.participants : 0);
q('[data-participants]').textContent = !slide.isInteractive ? '' : (qaStage
setText('[data-participants]', !slide.isInteractive ? '' : (qaStage
? count + (count === 1 ? ' Frage' : ' Fragen')
: count + ' ' + (count === 1 ? 'Antwort' : 'Antworten'));
: count + ' ' + (count === 1 ? 'Antwort' : 'Antworten')));
var container = q('[data-results]');
container.classList.toggle('is-hidden', hideResults);
@@ -865,10 +882,70 @@
function toggleHide() {
hideResults = !hideResults;
q('[data-results]').classList.toggle('is-hidden', hideResults);
q('[data-hide-results] [data-label]').textContent = hideResults ? 'Ergebnisse zeigen' : 'Ergebnisse verbergen';
setText('[data-hide-results] [data-label]', hideResults ? 'Ergebnisse zeigen' : 'Ergebnisse verbergen');
}
q('[data-hide-results]').addEventListener('click', toggleHide);
/*
* Embed mode: the slide goes live while the embed is really on screen (tab visible and
* at least half of it in the viewport - IntersectionObserver also sees through the
* iframes of the surrounding presentation), stays live with heartbeats, pauses when gone.
*/
var live = false;
function renderLive() {
var isLive = !!state.isLive;
var indicator = q('[data-live]');
indicator.textContent = !state.poll.isActive
? 'Umfrage geschlossen'
: (isLive ? '● live' : 'nicht live');
indicator.classList.toggle('is-live', isLive);
q('[data-go-live]').hidden = isLive || !state.poll.isActive;
}
function goLive() {
live = true;
postJson(root.getAttribute('data-activate-url'), {}).then(render).catch(function () {});
}
function leave() {
if (!live) {
return;
}
live = false;
var url = root.getAttribute('data-pause-url');
// sendBeacon survives page unload; embed routes need no CSRF token.
if (!(navigator.sendBeacon && navigator.sendBeacon(url, new FormData()))) {
postJson(url, {}).catch(function () {});
}
}
if (embedded) {
var inView = false;
var check = function () {
if (inView && document.visibilityState === 'visible') {
if (!live) {
goLive();
}
} else {
leave();
}
};
if ('IntersectionObserver' in window) {
new IntersectionObserver(function (entries) {
inView = entries[entries.length - 1].intersectionRatio >= 0.5;
check();
}, { threshold: [0, 0.5, 1] }).observe(root);
} else {
inView = true;
check();
}
document.addEventListener('visibilitychange', check);
window.addEventListener('pagehide', leave);
q('[data-go-live]').addEventListener('click', goLive);
setInterval(function () {
if (live) {
postJson(root.getAttribute('data-heartbeat-url'), {}).then(render).catch(function () {});
}
}, parseInt(root.getAttribute('data-heartbeat'), 10) || 5000);
}
function toggleFullscreen() {
if (!document.fullscreenElement) {
(document.documentElement.requestFullscreen || function () {}).call(document.documentElement);
@@ -876,20 +953,33 @@
document.exitFullscreen();
}
}
q('[data-fullscreen]').addEventListener('click', toggleFullscreen);
if (q('[data-fullscreen]')) {
q('[data-fullscreen]').addEventListener('click', toggleFullscreen);
}
var overlay = q('[data-qr-overlay]');
function toggleQr() {
overlay.hidden = !overlay.hidden;
if (overlay) {
overlay.hidden = !overlay.hidden;
}
}
if (overlay) {
q('[data-qr-toggle]').addEventListener('click', toggleQr);
overlay.addEventListener('click', toggleQr);
}
q('[data-qr-toggle]').addEventListener('click', toggleQr);
overlay.addEventListener('click', toggleQr);
document.addEventListener('keydown', function (event) {
if (event.target.closest('input, textarea, select')) {
return;
}
if (embedded && ['ArrowRight', 'ArrowLeft', 'PageUp', 'PageDown', ' ', 'p', 'P', 'f', 'F', 'q', 'Q'].indexOf(event.key) >= 0) {
return; // slide navigation belongs to the surrounding presentation
}
switch (event.key) {
case 'p':
case 'P':
control('stop');
break;
case 'ArrowRight':
case 'PageDown':
case ' ':
@@ -926,7 +1016,9 @@
}
break;
case 'Escape':
overlay.hidden = true;
if (overlay) {
overlay.hidden = true;
}
break;
}
});