Add initial Plenario live polling app
CakePHP 5.4 app for live polls: create via email without login, manage via secret admin link, join via code. Includes slide types (choice, wordcloud, open, scale, content), presenter mode, CSV export, captcha, throttling, tests and Gitea CI/deploy workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
eb319f8c1e
120 files changed
+15572
No files matched your search
@@ -0,0 +1,5 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^ index.php [L]
|
||||
</IfModule>
|
||||
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Minified by jsDelivr using clean-css v4.2.1.
|
||||
* Original file: /npm/normalize.css@8.0.1/normalize.css
|
||||
*
|
||||
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
||||
*/
|
||||
/*! normalize.css v8.0.1 | MIT License | github.com/necolas/normalize.css */
|
||||
html{line-height:1.15;-webkit-text-size-adjust:100%}body{margin:0}main{display:block}h1{font-size:2em;margin:.67em 0}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}img{border-style:none}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{padding:.35em .75em .625em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details{display:block}summary{display:list-item}template{display:none}[hidden]{display:none}
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* Plenario stylesheet – no framework, no build step.
|
||||
* Sections: tokens · base · layout · components · forms · admin · participant · results · presenter
|
||||
*/
|
||||
|
||||
/* ---------------------------------------------------------------- tokens */
|
||||
:root {
|
||||
--bg: #f5f6fb;
|
||||
--surface: #ffffff;
|
||||
--surface-2: #eef0f8;
|
||||
--text: #1d1f33;
|
||||
--muted: #5d6280;
|
||||
--border: #dde0ee;
|
||||
--primary: #4b3fe0;
|
||||
--primary-ink: #ffffff;
|
||||
--primary-soft: #ebe9fd;
|
||||
--danger: #c42b4b;
|
||||
--ok: #18865a;
|
||||
--warn: #a86400;
|
||||
--radius: 12px;
|
||||
--shadow: 0 1px 2px rgba(20, 22, 50, .06), 0 4px 16px rgba(20, 22, 50, .05);
|
||||
--font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
|
||||
--c0: #4b3fe0;
|
||||
--c1: #e0457b;
|
||||
--c2: #12a08a;
|
||||
--c3: #f29a1f;
|
||||
--c4: #2f8fe0;
|
||||
--c5: #8e44c9;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root:not(.present) {
|
||||
--bg: #12131d;
|
||||
--surface: #1b1d2b;
|
||||
--surface-2: #24263a;
|
||||
--text: #eceefa;
|
||||
--muted: #a1a6c3;
|
||||
--border: #30334a;
|
||||
--primary: #7f75ff;
|
||||
--primary-soft: #2a2752;
|
||||
--shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- base */
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
|
||||
html { font-size: 16px; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: var(--font);
|
||||
line-height: 1.55;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
a { color: var(--primary); }
|
||||
a:hover { text-decoration-thickness: 2px; }
|
||||
|
||||
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
|
||||
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); }
|
||||
h2 { font-size: 1.25rem; }
|
||||
h3 { font-size: 1.05rem; margin-top: 1.6em; }
|
||||
|
||||
.muted { color: var(--muted); }
|
||||
.center { text-align: center; }
|
||||
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--primary); margin: 0 0 .4em; }
|
||||
.lead { font-size: 1.15rem; color: var(--muted); }
|
||||
.hint { font-size: .875rem; color: var(--muted); margin: .25em 0 1em; }
|
||||
.hint--error { color: var(--danger); }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
/* ---------------------------------------------------------------- layout */
|
||||
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 16px; }
|
||||
.main { padding-top: 32px; padding-bottom: 48px; min-height: calc(100vh - 140px); }
|
||||
|
||||
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
|
||||
.site-header__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; flex-wrap: wrap; }
|
||||
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; color: var(--text); text-decoration: none; }
|
||||
.brand__mark { width: 22px; height: 22px; border-radius: 6px; background: conic-gradient(var(--c0) 0 40%, var(--c1) 0 65%, var(--c2) 0 85%, var(--c3) 0); }
|
||||
.site-nav { display: flex; gap: 20px; font-size: .95rem; }
|
||||
.site-nav a { color: var(--muted); text-decoration: none; }
|
||||
.site-nav a:hover { color: var(--text); }
|
||||
.site-footer { padding: 24px 16px; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--border); }
|
||||
|
||||
.grid { display: grid; gap: 24px; }
|
||||
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
|
||||
.grid--tight { gap: 0 16px; }
|
||||
.grid--sidebar { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
|
||||
@media (max-width: 900px) {
|
||||
.grid--sidebar { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- components */
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 24px;
|
||||
box-shadow: var(--shadow);
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
.card--narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
|
||||
.card--form { max-width: 720px; }
|
||||
.card--accent { background: var(--primary-soft); border-color: transparent; }
|
||||
.card--danger h2 { color: var(--danger); }
|
||||
|
||||
.hero { text-align: center; max-width: 760px; margin: 16px auto 40px; }
|
||||
.hero h1 { font-size: clamp(1.9rem, 4.5vw, 3rem); }
|
||||
|
||||
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-top: 16px; }
|
||||
.features div { padding: 16px; border-radius: var(--radius); background: var(--surface-2); }
|
||||
.features strong { display: block; }
|
||||
.features span { color: var(--muted); font-size: .9rem; }
|
||||
|
||||
.button {
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 6px;
|
||||
padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border);
|
||||
background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
|
||||
text-decoration: none; cursor: pointer; line-height: 1.2; white-space: nowrap;
|
||||
}
|
||||
.button:hover { border-color: var(--primary); }
|
||||
.button:disabled { opacity: .6; cursor: wait; }
|
||||
.button--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
|
||||
.button--primary:hover { filter: brightness(1.08); }
|
||||
.button--danger { color: var(--danger); }
|
||||
.button--danger:hover { border-color: var(--danger); }
|
||||
.button--ghost { border-color: transparent; background: transparent; }
|
||||
.button--small { padding: 6px 10px; font-size: .85rem; }
|
||||
.button--icon { min-width: 32px; }
|
||||
.button--block { width: 100%; padding: 14px; font-size: 1.05rem; }
|
||||
|
||||
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
|
||||
.badge--ok { background: #dff5ea; color: var(--ok); }
|
||||
.badge--off { background: #fbe3e8; color: var(--danger); }
|
||||
.badge--live { background: var(--c1); color: #fff; }
|
||||
.badge--type-choice { background: #e9e7ff; color: #3a2fc4; }
|
||||
.badge--type-wordcloud { background: #fde4ee; color: #b12a5d; }
|
||||
.badge--type-open { background: #dcf5f0; color: #0b7766; }
|
||||
.badge--type-scale { background: #fdeed8; color: #9a5a00; }
|
||||
.badge--type-content { background: #e3eefb; color: #1f6bb0; }
|
||||
|
||||
.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); }
|
||||
.message.error { border-color: var(--danger); }
|
||||
.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; } }
|
||||
|
||||
.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); }
|
||||
.empty { padding: 24px; border: 2px dashed var(--border); border-radius: var(--radius); color: var(--muted); text-align: center; }
|
||||
|
||||
/* ---------------------------------------------------------------- forms */
|
||||
form .input { margin-bottom: 16px; }
|
||||
form .input label { display: block; font-weight: 600; margin-bottom: 6px; }
|
||||
form .input.checkbox label { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
|
||||
form .input.checkbox input { margin-top: 5px; }
|
||||
|
||||
input[type=text], input[type=email], input[type=number], input[type=url], select, textarea {
|
||||
width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
|
||||
background: var(--surface); color: var(--text); font: inherit;
|
||||
}
|
||||
input:focus, select:focus, textarea:focus, .button:focus-visible { outline: 3px solid var(--primary-soft); border-color: var(--primary); }
|
||||
textarea { resize: vertical; }
|
||||
.input-short { max-width: 160px; }
|
||||
.input-code { text-transform: uppercase; letter-spacing: .15em; font-weight: 700; }
|
||||
.input-code--big { font-size: 2rem; text-align: center; padding: 16px; }
|
||||
.error-message { color: var(--danger); font-size: .875rem; margin-top: 4px; }
|
||||
.input.error input, .input.error textarea { border-color: var(--danger); }
|
||||
.form-actions { display: flex; gap: 12px; margin-top: 8px; }
|
||||
|
||||
/* ---------------------------------------------------------------- admin */
|
||||
.admin-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
|
||||
.admin-head h1 { margin-bottom: .2em; word-break: break-word; }
|
||||
.admin-head__actions { display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
|
||||
.slide-list { list-style: none; padding: 0; margin: 0 0 16px; }
|
||||
.slide-item {
|
||||
display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 16px; align-items: center;
|
||||
background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
|
||||
padding: 14px 16px; margin-bottom: 10px;
|
||||
}
|
||||
.slide-item--current { border-color: var(--c1); box-shadow: 0 0 0 2px rgba(224, 69, 123, .15); }
|
||||
.slide-item__pos { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-weight: 700; }
|
||||
.slide-item__meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; margin-bottom: 4px; }
|
||||
.slide-item__title { font-weight: 600; color: var(--text); text-decoration: none; word-break: break-word; }
|
||||
.slide-item__options { margin: 4px 0 0; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.slide-item__actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
|
||||
@media (max-width: 700px) {
|
||||
.slide-item { grid-template-columns: 32px minmax(0, 1fr); }
|
||||
.slide-item__actions { grid-column: 1 / -1; justify-content: flex-start; }
|
||||
}
|
||||
|
||||
.type-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
|
||||
.type-card { display: block; padding: 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); border-top: 4px solid var(--c0); }
|
||||
.type-card:hover { border-color: var(--primary); }
|
||||
.type-card strong { display: block; }
|
||||
.type-card span { font-size: .85rem; color: var(--muted); }
|
||||
.type-card--wordcloud { border-top-color: var(--c1); }
|
||||
.type-card--open { border-top-color: var(--c2); }
|
||||
.type-card--scale { border-top-color: var(--c3); }
|
||||
.type-card--content { border-top-color: var(--c4); }
|
||||
|
||||
.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; }
|
||||
.copy-field { display: flex; gap: 8px; }
|
||||
.copy-field input { font-size: .85rem; }
|
||||
|
||||
/* ---------------------------------------------------------------- participant */
|
||||
.participant .main { max-width: 640px; }
|
||||
.participant .site-nav { display: none; }
|
||||
.question { font-size: 1.5rem; }
|
||||
.choices { display: grid; gap: 10px; margin: 16px 0 20px; }
|
||||
.choice { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border: 2px solid var(--border); border-radius: 10px; cursor: pointer; font-weight: 500; }
|
||||
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.choice input { width: 20px; height: 20px; accent-color: var(--primary); }
|
||||
.word-input { margin-bottom: 10px; }
|
||||
.word-entry .word-input { margin-bottom: 0; }
|
||||
/* In the flow (not absolute) so it pushes message and button down instead of covering them. */
|
||||
.suggestions { margin: 4px 0 0; padding: 4px; max-height: 50vh; overflow-y: auto; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); }
|
||||
.suggestion { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
|
||||
.suggestion:hover, .suggestion.is-active { background: var(--primary-soft); }
|
||||
.suggestion.is-mine { cursor: default; opacity: .6; }
|
||||
.suggestion__text { font-weight: 600; word-break: break-word; }
|
||||
.suggestion__meta { font-size: .8rem; color: var(--muted); white-space: nowrap; align-self: center; }
|
||||
.word-message { min-height: 1.4em; margin: 8px 0 0; font-size: .9rem; color: var(--ok); }
|
||||
.word-message.is-error { color: var(--danger); }
|
||||
.vote-form textarea { margin: 12px 0 16px; }
|
||||
.vote-form .button { margin-top: 12px; }
|
||||
.scale { display: flex; gap: 6px; margin: 20px 0 6px; }
|
||||
.scale__step { flex: 1; }
|
||||
.scale__step input { position: absolute; opacity: 0; }
|
||||
.scale__step span { display: block; text-align: center; padding: 14px 0; border: 2px solid var(--border); border-radius: 8px; font-weight: 700; cursor: pointer; }
|
||||
.scale__step input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
|
||||
.scale__step input:focus-visible + span { outline: 3px solid var(--primary-soft); }
|
||||
.scale__labels { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
|
||||
.done { font-size: 1.1rem; font-weight: 600; color: var(--ok); }
|
||||
.waiting { padding: 48px 24px; }
|
||||
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); margin: 0 auto 24px; animation: pulse 1.6s infinite; }
|
||||
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(75, 63, 224, .5); } 100% { box-shadow: 0 0 0 24px rgba(75, 63, 224, 0); } }
|
||||
.prose { font-size: 1.1rem; }
|
||||
|
||||
/* ---------------------------------------------------------------- results (shared) */
|
||||
.results-empty { color: var(--muted); font-style: italic; }
|
||||
.is-hidden { visibility: hidden; }
|
||||
|
||||
.bars { display: grid; gap: 14px; }
|
||||
.bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label value" "track track"; gap: 4px 12px; }
|
||||
.bar__label { grid-area: label; font-weight: 600; word-break: break-word; }
|
||||
.bar__value { grid-area: value; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.bar__track { grid-area: track; height: 14px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
|
||||
.bar__fill { height: 100%; border-radius: 99px; background: var(--c0); transition: width .6s ease; min-width: 2px; }
|
||||
.bar--c1 .bar__fill { background: var(--c1); }
|
||||
.bar--c2 .bar__fill { background: var(--c2); }
|
||||
.bar--c3 .bar__fill { background: var(--c3); }
|
||||
.bar--c4 .bar__fill { background: var(--c4); }
|
||||
.bar--c5 .bar__fill { background: var(--c5); }
|
||||
|
||||
.columns { display: flex; gap: 8px; align-items: stretch; height: 180px; }
|
||||
.column { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
|
||||
.column__count { font-size: .85rem; color: var(--muted); }
|
||||
.column__track { flex: 1; width: 100%; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
|
||||
.column__fill { width: 100%; background: var(--c3); transition: height .6s ease; }
|
||||
.column__label { font-weight: 700; }
|
||||
.average { font-size: 1.1rem; margin: 0 0 12px; }
|
||||
.average strong { font-size: 1.6em; }
|
||||
|
||||
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; }
|
||||
.cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; }
|
||||
.cloud__word--c1 { color: var(--c1); }
|
||||
.cloud__word--c2 { color: var(--c2); }
|
||||
.cloud__word--c3 { color: var(--c3); }
|
||||
.cloud__word--c4 { color: var(--c4); }
|
||||
.cloud__word--c5 { color: var(--c5); }
|
||||
.cloud__word { display: inline-flex; align-items: baseline; gap: .25em; }
|
||||
.cloud__count { font-size: max(.75rem, .4em); font-weight: 600; color: var(--muted); white-space: nowrap; }
|
||||
.cloud__count--up { color: var(--ok); }
|
||||
.cloud__count--down { color: var(--danger); }
|
||||
.stage .cloud__count { font-size: max(.9rem, .4em); }
|
||||
/* Participant cloud: word (+) and − are separate buttons */
|
||||
.cloud--interactive .cloud__word { gap: .1em; }
|
||||
.cloud__vote { font: inherit; font-weight: inherit; color: inherit; line-height: 1.15; background: none; border: 2px solid transparent; border-radius: 10px; padding: .05em .3em; cursor: pointer; display: inline-flex; align-items: baseline; gap: .25em; }
|
||||
.cloud__vote:hover:not(:disabled), .cloud__vote:focus-visible { border-color: currentColor; }
|
||||
.cloud__vote:disabled { cursor: default; }
|
||||
.cloud__vote--down { padding: .05em .25em; }
|
||||
.cloud__word.is-mine .cloud__vote--up, .cloud__word.is-down .cloud__vote--down { background: var(--surface-2); }
|
||||
.cloud__word.is-down .cloud__vote--up { opacity: .55; }
|
||||
|
||||
.answers { list-style: none; padding: 0; margin: 0; columns: 280px; column-gap: 12px; }
|
||||
.answer { break-inside: avoid; background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; word-break: break-word; }
|
||||
|
||||
/* ---------------------------------------------------------------- presenter */
|
||||
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);
|
||||
color: var(--text);
|
||||
overflow: hidden;
|
||||
}
|
||||
.stage { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; padding: 20px 4vw; }
|
||||
.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__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; }
|
||||
.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--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); }
|
||||
.stage .bar__track { height: 1.1em; }
|
||||
.stage .columns { height: 34vh; }
|
||||
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
|
||||
.stage .answers { columns: 340px; }
|
||||
|
||||
.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-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 img { width: min(70vh, 80vw); height: auto; background: #fff; border-radius: 16px; padding: 16px; }
|
||||
.qr-overlay p { font-size: 1.4rem; }
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* The Front Controller for handling every request
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
|
||||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
||||
* @link https://cakephp.org CakePHP(tm) Project
|
||||
* @since 0.2.9
|
||||
* @license MIT License (https://opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
|
||||
// For built-in server
|
||||
if (PHP_SAPI === 'cli-server') {
|
||||
$_SERVER['PHP_SELF'] = '/' . basename(__FILE__);
|
||||
|
||||
$url = parse_url(urldecode($_SERVER['REQUEST_URI']));
|
||||
$file = __DIR__ . $url['path'];
|
||||
if (!str_contains($url['path'], '..') && str_contains($url['path'], '.') && is_file($file)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use App\Application;
|
||||
use Cake\Http\Server;
|
||||
|
||||
// Bind your application to the server.
|
||||
$server = new Server(new Application(dirname(__DIR__) . '/config'));
|
||||
|
||||
// Run the request/response through the application and emit the response.
|
||||
$server->emit($server->run());
|
||||
Whitespace-only changes.
@@ -0,0 +1,780 @@
|
||||
/**
|
||||
* Plenario frontend – plain JavaScript, no build step, no dependencies.
|
||||
*
|
||||
* Modules (auto-initialised by data attributes):
|
||||
* - [data-copy] copy the value of the sibling [data-copy-source]
|
||||
* - [data-presenter] presenter screen, polls /admin/{token}/state
|
||||
* - [data-participant] participant page, polls /p/{code}/state
|
||||
*
|
||||
* Results JSON shape: see src/Service/ResultsService.php
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ------------------------------------------------------------------ helpers
|
||||
|
||||
function el(tag, attrs, children) {
|
||||
var node = document.createElement(tag);
|
||||
Object.keys(attrs || {}).forEach(function (key) {
|
||||
if (key === 'text') {
|
||||
node.textContent = attrs[key];
|
||||
} else if (key === 'style') {
|
||||
node.setAttribute('style', attrs[key]);
|
||||
} else {
|
||||
node.setAttribute(key, attrs[key]);
|
||||
}
|
||||
});
|
||||
(children || []).forEach(function (child) {
|
||||
if (child) {
|
||||
node.appendChild(child);
|
||||
}
|
||||
});
|
||||
return node;
|
||||
}
|
||||
|
||||
function csrfToken() {
|
||||
var meta = document.querySelector('meta[name="csrf-token"]');
|
||||
return meta ? meta.getAttribute('content') : '';
|
||||
}
|
||||
|
||||
function getJson(url) {
|
||||
return fetch(url, {
|
||||
headers: { Accept: 'application/json' },
|
||||
credentials: 'same-origin',
|
||||
cache: 'no-store'
|
||||
}).then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error('HTTP ' + response.status);
|
||||
}
|
||||
return response.json();
|
||||
});
|
||||
}
|
||||
|
||||
function postJson(url, data) {
|
||||
var body = new FormData();
|
||||
Object.keys(data).forEach(function (key) {
|
||||
body.append(key, data[key]);
|
||||
});
|
||||
return fetch(url, {
|
||||
method: 'POST',
|
||||
body: body,
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'X-CSRF-Token': csrfToken()
|
||||
}
|
||||
}).then(function (response) {
|
||||
if (!response.ok) {
|
||||
throw new Error('HTTP ' + response.status);
|
||||
}
|
||||
return response.json();
|
||||
});
|
||||
}
|
||||
|
||||
/** Polls `fn` every `interval` ms, pauses while the tab is hidden. */
|
||||
function poll(fn, interval) {
|
||||
var timer = null;
|
||||
function tick() {
|
||||
Promise.resolve(fn()).catch(function () { /* retry next tick */ }).then(schedule);
|
||||
}
|
||||
function schedule() {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(tick, document.hidden ? interval * 5 : interval);
|
||||
}
|
||||
document.addEventListener('visibilitychange', function () {
|
||||
if (!document.hidden) {
|
||||
tick();
|
||||
}
|
||||
});
|
||||
tick();
|
||||
return { now: tick };
|
||||
}
|
||||
|
||||
function formatNumber(value) {
|
||||
return Number(value).toLocaleString('de-DE');
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ word matching
|
||||
|
||||
/**
|
||||
* Suggestions for the word cloud input: prefix/substring matches, small
|
||||
* typos (Levenshtein) and similar sounding words (Kölner Phonetik).
|
||||
*/
|
||||
var Words = {
|
||||
/** Lower case, umlauts folded, accents and non-alphanumerics removed. */
|
||||
fold: function (text) {
|
||||
return String(text).toLowerCase()
|
||||
.replace(/ä/g, 'ae').replace(/ö/g, 'oe').replace(/ü/g, 'ue').replace(/ß/g, 'ss')
|
||||
.normalize('NFD').replace(/[̀-ͯ]/g, '')
|
||||
.replace(/[^a-z0-9]/g, '');
|
||||
},
|
||||
|
||||
/** Kölner Phonetik – phonetic code for German words. */
|
||||
phonetic: function (text) {
|
||||
var s = String(text).toUpperCase()
|
||||
.replace(/Ä/g, 'A').replace(/Ö/g, 'O').replace(/Ü/g, 'U').replace(/ß/g, 'S')
|
||||
.normalize('NFD').replace(/[̀-ͯ]/g, '')
|
||||
.replace(/[^A-Z]/g, '');
|
||||
var codes = '';
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
var c = s[i];
|
||||
var prev = i > 0 ? s[i - 1] : '';
|
||||
var next = s[i + 1] || '';
|
||||
var code = '';
|
||||
if ('AEIJOUY'.indexOf(c) >= 0) {
|
||||
code = '0';
|
||||
} else if (c === 'B') {
|
||||
code = '1';
|
||||
} else if (c === 'P') {
|
||||
code = next === 'H' ? '3' : '1';
|
||||
} else if (c === 'D' || c === 'T') {
|
||||
code = next && 'CSZ'.indexOf(next) >= 0 ? '8' : '2';
|
||||
} else if ('FVW'.indexOf(c) >= 0) {
|
||||
code = '3';
|
||||
} else if ('GKQ'.indexOf(c) >= 0) {
|
||||
code = '4';
|
||||
} else if (c === 'C') {
|
||||
if (i === 0) {
|
||||
code = next && 'AHKLOQRUX'.indexOf(next) >= 0 ? '4' : '8';
|
||||
} else {
|
||||
code = next && 'AHKOQUX'.indexOf(next) >= 0 && 'SZ'.indexOf(prev) < 0 ? '4' : '8';
|
||||
}
|
||||
} else if (c === 'X') {
|
||||
code = prev && 'CKQ'.indexOf(prev) >= 0 ? '8' : '48';
|
||||
} else if (c === 'L') {
|
||||
code = '5';
|
||||
} else if (c === 'M' || c === 'N') {
|
||||
code = '6';
|
||||
} else if (c === 'R') {
|
||||
code = '7';
|
||||
} else if (c === 'S' || c === 'Z') {
|
||||
code = '8';
|
||||
}
|
||||
// H and anything else: no code
|
||||
codes += code;
|
||||
}
|
||||
var collapsed = '';
|
||||
for (var j = 0; j < codes.length; j++) {
|
||||
if (codes[j] !== collapsed[collapsed.length - 1]) {
|
||||
collapsed += codes[j];
|
||||
}
|
||||
}
|
||||
return collapsed.charAt(0) + collapsed.slice(1).replace(/0/g, '');
|
||||
},
|
||||
|
||||
levenshtein: function (a, b) {
|
||||
if (a === b) {
|
||||
return 0;
|
||||
}
|
||||
var row = [];
|
||||
for (var j = 0; j <= b.length; j++) {
|
||||
row.push(j);
|
||||
}
|
||||
for (var i = 1; i <= a.length; i++) {
|
||||
var diag = row[0];
|
||||
row[0] = i;
|
||||
for (var k = 1; k <= b.length; k++) {
|
||||
var tmp = row[k];
|
||||
row[k] = Math.min(row[k] + 1, row[k - 1] + 1, diag + (a[i - 1] === b[k - 1] ? 0 : 1));
|
||||
diag = tmp;
|
||||
}
|
||||
}
|
||||
return row[b.length];
|
||||
},
|
||||
|
||||
/** Score 0 (no match) .. 100 (same word). */
|
||||
score: function (input, word) {
|
||||
var a = Words.fold(input);
|
||||
var b = Words.fold(word);
|
||||
if (!a || !b) {
|
||||
return 0;
|
||||
}
|
||||
if (a === b) {
|
||||
return 100;
|
||||
}
|
||||
if (b.indexOf(a) === 0) {
|
||||
return 90 - Math.min(20, b.length - a.length);
|
||||
}
|
||||
var pa = Words.phonetic(input);
|
||||
var pb = Words.phonetic(word);
|
||||
if (a.length >= 3 && pa && pa === pb) {
|
||||
return 70;
|
||||
}
|
||||
var tolerance = a.length >= 8 ? 2 : (a.length >= 4 ? 1 : 0);
|
||||
if (tolerance && Words.levenshtein(a, b) <= tolerance) {
|
||||
return 65;
|
||||
}
|
||||
if (a.length >= 3 && b.indexOf(a) > 0) {
|
||||
return 60;
|
||||
}
|
||||
// Typo within what has been typed so far ("Kafe" → "Kaffeemaschine").
|
||||
if (tolerance && b.length > a.length && Words.levenshtein(a, b.slice(0, a.length)) <= tolerance) {
|
||||
return 50;
|
||||
}
|
||||
if (a.length >= 4 && pa.length >= 3 && pb.indexOf(pa) === 0) {
|
||||
return 45;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
/** Matching existing cloud words ({key, text, count}) for an input, best first; optional limit. */
|
||||
suggest: function (input, words, limit) {
|
||||
if (Words.fold(input).length < 2) {
|
||||
return [];
|
||||
}
|
||||
return words
|
||||
.map(function (word) { return { word: word, score: Words.score(input, word.text) }; })
|
||||
.filter(function (item) { return item.score > 0; })
|
||||
.sort(function (x, y) { return y.score - x.score || y.word.count - x.word.count; })
|
||||
.slice(0, limit || undefined)
|
||||
.map(function (item) { return item.word; });
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------ results
|
||||
|
||||
var Results = {
|
||||
/**
|
||||
* @param {Object} [options] renderer specific; wordcloud: {mine: [keys], onUpvote: fn(word)|null}
|
||||
*/
|
||||
render: function (container, results, options) {
|
||||
container.innerHTML = '';
|
||||
if (!results) {
|
||||
return;
|
||||
}
|
||||
var renderer = Results[results.type];
|
||||
if (typeof renderer !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (results.participants === 0) {
|
||||
container.appendChild(el('p', { class: 'results-empty', text: 'Noch keine Antworten' }));
|
||||
return;
|
||||
}
|
||||
container.appendChild(renderer(results, options || {}));
|
||||
},
|
||||
|
||||
choice: function (results) {
|
||||
var max = Math.max.apply(null, results.options.map(function (o) { return o.count; }).concat([1]));
|
||||
return el('div', { class: 'bars' }, results.options.map(function (option, index) {
|
||||
return el('div', { class: 'bar bar--c' + (index % 6) }, [
|
||||
el('div', { class: 'bar__label', text: option.label }),
|
||||
el('div', { class: 'bar__track' }, [
|
||||
el('div', { class: 'bar__fill', style: 'width:' + (option.count / max * 100) + '%' })
|
||||
]),
|
||||
el('div', { class: 'bar__value', text: formatNumber(option.percent) + ' % (' + option.count + ')' })
|
||||
]);
|
||||
}));
|
||||
},
|
||||
|
||||
scale: function (results) {
|
||||
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
|
||||
var columns = el('div', { class: 'columns' }, results.buckets.map(function (bucket) {
|
||||
return el('div', { class: 'column' }, [
|
||||
el('div', { class: 'column__count', text: String(bucket.count) }),
|
||||
el('div', { class: 'column__track' }, [
|
||||
el('div', { class: 'column__fill', style: 'height:' + (bucket.count / max * 100) + '%' })
|
||||
]),
|
||||
el('div', { class: 'column__label', text: String(bucket.value) })
|
||||
]);
|
||||
}));
|
||||
var labels = el('div', { class: 'scale__labels' }, [
|
||||
el('span', { text: results.minLabel || '' }),
|
||||
el('span', { text: results.maxLabel || '' })
|
||||
]);
|
||||
var average = el('p', { class: 'average' }, [
|
||||
el('span', { text: 'Durchschnitt ' }),
|
||||
el('strong', { text: results.average === null ? '–' : formatNumber(results.average) })
|
||||
]);
|
||||
return el('div', { class: 'scale-results' }, [average, columns, labels]);
|
||||
},
|
||||
|
||||
/**
|
||||
* options: {mine: [keys], down: [keys], onUpvote: fn(word)|null, onDownvote: fn(word)|null}
|
||||
* Counts are shown as "+up" and "−down" (down only when > 0 or clickable).
|
||||
*/
|
||||
wordcloud: function (results, options) {
|
||||
var mine = (options && options.mine) || [];
|
||||
var down = (options && options.down) || [];
|
||||
var onUpvote = options && options.onUpvote;
|
||||
var onDownvote = options && options.onDownvote;
|
||||
// Interleave big and small words so the biggest ends up in the middle.
|
||||
var words = results.words.slice();
|
||||
var ordered = [];
|
||||
words.forEach(function (word, index) {
|
||||
if (index % 2 === 0) {
|
||||
ordered.push(word);
|
||||
} else {
|
||||
ordered.unshift(word);
|
||||
}
|
||||
});
|
||||
return el('div', { class: 'cloud' + (onUpvote ? ' cloud--interactive' : '') }, ordered.map(function (word, index) {
|
||||
var size = 0.9 + word.weight * 2.6;
|
||||
var isMine = mine.indexOf(word.key) >= 0;
|
||||
var isDown = down.indexOf(word.key) >= 0;
|
||||
var rated = isMine || isDown;
|
||||
var downCount = word.down || 0;
|
||||
var attrs = {
|
||||
class: 'cloud__word cloud__word--c' + (index % 6) + (isMine ? ' is-mine' : '') + (isDown ? ' is-down' : ''),
|
||||
style: 'font-size:' + size.toFixed(2) + 'em',
|
||||
title: '+' + word.count + ' / −' + downCount
|
||||
+ (isMine ? ' – von dir genannt' : (isDown ? ' – von dir abgelehnt' : ''))
|
||||
};
|
||||
if (!onUpvote) {
|
||||
// Presenter (and participants without upvotes): show the counts next to the word.
|
||||
return el('span', attrs, [
|
||||
el('span', { text: word.text }),
|
||||
el('span', { class: 'cloud__count cloud__count--up', text: '+' + word.count }),
|
||||
downCount > 0 ? el('span', { class: 'cloud__count cloud__count--down', text: '−' + downCount }) : null
|
||||
]);
|
||||
}
|
||||
|
||||
var up = el('button', {
|
||||
type: 'button',
|
||||
class: 'cloud__vote cloud__vote--up',
|
||||
'aria-pressed': isMine ? 'true' : 'false',
|
||||
'aria-label': word.text + ', ' + word.count + ' Stimmen'
|
||||
+ (isMine ? ', von dir genannt' : (isDown ? '' : ', unterstützen'))
|
||||
}, [
|
||||
el('span', { text: word.text }),
|
||||
el('span', { class: 'cloud__count cloud__count--up', 'aria-hidden': 'true', text: (isMine ? '✓ ' : '+') + word.count })
|
||||
]);
|
||||
up.disabled = rated;
|
||||
if (!rated) {
|
||||
up.addEventListener('click', function () { onUpvote(word); });
|
||||
}
|
||||
|
||||
var downEl = null;
|
||||
if (onDownvote) {
|
||||
downEl = el('button', {
|
||||
type: 'button',
|
||||
class: 'cloud__vote cloud__vote--down',
|
||||
'aria-pressed': isDown ? 'true' : 'false',
|
||||
'aria-label': word.text + ', ' + downCount + ' Ablehnungen'
|
||||
+ (isDown ? ', von dir abgelehnt' : (isMine ? '' : ', ablehnen'))
|
||||
}, [
|
||||
el('span', { class: 'cloud__count cloud__count--down', 'aria-hidden': 'true', text: (isDown ? '✓ ' : '') + '−' + downCount })
|
||||
]);
|
||||
downEl.disabled = rated;
|
||||
if (!rated) {
|
||||
downEl.addEventListener('click', function () { onDownvote(word); });
|
||||
}
|
||||
} else if (downCount > 0) {
|
||||
downEl = el('span', { class: 'cloud__count cloud__count--down', text: '−' + downCount });
|
||||
}
|
||||
return el('span', attrs, [up, downEl]);
|
||||
}));
|
||||
},
|
||||
|
||||
open: function (results) {
|
||||
return el('ul', { class: 'answers' }, results.answers.map(function (answer) {
|
||||
return el('li', { class: 'answer', text: answer.text });
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------ copy
|
||||
|
||||
function initCopy() {
|
||||
document.querySelectorAll('[data-copy]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ presenter
|
||||
|
||||
function initPresenter(root) {
|
||||
var stateUrl = root.getAttribute('data-state-url');
|
||||
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 last = '';
|
||||
var hideResults = false;
|
||||
var state = null;
|
||||
|
||||
function render(newState) {
|
||||
var serialized = JSON.stringify(newState);
|
||||
if (serialized === last) {
|
||||
return;
|
||||
}
|
||||
last = serialized;
|
||||
state = newState;
|
||||
var slide = state.slide;
|
||||
|
||||
q('[data-counter]').textContent = state.count === 0
|
||||
? '0 / 0'
|
||||
: (state.index === null ? '–' : state.index + 1) + ' / ' + state.count;
|
||||
|
||||
if (!slide) {
|
||||
q('[data-type]').textContent = '';
|
||||
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.';
|
||||
q('[data-results]').innerHTML = '';
|
||||
q('[data-voting]').hidden = true;
|
||||
q('[data-participants]').textContent = '';
|
||||
return;
|
||||
}
|
||||
|
||||
q('[data-type]').textContent = slide.typeLabel;
|
||||
q('[data-question]').textContent = slide.question;
|
||||
q('[data-description]').textContent = slide.description;
|
||||
root.classList.toggle('stage--content', !slide.isInteractive);
|
||||
root.classList.toggle('stage--closed', slide.isInteractive && !slide.isVotingOpen);
|
||||
|
||||
var voting = q('[data-voting]');
|
||||
voting.hidden = !slide.isInteractive;
|
||||
voting.textContent = slide.isVotingOpen ? 'Abstimmung schließen' : 'Abstimmung öffnen';
|
||||
|
||||
q('[data-participants]').textContent = slide.isInteractive
|
||||
? state.results.participants + ' ' + (state.results.participants === 1 ? 'Antwort' : 'Antworten')
|
||||
: '';
|
||||
|
||||
var container = q('[data-results]');
|
||||
container.classList.toggle('is-hidden', hideResults);
|
||||
Results.render(container, slide.isInteractive ? state.results : null);
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
return getJson(stateUrl).then(render);
|
||||
}
|
||||
|
||||
function control(action, extra) {
|
||||
var data = Object.assign({ action: action }, extra || {});
|
||||
return postJson(controlUrl, data).then(render).catch(function () { /* next poll fixes it */ });
|
||||
}
|
||||
|
||||
root.querySelectorAll('[data-action]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
control(button.getAttribute('data-action'));
|
||||
});
|
||||
});
|
||||
|
||||
function toggleHide() {
|
||||
hideResults = !hideResults;
|
||||
q('[data-results]').classList.toggle('is-hidden', hideResults);
|
||||
q('[data-hide-results]').textContent = hideResults ? 'Ergebnisse zeigen' : 'Ergebnisse verbergen';
|
||||
}
|
||||
q('[data-hide-results]').addEventListener('click', toggleHide);
|
||||
|
||||
function toggleFullscreen() {
|
||||
if (!document.fullscreenElement) {
|
||||
(document.documentElement.requestFullscreen || function () {}).call(document.documentElement);
|
||||
} else if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
q('[data-fullscreen]').addEventListener('click', toggleFullscreen);
|
||||
|
||||
var overlay = q('[data-qr-overlay]');
|
||||
function toggleQr() {
|
||||
overlay.hidden = !overlay.hidden;
|
||||
}
|
||||
q('[data-qr-toggle]').addEventListener('click', toggleQr);
|
||||
overlay.addEventListener('click', toggleQr);
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
if (event.target.closest('input, textarea, select')) {
|
||||
return;
|
||||
}
|
||||
switch (event.key) {
|
||||
case 'ArrowRight':
|
||||
case 'PageDown':
|
||||
case ' ':
|
||||
event.preventDefault();
|
||||
control('next');
|
||||
break;
|
||||
case 'ArrowLeft':
|
||||
case 'PageUp':
|
||||
event.preventDefault();
|
||||
control('prev');
|
||||
break;
|
||||
case 'v':
|
||||
case 'V':
|
||||
if (state && state.slide && state.slide.isInteractive) {
|
||||
control('toggle');
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
toggleHide();
|
||||
break;
|
||||
case 'f':
|
||||
case 'F':
|
||||
toggleFullscreen();
|
||||
break;
|
||||
case 'q':
|
||||
case 'Q':
|
||||
toggleQr();
|
||||
break;
|
||||
case 'Escape':
|
||||
overlay.hidden = true;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
poll(refresh, interval);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ participant
|
||||
|
||||
function initParticipant(root) {
|
||||
var stateUrl = root.getAttribute('data-state-url');
|
||||
var voteUrl = root.getAttribute('data-vote-url');
|
||||
var version = root.getAttribute('data-version');
|
||||
var interval = parseInt(root.getAttribute('data-interval'), 10) || 2000;
|
||||
var card = root.querySelector('[data-results-card]');
|
||||
var container = root.querySelector('[data-results]');
|
||||
var wordForm = root.querySelector('[data-word-form]');
|
||||
var current = null;
|
||||
var lastRendered = '';
|
||||
|
||||
function canUpvote(state) {
|
||||
return !!(wordForm && state.words && state.words.allowUpvotes
|
||||
&& state.isVotingOpen && !state.words.limitReached);
|
||||
}
|
||||
|
||||
function renderResults(state) {
|
||||
current = state;
|
||||
if (!card || !container) {
|
||||
return;
|
||||
}
|
||||
var upvote = canUpvote(state);
|
||||
var key = JSON.stringify([state.results, state.words, upvote]);
|
||||
if (key === lastRendered) {
|
||||
return;
|
||||
}
|
||||
lastRendered = key;
|
||||
card.hidden = !state.results;
|
||||
var hint = root.querySelector('[data-upvote-hint]');
|
||||
if (hint) {
|
||||
hint.hidden = !upvote;
|
||||
}
|
||||
Results.render(container, state.results, {
|
||||
mine: state.words ? state.words.mine : [],
|
||||
down: state.words ? state.words.down : [],
|
||||
onUpvote: upvote ? function (word) { sendWord(word.text); } : null,
|
||||
onDownvote: upvote && state.words.allowDownvotes ? function (word) { sendWord(word.text, 'down'); } : null
|
||||
});
|
||||
}
|
||||
|
||||
// --- word cloud: one word per submit, suggestions, upvotes ----------
|
||||
var input = wordForm ? wordForm.querySelector('[data-word-input]') : null;
|
||||
var list = wordForm ? wordForm.querySelector('[data-suggestions]') : null;
|
||||
var message = wordForm ? wordForm.querySelector('[data-word-message]') : null;
|
||||
var matches = [];
|
||||
var activeIndex = -1;
|
||||
var sending = false;
|
||||
|
||||
function isMine(word) {
|
||||
return !!(current && current.words && current.words.mine.indexOf(word.key) >= 0);
|
||||
}
|
||||
|
||||
function isDown(word) {
|
||||
return !!(current && current.words && current.words.down.indexOf(word.key) >= 0);
|
||||
}
|
||||
|
||||
function sendWord(text, vote) {
|
||||
if (!wordForm || sending) {
|
||||
return;
|
||||
}
|
||||
sending = true;
|
||||
var slideId = wordForm.querySelector('[name=slide_id]').value;
|
||||
var data = { slide_id: slideId, word: text };
|
||||
if (vote === 'down') {
|
||||
data.vote = 'down';
|
||||
}
|
||||
postJson(voteUrl, data).then(function (response) {
|
||||
var success = vote === 'down' ? '✓ „' + text + '“ abgelehnt.' : '✓ „' + text + '“ ist angekommen.';
|
||||
message.textContent = response.ok ? success : response.message;
|
||||
message.classList.toggle('is-error', !response.ok);
|
||||
if (response.ok && vote !== 'down') {
|
||||
input.value = '';
|
||||
closeSuggestions();
|
||||
}
|
||||
applyWordState(response.state);
|
||||
}).catch(function () {
|
||||
message.textContent = 'Das hat nicht geklappt. Bitte versuche es noch einmal.';
|
||||
message.classList.add('is-error');
|
||||
}).then(function () {
|
||||
sending = false;
|
||||
});
|
||||
}
|
||||
|
||||
function applyWordState(state) {
|
||||
if (state.version !== version || !state.words) {
|
||||
// Limit reached, slide changed or voting closed.
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
var remaining = wordForm.querySelector('[data-words-remaining]');
|
||||
if (state.words.remaining === null) {
|
||||
remaining.textContent = 'Du kannst beliebig viele Begriffe abgeben.';
|
||||
} else {
|
||||
remaining.textContent = state.words.remaining === 1
|
||||
? 'Du kannst noch einen Begriff abgeben.'
|
||||
: 'Du kannst noch ' + state.words.remaining + ' Begriffe abgeben.';
|
||||
}
|
||||
renderResults(state);
|
||||
}
|
||||
|
||||
function closeSuggestions() {
|
||||
matches = [];
|
||||
activeIndex = -1;
|
||||
list.hidden = true;
|
||||
list.textContent = '';
|
||||
input.setAttribute('aria-expanded', 'false');
|
||||
input.removeAttribute('aria-activedescendant');
|
||||
}
|
||||
|
||||
function highlight(index) {
|
||||
var items = list.querySelectorAll('[role=option]');
|
||||
activeIndex = items.length ? (index + items.length) % items.length : -1;
|
||||
items.forEach(function (item, i) {
|
||||
item.classList.toggle('is-active', i === activeIndex);
|
||||
item.setAttribute('aria-selected', i === activeIndex ? 'true' : 'false');
|
||||
});
|
||||
if (activeIndex >= 0) {
|
||||
input.setAttribute('aria-activedescendant', items[activeIndex].id);
|
||||
items[activeIndex].scrollIntoView({ block: 'nearest' });
|
||||
}
|
||||
}
|
||||
|
||||
function pick(word) {
|
||||
if (isMine(word) || isDown(word)) {
|
||||
return;
|
||||
}
|
||||
input.value = word.text;
|
||||
closeSuggestions();
|
||||
sendWord(word.text);
|
||||
}
|
||||
|
||||
function updateSuggestions() {
|
||||
var words = current && current.results && current.results.words ? current.results.words : [];
|
||||
var found = Words.suggest(input.value, words);
|
||||
closeSuggestions();
|
||||
if (!found.length) {
|
||||
return;
|
||||
}
|
||||
matches = found;
|
||||
found.forEach(function (word, i) {
|
||||
var mine = isMine(word);
|
||||
var rejected = isDown(word);
|
||||
var item = el('li', {
|
||||
id: 'word-suggestion-' + i,
|
||||
role: 'option',
|
||||
class: 'suggestion' + (mine || rejected ? ' is-mine' : ''),
|
||||
'aria-selected': 'false',
|
||||
'aria-disabled': mine || rejected ? 'true' : 'false'
|
||||
}, [
|
||||
el('span', { class: 'suggestion__text', text: word.text }),
|
||||
el('span', {
|
||||
class: 'suggestion__meta',
|
||||
text: mine ? 'schon genannt' : (rejected ? 'von dir abgelehnt' : '+' + word.count + ' · unterstützen')
|
||||
})
|
||||
]);
|
||||
item.addEventListener('mousedown', function (event) {
|
||||
event.preventDefault(); // keep focus in the input
|
||||
pick(word);
|
||||
});
|
||||
list.appendChild(item);
|
||||
});
|
||||
list.hidden = false;
|
||||
input.setAttribute('aria-expanded', 'true');
|
||||
}
|
||||
|
||||
if (wordForm && input && list) {
|
||||
wordForm.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
var text = input.value.trim();
|
||||
if (text) {
|
||||
sendWord(text);
|
||||
}
|
||||
});
|
||||
input.addEventListener('input', updateSuggestions);
|
||||
input.addEventListener('blur', function () { setTimeout(closeSuggestions, 150); });
|
||||
input.addEventListener('keydown', function (event) {
|
||||
if (list.hidden) {
|
||||
return;
|
||||
}
|
||||
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
||||
event.preventDefault();
|
||||
highlight(activeIndex + (event.key === 'ArrowDown' ? 1 : -1));
|
||||
} else if (event.key === 'Enter' && activeIndex >= 0) {
|
||||
event.preventDefault();
|
||||
pick(matches[activeIndex]);
|
||||
} else if (event.key === 'Escape') {
|
||||
closeSuggestions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var initial = root.querySelector('[data-initial-state]');
|
||||
if (initial) {
|
||||
try {
|
||||
renderResults(JSON.parse(initial.textContent));
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
poll(function () {
|
||||
return getJson(stateUrl).then(function (state) {
|
||||
if (state.version !== version) {
|
||||
// Do not destroy what the participant is typing right now.
|
||||
var typing = document.activeElement && document.activeElement.closest('.vote-form textarea, .vote-form input[type=text]');
|
||||
if (typing && typing.value && state.isVotingOpen && String(state.slideId) === String(root.querySelector('[name=slide_id]').value)) {
|
||||
return;
|
||||
}
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
renderResults(state);
|
||||
});
|
||||
}, interval);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ boot
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
initCopy();
|
||||
document.querySelectorAll('[data-presenter]').forEach(initPresenter);
|
||||
document.querySelectorAll('[data-participant]').forEach(initParticipant);
|
||||
|
||||
// Prevent double submits of vote forms.
|
||||
document.querySelectorAll('.vote-form').forEach(function (form) {
|
||||
form.addEventListener('submit', function (event) {
|
||||
if (event.defaultPrevented) {
|
||||
return; // handled via fetch (word cloud)
|
||||
}
|
||||
var button = form.querySelector('button[type=submit], button:not([type])');
|
||||
if (button) {
|
||||
setTimeout(function () { button.disabled = true; }, 0);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
window.Plenario = { Results: Results, Words: Words };
|
||||
})();
|
||||
Reference in new issue
Block a user