Add light/dark theme switch
CI / Deploy / test (push) Successful in 46s
CI / Deploy / deploy (push) Skipped

Theme follows the system by default; the header switch cycles
auto/light/dark and is stored per browser. The presenter has its own
switch (T), dark by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 16:15:14 +01:00
1 parent f0c6687100
commit 58145e9753
9 files changed
+187 -18

No files matched your search

+8 -1
View File
@@ -68,7 +68,7 @@ src/
YouTubeService YouTube-Links/Timecodes parsen, Watch-/Embed-URLs, Prüfung per oEmbed (Http\Client)
QaService Q&A: Phasen wechseln, Fragen nach Upvotes ranken, Fokus beim Besprechen
templates/ Deutsche UI, Layouts: default, present (Vollbild, dunkel), error, email
webroot/css/plenario.css Eigenes CSS, kein Framework
webroot/css/plenario.css Eigenes CSS, kein Framework; Farben nur als Tokens (Hell/Dunkel, siehe Theme unten)
webroot/js/plenario.js Vanilla JS: Polling, Ergebnis-Rendering, Presenter-Steuerung, Folien-Sortierung (Pointer Events + Pfeiltasten)
tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures sind leer
```
@@ -147,6 +147,13 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
7. Tests in `tests/TestCase/Service/VoteServiceTest.php` (Quiz: `QuizTest.php`, Q&A: `QaTest.php`)
8. Nach neuen Spalten lokal `bin/cake cache clear_all`, sonst nutzt das ORM das alte Schema aus dem Cache
### Farbschema (Tag/Nacht)
`data-theme="light|dark"` auf `<html>`, ohne Attribut gilt die Systemeinstellung. `element/theme_init` setzt die
Wahl aus `localStorage` vor dem ersten Rendern (Inline-Skript im `<head>`), `element/theme_switch` ist der Schalter
(`Theme` in `plenario.js`). Presenter: eigener Schlüssel `plenario-theme-present`, Standard dunkel, Taste T.
Neue Farben als Token in beiden Dark-Blöcken von `plenario.css` pflegen; auf der Bühne Overlays mit `rgba(var(--tint), …)`.
### Live-Updates
Kein WebSocket: Presenter (`/admin/{token}/state`) und Teilnehmende (`/p/{code}/state`) pollen per `fetch`
+7 -1
View File
@@ -3,7 +3,7 @@
* Presenter screen. Rendered empty and filled by webroot/js/plenario.js
* (Plenario.presenter) from /admin/{token}/state.
*
* Keyboard: ←/→ slides, V voting on/off, H hide results, F fullscreen, Q QR code.
* Keyboard: ←/→ slides, V voting on/off, H hide results, F fullscreen, Q QR code, T light/dark.
* Q&A slides: V switches to the next stage; while discussing ←/→ step through the questions first.
*
* @var \App\View\AppView $this
@@ -57,6 +57,12 @@ $host = preg_replace('#^https?://#', '', $joinBaseUrl);
<span data-label><?= __('Ergebnisse verbergen') ?></span> <kbd class="ctrl__key" aria-hidden="true">[H]</kbd>
</button>
<span class="ctrl-counter" data-participants></span>
<?= $this->element('theme_switch', [
'key' => 'plenario-theme-present',
'modes' => 'dark,light',
'class' => 'ctrl ctrl--wide',
'shortcut' => 'T',
]) ?>
<button type="button" class="ctrl" data-fullscreen aria-keyshortcuts="F" title="<?= __('Vollbild (F)') ?>">
<span aria-hidden="true">⛶</span><span class="sr-only"><?= __('Vollbild') ?></span>
<kbd class="ctrl__key" aria-hidden="true">[F]</kbd>
+24
View File
@@ -0,0 +1,24 @@
<?php
/**
* Applies the stored colour scheme before first paint (no flash of the wrong theme).
* Must be included in <head>. The theme switch (element theme_switch, webroot/js/plenario.js
* `Theme`) writes the same localStorage key.
*
* @var \App\View\AppView $this
* @var string $key localStorage key (presenter uses its own, the beamer is not the laptop)
* @var string $fallback Theme without stored choice: '' = follow the system, 'dark' or 'light'
*/
$key ??= 'plenario-theme';
$fallback ??= '';
?>
<script>
(function () {
var theme = <?= json_encode($fallback) ?>;
try {
theme = localStorage.getItem(<?= json_encode($key) ?>) || theme;
} catch (e) {}
if (theme === 'light' || theme === 'dark') {
document.documentElement.setAttribute('data-theme', theme);
}
})();
</script>
+25
View File
@@ -0,0 +1,25 @@
<?php
/**
* Button that cycles the colour scheme (wired up by webroot/js/plenario.js `Theme`).
* Without JavaScript it stays hidden, the system setting applies.
*
* @var \App\View\AppView $this
* @var string $key localStorage key, same as in element theme_init
* @var string $modes Comma separated cycle order of auto|light|dark
* @var string $class CSS class of the button
*/
$key ??= 'plenario-theme';
$modes ??= 'auto,light,dark';
$class ??= 'theme-switch';
?>
<button type="button" class="<?= h($class) ?>" data-theme-switch hidden
data-theme-key="<?= h($key) ?>" data-theme-modes="<?= h($modes) ?>"
data-label-auto="<?= __('Automatisch') ?>" data-label-light="<?= __('Hell') ?>" data-label-dark="<?= __('Dunkel') ?>"
data-label-prefix="<?= __('Farbschema') ?>" data-label-next="<?= __('wechseln zu') ?>"
<?= !empty($shortcut) ? 'aria-keyshortcuts="' . h($shortcut) . '"' : '' ?>>
<span class="theme-switch__icon" aria-hidden="true" data-theme-icon></span>
<span data-theme-label></span>
<?php if (!empty($shortcut)) : ?>
<kbd class="ctrl__key" aria-hidden="true">[<?= h($shortcut) ?>]</kbd>
<?php endif; ?>
</button>
+2
View File
@@ -16,6 +16,7 @@ $title = $this->fetch('title');
<meta name="robots" content="noindex, nofollow">
<?php endif; ?>
<title><?= $title ? h($title) . ' · ' : '' ?>Plenario</title>
<?= $this->element('theme_init') ?>
<?= $this->Html->meta('icon') ?>
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
<?= $this->fetch('meta') ?>
@@ -31,6 +32,7 @@ $title = $this->fetch('title');
<a href="<?= $this->Url->build(['_name' => 'join']) ?>"><?= __('Teilnehmen') ?></a>
<a href="<?= $this->Url->build(['_name' => 'recover']) ?>"><?= __('Admin-Link verloren?') ?></a>
</nav>
<?= $this->element('theme_switch') ?>
</div>
</header>
<main class="container main">
+1
View File
@@ -12,6 +12,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex">
<title><?= h($this->fetch('title')) ?> · Plenario</title>
<?= $this->element('theme_init') ?>
<?= $this->Html->meta('icon') ?>
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
</head>
+2 -1
View File
@@ -1,6 +1,6 @@
<?php
/**
* Full screen presenter layout (dark, no navigation).
* Full screen presenter layout (dark by default, own theme switch in the controls, no navigation).
*
* @var \App\View\AppView $this
*/
@@ -13,6 +13,7 @@
<meta name="robots" content="noindex, nofollow">
<meta name="csrf-token" content="<?= h((string)$this->request->getAttribute('csrfToken')) ?>">
<title><?= h($this->fetch('title')) ?> · Plenario</title>
<?= $this->element('theme_init', ['key' => 'plenario-theme-present', 'fallback' => 'dark']) ?>
<?= $this->Html->meta('icon') ?>
<?= $this->Html->css(['normalize.min', 'plenario']) ?>
</head>
+60 -15
View File
@@ -28,10 +28,33 @@
--c4: #2f8fe0;
--c5: #8e44c9;
--qa: #1f6bb0; /* Q&A accent, AA contrast with white text */
--notice-bg: #fff6e0;
--notice-ink: #6b4a00;
color-scheme: light;
}
/*
* Theme: data-theme="light|dark" on <html> (set by the theme switch, stored per browser),
* without it the system setting decides. Keep both dark blocks in sync.
*/
:root[data-theme="dark"] {
--bg: #12131d;
--surface: #1b1d2b;
--surface-2: #24263a;
--text: #eceefa;
--muted: #a1a6c3;
--border: #30334a;
--primary: #7f75ff;
--primary-soft: #2a2752;
--qa: #7cc4ff;
--shadow: none;
--notice-bg: #3a2f12;
--notice-ink: #f3d98f;
color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
:root:not(.present) {
:root:not([data-theme="light"]) {
--bg: #12131d;
--surface: #1b1d2b;
--surface-2: #24263a;
@@ -42,6 +65,9 @@
--primary-soft: #2a2752;
--qa: #7cc4ff;
--shadow: none;
--notice-bg: #3a2f12;
--notice-ink: #f3d98f;
color-scheme: dark;
}
}
@@ -156,8 +182,7 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
.message.warning { border-color: var(--warn); }
.message.hidden { display: none; }
.notice { padding: 12px 16px; border-radius: 8px; background: #fff6e0; color: #6b4a00; margin-bottom: 24px; font-size: .95rem; }
@media (prefers-color-scheme: dark) { .notice { background: #3a2f12; color: #f3d98f; } }
.notice { padding: 12px 16px; border-radius: 8px; background: var(--notice-bg); color: var(--notice-ink); margin-bottom: 24px; font-size: .95rem; }
.devnote { margin-top: 24px; padding: 16px; border: 2px dashed var(--warn); border-radius: var(--radius); }
.icon-circle { width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 50%; display: grid; place-items: center; font-size: 28px; background: var(--primary-soft); color: var(--primary); }
@@ -427,19 +452,34 @@ button.qa-steps__step:hover:not(:disabled) { color: var(--text); border-color: v
.qa-steps .is-current .qa-steps__step { background: var(--qa); border-color: var(--qa); color: var(--surface); font-weight: 700; cursor: default; }
/* ---------------------------------------------------------------- presenter */
/* Dark by default (beamer); the presenter's own switch can make it light (data-theme="light"). */
body.present {
--bg: #0f1020;
--surface-2: #1f2140;
--text: #f3f4ff;
--muted: #a3a7cf;
background: radial-gradient(1200px 600px at 10% -10%, #2a1f6e 0%, transparent 60%), var(--bg);
--tint: 255, 255, 255; /* overlays on the stage: rgba(var(--tint), alpha) */
--stage-glow: #2a1f6e;
--stage-ok: #3ddc97; /* brighter green for contrast on the dark stage */
--overlay-bg: rgba(8, 9, 20, .92);
background: radial-gradient(1200px 600px at 10% -10%, var(--stage-glow) 0%, transparent 60%), var(--bg);
color: var(--text);
overflow: hidden;
}
.stage { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; padding: 20px 4vw; }
:root[data-theme="light"] body.present {
--bg: #f5f6fb;
--surface-2: #e4e7f4;
--text: #1d1f33;
--muted: #4f5473;
--tint: 20, 22, 50;
--stage-glow: #dcd8ff;
--stage-ok: var(--ok);
--overlay-bg: rgba(245, 246, 251, .95);
}
.stage__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: clamp(1rem, 1.6vw, 1.4rem); color: var(--muted); }
.stage__top strong { color: var(--text); }
.stage__code { letter-spacing: .12em; background: rgba(255, 255, 255, .1); padding: 2px 10px; border-radius: 8px; }
.stage__code { letter-spacing: .12em; background: rgba(var(--tint), .1); padding: 2px 10px; border-radius: 8px; }
.stage__qr { border: 0; padding: 4px; background: #fff; border-radius: 8px; cursor: zoom-in; }
.stage__qr img { display: block; width: 72px; height: 72px; }
.stage__main { display: flex; flex-direction: column; justify-content: center; min-height: 0; overflow: auto; padding: 2vh 0; }
@@ -454,7 +494,7 @@ body.present {
.stage--closed .stage__type::after { content: " · Abstimmung geschlossen"; color: var(--muted); }
.stage .bar__track { height: 1.1em; }
.stage .columns { height: 34vh; }
.stage .average { padding: 2vh 2.5vw; gap: 2vh 4vw; background: rgba(255, 255, 255, .06); }
.stage .average { padding: 2vh 2.5vw; gap: 2vh 4vw; background: rgba(var(--tint), .06); }
.stage .average__value strong { font-size: clamp(4rem, 9vw, 8rem); }
.stage .average__of { font-size: clamp(1.6rem, 3vw, 2.8rem); }
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.9rem, 1.4vw, 1.3rem); }
@@ -463,15 +503,15 @@ body.present {
.stage .answers { columns: 340px; }
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
.stage .quiz-tile { font-size: clamp(1.2rem, 2.2vw, 2rem); }
/* brighter green for contrast on the dark stage */
.stage .quiz-summary strong, .stage .bar--correct .bar__label { color: #3ddc97; }
.stage .bar--correct .bar__fill { background: #3ddc97; }
.stage .quiz-summary strong, .stage .bar--correct .bar__label { color: var(--stage-ok); }
.stage .bar--correct .bar__fill { background: var(--stage-ok); }
.stage .qa-steps { font-size: .7em; }
.stage .qa-steps__step { border-color: rgba(255, 255, 255, .25); }
.stage .qa-item { background: rgba(255, 255, 255, .06); }
.stage .qa-steps__step { border-color: rgba(var(--tint), .25); }
.stage .qa-item { background: rgba(var(--tint), .06); }
.stage { --qa: #7cc4ff; }
:root[data-theme="light"] .stage { --qa: #1f6bb0; }
.stage .qa-steps .is-current .qa-steps__step { color: var(--bg); }
.stage .qa-focus { background: rgba(255, 255, 255, .08); padding: 3vh 3vw; }
.stage .qa-focus { background: rgba(var(--tint), .08); padding: 3vh 3vw; }
.stage .qa-focus__meta { font-size: .7em; }
.stage .qa-focus__text { font-size: clamp(1.8rem, 3.6vw, 3.2rem); line-height: 1.2; }
.stage .qa-list--compact { font-size: .75em; }
@@ -479,8 +519,8 @@ body.present {
.stage__controls { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; opacity: .35; transition: opacity .2s; padding-top: 12px; }
.stage__controls:hover, .stage__controls:focus-within { opacity: 1; }
.ctrl { min-width: 44px; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .06); color: var(--text); font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ctrl:hover { background: rgba(255, 255, 255, .15); }
.ctrl { min-width: 44px; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid rgba(var(--tint), .2); background: rgba(var(--tint), .06); color: var(--text); font: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.ctrl:hover { background: rgba(var(--tint), .15); }
.ctrl { gap: 6px; }
/* Visible keyboard shortcuts – nobody hovers for tooltips during a talk. */
.ctrl__key { font: inherit; font-size: .8em; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
@@ -492,6 +532,11 @@ body.present {
}
.ctrl-counter { color: var(--muted); min-width: 64px; text-align: center; font-variant-numeric: tabular-nums; }
.qr-overlay { position: fixed; inset: 0; background: rgba(8, 9, 20, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; cursor: zoom-out; z-index: 10; }
.qr-overlay { position: fixed; inset: 0; background: var(--overlay-bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; cursor: zoom-out; z-index: 10; }
.qr-overlay img { width: min(70vh, 80vw); height: auto; background: #fff; border-radius: 16px; padding: 16px; }
.qr-overlay p { font-size: 1.4rem; }
/* ---------------------------------------------------------------- theme switch */
.theme-switch { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; }
.theme-switch:hover { border-color: var(--primary); }
.theme-switch__icon { font-size: 1.05em; line-height: 1; }
+58
View File
@@ -10,6 +10,8 @@
* - [data-countdown] quiz timer (data-remaining = seconds), fires `plenario:timeup` on document
* - [data-quiz-options] slide form: "add answer" button for quiz slides
* - [data-sortable] admin slide list: drag & drop / arrow keys via [data-drag-handle], POSTs ids[] to the URL
* - [data-theme-switch] cycles the colour scheme (data-theme on <html>, stored in localStorage),
* see templates/element/theme_init.php for the pre-paint part
*
* Results JSON shape: see src/Service/ResultsService.php
*/
@@ -917,11 +919,18 @@
case 'Q':
toggleQr();
break;
case 't':
case 'T':
if (themeSwitch) {
themeSwitch.click();
}
break;
case 'Escape':
overlay.hidden = true;
break;
}
});
var themeSwitch = q('[data-theme-switch]');
var poller = poll(refresh, interval);
document.addEventListener('plenario:timeup', function () {
@@ -1523,9 +1532,58 @@
}
}
// ------------------------------------------------------------------ theme switch
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
function initThemeSwitch(button) {
var key = button.getAttribute('data-theme-key');
var modes = button.getAttribute('data-theme-modes').split(',');
var root = document.documentElement;
function current() {
var theme = root.getAttribute('data-theme') || 'auto';
return modes.indexOf(theme) >= 0 ? theme : modes[0];
}
function label(mode) {
return button.getAttribute('data-label-' + mode);
}
function render() {
var mode = current();
var next = modes[(modes.indexOf(mode) + 1) % modes.length];
button.querySelector('[data-theme-icon]').textContent = THEME_ICONS[mode];
button.querySelector('[data-theme-label]').textContent = label(mode);
var text = button.getAttribute('data-label-prefix') + ': ' + label(mode) + ', '
+ button.getAttribute('data-label-next') + ' ' + label(next);
button.setAttribute('aria-label', text);
button.title = text + (button.hasAttribute('aria-keyshortcuts') ? ' (' + button.getAttribute('aria-keyshortcuts') + ')' : '');
}
button.addEventListener('click', function () {
var next = modes[(modes.indexOf(current()) + 1) % modes.length];
if (next === 'auto') {
root.removeAttribute('data-theme');
} else {
root.setAttribute('data-theme', next);
}
try {
localStorage.setItem(key, next);
} catch (e) {
// private mode: the choice just lasts until reload
}
render();
});
render();
button.hidden = false;
}
// ------------------------------------------------------------------ boot
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch);
initCopy();
initShare();
document.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm);