Add YouTube video slide type
Admins paste a YouTube link (watch, youtu.be, shorts, live, embed). The link is checked via oEmbed on save and with a "check link" button (not found / not embeddable is rejected, unreachable saves with a warning). Start time can be entered or is taken from the link's timecode; autoplay is optional. The presenter embeds the video via youtube-nocookie.com; participants get the link plus a share button (Web Share API, falls back to copying). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
93aeae1884
commit
1c509e31c2
14 files changed
+972
-24
No files matched your search
@@ -145,6 +145,7 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
|
||||
.badge--type-scale { background: #fdeed8; color: #9a5a00; }
|
||||
.badge--type-content { background: #e3eefb; color: #1f6bb0; }
|
||||
.badge--type-quiz { background: #f1e3fb; color: #7a2fb0; }
|
||||
.badge--type-youtube { background: #fde4e1; color: #b3261e; }
|
||||
|
||||
.message { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; cursor: pointer; background: var(--surface-2); border-left: 4px solid var(--muted); }
|
||||
.message.success { border-color: var(--ok); }
|
||||
@@ -225,6 +226,17 @@ textarea { resize: vertical; }
|
||||
.type-card--scale { border-top-color: var(--c3); }
|
||||
.type-card--content { border-top-color: var(--c4); }
|
||||
.type-card--quiz { border-top-color: var(--c5); }
|
||||
.type-card--youtube { border-top-color: #d93025; }
|
||||
|
||||
/* ---------------------------------------------------------------- slide form: youtube */
|
||||
.youtube-status { margin: 6px 0 0; font-size: .9rem; color: var(--muted); }
|
||||
.youtube-status:empty { display: none; }
|
||||
.youtube-status.is-ok { color: var(--ok); }
|
||||
.youtube-status.is-error { color: var(--danger); }
|
||||
.youtube-preview { margin: 0 0 16px; }
|
||||
.youtube-preview iframe, .stage__media iframe { display: block; width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 8px; background: #000; }
|
||||
.video-link { margin: 16px 0 12px; }
|
||||
.share-field input { min-width: 0; }
|
||||
|
||||
/* ---------------------------------------------------------------- slide form: quiz answers */
|
||||
.quiz-options { border: 0; padding: 0; margin: 0 0 16px; }
|
||||
@@ -390,6 +402,9 @@ body.present {
|
||||
.stage__type { text-transform: uppercase; letter-spacing: .12em; color: var(--c1); font-weight: 700; margin: 0 0 .6em; }
|
||||
.stage__question { font-size: clamp(2rem, 4.5vw, 4rem); margin-bottom: .3em; }
|
||||
.stage__description { font-size: clamp(1.1rem, 2vw, 1.6rem); color: var(--muted); white-space: pre-line; margin-top: 0; }
|
||||
.stage__media { width: min(100%, calc(62vh * 16 / 9)); margin: 1vh auto 0; }
|
||||
.stage--video .stage__question { font-size: clamp(1.5rem, 3vw, 2.6rem); }
|
||||
.stage--video .stage__description { font-size: clamp(1rem, 1.6vw, 1.3rem); }
|
||||
.stage--content .stage__description { color: var(--text); font-size: clamp(1.3rem, 2.6vw, 2.2rem); }
|
||||
.stage__results { font-size: clamp(1rem, 1.8vw, 1.5rem); margin-top: 2vh; }
|
||||
.stage--closed .stage__type::after { content: " · Abstimmung geschlossen"; color: var(--muted); }
|
||||
|
||||
+159
-17
@@ -3,6 +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-youtube-form] slide form: "Link prüfen" for YouTube slides (status + preview)
|
||||
* - [data-presenter] presenter screen, polls /admin/{token}/state
|
||||
* - [data-participant] participant page, polls /p/{code}/state
|
||||
* - [data-countdown] quiz timer (data-remaining = seconds), fires `plenario:timeup` on document
|
||||
@@ -501,32 +503,149 @@
|
||||
|
||||
// ------------------------------------------------------------------ copy
|
||||
|
||||
/** Copies the value of the [data-copy-source] next to `button` and confirms on the button. */
|
||||
function copyFrom(button) {
|
||||
var source = button.parentNode.querySelector('[data-copy-source]');
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
source.select();
|
||||
var done = function () {
|
||||
var label = button.textContent;
|
||||
button.textContent = 'Kopiert ✓';
|
||||
setTimeout(function () { button.textContent = label; }, 1500);
|
||||
};
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(source.value).then(done, function () {
|
||||
document.execCommand('copy');
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
document.execCommand('copy');
|
||||
done();
|
||||
}
|
||||
}
|
||||
|
||||
function initCopy() {
|
||||
document.querySelectorAll('[data-copy]').forEach(function (button) {
|
||||
button.addEventListener('click', function () { copyFrom(button); });
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ share
|
||||
|
||||
/**
|
||||
* [data-share]: native share sheet (smartphones) with data-share-url / data-share-title,
|
||||
* otherwise copies the sibling [data-copy-source]. Hidden without JS.
|
||||
*/
|
||||
function initShare() {
|
||||
document.querySelectorAll('[data-share]').forEach(function (button) {
|
||||
var canShare = typeof navigator.share === 'function';
|
||||
button.textContent = button.getAttribute(canShare ? 'data-label-share' : 'data-label-copy');
|
||||
button.hidden = false;
|
||||
button.addEventListener('click', function () {
|
||||
var source = button.parentNode.querySelector('[data-copy-source]');
|
||||
if (!source) {
|
||||
if (!canShare) {
|
||||
copyFrom(button);
|
||||
return;
|
||||
}
|
||||
source.select();
|
||||
var done = function () {
|
||||
var label = button.textContent;
|
||||
button.textContent = 'Kopiert ✓';
|
||||
setTimeout(function () { button.textContent = label; }, 1500);
|
||||
};
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(source.value).then(done, function () {
|
||||
document.execCommand('copy');
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
document.execCommand('copy');
|
||||
done();
|
||||
}
|
||||
navigator.share({
|
||||
title: button.getAttribute('data-share-title') || document.title,
|
||||
url: button.getAttribute('data-share-url')
|
||||
}).catch(function (error) {
|
||||
if (!error || error.name !== 'AbortError') {
|
||||
copyFrom(button);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ youtube
|
||||
|
||||
function youtubeFrame(src, title) {
|
||||
// The admin pages send no referrer at all; YouTube refuses to play without one.
|
||||
// strict-origin sends only the origin, never the path with the admin token.
|
||||
return el('iframe', {
|
||||
src: src,
|
||||
title: title,
|
||||
referrerpolicy: 'strict-origin',
|
||||
allow: 'autoplay; encrypted-media; picture-in-picture; fullscreen',
|
||||
allowfullscreen: ''
|
||||
});
|
||||
}
|
||||
|
||||
/** [data-youtube-form]: "Link prüfen" in the slide form, shows status + preview. */
|
||||
function initYouTubeForm(root) {
|
||||
var url = root.getAttribute('data-youtube-form');
|
||||
var input = root.querySelector('[data-youtube-url]');
|
||||
var start = root.querySelector('[data-youtube-start]');
|
||||
var startHint = root.querySelector('[data-youtube-start-hint]');
|
||||
var button = root.querySelector('[data-youtube-check]');
|
||||
var status = root.querySelector('[data-youtube-status]');
|
||||
var preview = root.querySelector('[data-youtube-preview]');
|
||||
var title = document.querySelector('[data-youtube-title]');
|
||||
var lastChecked = null;
|
||||
|
||||
function show(text, kind) {
|
||||
status.textContent = text;
|
||||
status.classList.toggle('is-ok', kind === 'ok');
|
||||
status.classList.toggle('is-error', kind === 'error');
|
||||
}
|
||||
|
||||
function check() {
|
||||
var value = input.value.trim();
|
||||
if (value === '') {
|
||||
show('Bitte gib einen YouTube-Link ein.', 'error');
|
||||
input.focus();
|
||||
return;
|
||||
}
|
||||
var key = value + '|' + start.value.trim();
|
||||
if (key === lastChecked) {
|
||||
return;
|
||||
}
|
||||
lastChecked = key;
|
||||
button.disabled = true;
|
||||
show('Link wird geprüft …');
|
||||
postJson(url, { url: value, start: start.value }).then(function (result) {
|
||||
var text = result.message;
|
||||
if (result.ok && result.linkStart && start.value.trim() === '') {
|
||||
text += ' Start bei ' + result.linkStart + ' (aus dem Link).';
|
||||
}
|
||||
show((result.ok ? '✓ ' : '') + text, result.ok ? 'ok' : 'error');
|
||||
input.setAttribute('aria-invalid', result.ok ? 'false' : 'true');
|
||||
preview.textContent = '';
|
||||
preview.hidden = !result.embedUrl;
|
||||
if (result.embedUrl) {
|
||||
preview.appendChild(youtubeFrame(result.embedUrl, 'Vorschau des Videos'));
|
||||
}
|
||||
if (result.ok && result.title && title && title.value.trim() === '') {
|
||||
title.value = result.title;
|
||||
}
|
||||
if (result.ok) {
|
||||
start.placeholder = result.linkStart || '0:00';
|
||||
if (startHint && result.linkStart) {
|
||||
startHint.textContent = 'Leer lassen, um beim Zeitpunkt aus dem Link (' + result.linkStart + ') zu starten.';
|
||||
}
|
||||
}
|
||||
}).catch(function () {
|
||||
lastChecked = null;
|
||||
show('Die Prüfung hat gerade nicht geklappt. Beim Speichern wird der Link erneut geprüft.', 'error');
|
||||
}).then(function () {
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
|
||||
button.hidden = false;
|
||||
button.addEventListener('click', check);
|
||||
input.addEventListener('change', check);
|
||||
input.addEventListener('paste', function () { setTimeout(check, 0); });
|
||||
start.addEventListener('change', function () {
|
||||
if (input.value.trim() !== '') {
|
||||
check();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ presenter
|
||||
|
||||
function initPresenter(root) {
|
||||
@@ -537,6 +656,23 @@
|
||||
var last = '';
|
||||
var hideResults = false;
|
||||
var state = null;
|
||||
var mediaKey = '';
|
||||
|
||||
/** Embeds the video of a YouTube slide; kept as is while the slide stays (no restart on polls). */
|
||||
function renderMedia(slide) {
|
||||
var media = q('[data-media]');
|
||||
var video = slide && slide.video ? slide.video : null;
|
||||
var key = video ? slide.id + '|' + video.embedUrl : '';
|
||||
if (key === mediaKey) {
|
||||
return;
|
||||
}
|
||||
mediaKey = key;
|
||||
media.textContent = '';
|
||||
media.hidden = !video;
|
||||
if (video) {
|
||||
media.appendChild(youtubeFrame(video.embedUrl, slide.question));
|
||||
}
|
||||
}
|
||||
|
||||
function render(newState) {
|
||||
var serialized = JSON.stringify(newState);
|
||||
@@ -560,6 +696,8 @@
|
||||
? 'Lege in der Verwaltung Fragen an.'
|
||||
: '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 = '';
|
||||
return;
|
||||
@@ -572,6 +710,8 @@
|
||||
q('[data-question]').textContent = slide.question;
|
||||
q('[data-description]').textContent = slide.description;
|
||||
root.classList.toggle('stage--content', !slide.isInteractive);
|
||||
root.classList.toggle('stage--video', slide.type === 'youtube');
|
||||
renderMedia(slide);
|
||||
root.classList.toggle('stage--closed', slide.isInteractive && !slide.isVotingOpen && !quizPhase);
|
||||
|
||||
var voting = q('[data-voting]');
|
||||
@@ -1102,6 +1242,8 @@
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
initCopy();
|
||||
initShare();
|
||||
document.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm);
|
||||
document.querySelectorAll('[data-presenter]').forEach(initPresenter);
|
||||
document.querySelectorAll('[data-participant]').forEach(initParticipant);
|
||||
document.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions);
|
||||
|
||||
Reference in new issue
Block a user