Add Q&A slide type
Participants submit questions, upvote them and the presenter discusses them one by one, most upvoted first. - Stages collect -> vote -> discuss, switched manually by the presenter (V key or stepper, going back is possible) - Configurable upvote budget per participant, freely distributable (several upvotes on one question are allowed), votes can be withdrawn - Participants see all questions while collecting to avoid duplicates; no counts before the discussion - While discussing, next/prev step through the questions before moving to the next slide - Migration: slides.stage, slides.focus_response_id, responses.parent_id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ea944b080f
commit
f0c6687100
21 files changed
+1327
-27
No files matched your search
@@ -27,6 +27,7 @@
|
||||
--c3: #f29a1f;
|
||||
--c4: #2f8fe0;
|
||||
--c5: #8e44c9;
|
||||
--qa: #1f6bb0; /* Q&A accent, AA contrast with white text */
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
@@ -39,6 +40,7 @@
|
||||
--border: #30334a;
|
||||
--primary: #7f75ff;
|
||||
--primary-soft: #2a2752;
|
||||
--qa: #7cc4ff;
|
||||
--shadow: none;
|
||||
}
|
||||
}
|
||||
@@ -146,6 +148,7 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
|
||||
.badge--type-content { background: #e3eefb; color: #1f6bb0; }
|
||||
.badge--type-quiz { background: #f1e3fb; color: #7a2fb0; }
|
||||
.badge--type-youtube { background: #fde4e1; color: #b3261e; }
|
||||
.badge--type-qa { background: #dff1fb; color: #0b5f8a; }
|
||||
|
||||
.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); }
|
||||
@@ -227,6 +230,7 @@ textarea { resize: vertical; }
|
||||
.type-card--content { border-top-color: var(--c4); }
|
||||
.type-card--quiz { border-top-color: var(--c5); }
|
||||
.type-card--youtube { border-top-color: #d93025; }
|
||||
.type-card--qa { border-top-color: #0b8bc9; }
|
||||
|
||||
/* ---------------------------------------------------------------- slide form: youtube */
|
||||
.youtube-status { margin: 6px 0 0; font-size: .9rem; color: var(--muted); }
|
||||
@@ -382,6 +386,46 @@ textarea { resize: vertical; }
|
||||
.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; }
|
||||
|
||||
/* Q&A (participants + presenter) */
|
||||
.qa-form__label { display: block; font-weight: 600; margin-bottom: 6px; }
|
||||
.qa-message { min-height: 1.4em; margin: 8px 0; font-size: .9rem; color: var(--ok); }
|
||||
.qa-message.is-error { color: var(--danger); }
|
||||
.qa-heading { font-size: 1rem; margin: 16px 0 8px; }
|
||||
.qa-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
|
||||
.qa-item { position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); overflow: hidden; }
|
||||
.qa-item__text { flex: 1; min-width: 0; word-break: break-word; position: relative; }
|
||||
.qa-item__bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--qa); border-radius: 0 4px 4px 0; transition: width .6s ease; }
|
||||
.qa-item.is-mine { border-left: 4px solid var(--qa); }
|
||||
.qa-item.is-upvoted { box-shadow: inset 0 0 0 2px var(--qa); }
|
||||
.qa-item.is-done { opacity: .55; }
|
||||
.qa-item.is-current { box-shadow: inset 0 0 0 2px var(--c1); }
|
||||
.qa-votes { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--qa); position: relative; }
|
||||
.qa-own { font-size: .85rem; color: var(--muted); white-space: nowrap; }
|
||||
.qa-stepper { flex: none; display: inline-flex; align-items: center; gap: 6px; }
|
||||
.qa-stepper__count { min-width: 3.2em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
|
||||
.qa-stepper.is-active .qa-stepper__count { color: var(--qa); }
|
||||
.qa-upvote { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 2px solid var(--qa); background: var(--surface); color: var(--qa); font: inherit; font-size: 1.3rem; font-weight: 700; line-height: 1; cursor: pointer; }
|
||||
.qa-upvote--up { background: var(--qa); color: var(--surface); }
|
||||
.qa-upvote:disabled { opacity: .45; cursor: not-allowed; }
|
||||
.qa-upvote:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
|
||||
.qa-budget { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 12px; }
|
||||
.qa-budget strong { font-size: 1.4rem; color: var(--qa); }
|
||||
.qa-budget__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--qa); }
|
||||
.qa-budget__dot.is-used { background: transparent; box-shadow: inset 0 0 0 2px var(--border); }
|
||||
.qa-budget__dot:first-of-type { margin-left: 6px; }
|
||||
.qa-focus { padding: 16px 18px; margin: 0 0 16px; border-radius: 14px; background: var(--surface-2); border-left: 6px solid var(--c1); }
|
||||
.qa-focus__meta { display: flex; gap: 16px; justify-content: space-between; margin: 0 0 6px; font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
|
||||
.qa-focus__text { margin: 0; font-size: 1.3rem; font-weight: 700; word-break: break-word; }
|
||||
.qa-focus__nav { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
|
||||
.qa-focus__nav:empty { display: none; }
|
||||
.qa-list--compact .qa-item { padding: 8px 12px; }
|
||||
.qa-summary { color: var(--muted); margin: 0 0 1em; }
|
||||
.qa-steps { list-style: none; padding: 0; margin: 0 0 1em; display: flex; flex-wrap: wrap; gap: 6px; counter-reset: none; }
|
||||
.qa-steps__step { display: inline-block; padding: 4px 12px; border-radius: 99px; border: 1px solid var(--border); background: transparent; color: var(--muted); font: inherit; font-size: .85em; }
|
||||
button.qa-steps__step { cursor: pointer; }
|
||||
button.qa-steps__step:hover:not(:disabled) { color: var(--text); border-color: var(--text); }
|
||||
.qa-steps .is-current .qa-steps__step { background: var(--qa); border-color: var(--qa); color: var(--surface); font-weight: 700; cursor: default; }
|
||||
|
||||
/* ---------------------------------------------------------------- presenter */
|
||||
body.present {
|
||||
--bg: #0f1020;
|
||||
@@ -422,6 +466,16 @@ body.present {
|
||||
/* 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 .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: #7cc4ff; }
|
||||
.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__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; }
|
||||
.stage--qa .stage__question { font-size: clamp(1.5rem, 3vw, 2.6rem); }
|
||||
|
||||
.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; }
|
||||
|
||||
+294
-9
@@ -300,7 +300,8 @@
|
||||
return;
|
||||
}
|
||||
// A quiz shows its answer options even before anyone has answered.
|
||||
if (results.participants === 0 && !(results.type === 'quiz' && !results.revealed)) {
|
||||
// A Q&A slide always shows its stages.
|
||||
if (results.participants === 0 && results.type !== 'qa' && !(results.type === 'quiz' && !results.revealed)) {
|
||||
container.appendChild(el('p', { class: 'results-empty', text: 'Noch keine Antworten' }));
|
||||
return;
|
||||
}
|
||||
@@ -498,6 +499,111 @@
|
||||
return el('ul', { class: 'answers' }, results.answers.map(function (answer) {
|
||||
return el('li', { class: 'answer', text: answer.text });
|
||||
}));
|
||||
},
|
||||
|
||||
/**
|
||||
* Presenter view of a Q&A slide: stage stepper, then per stage the
|
||||
* collected questions, the live ranking or the question being discussed.
|
||||
* options: {onStage: fn(stage)|null, onQuestion: fn(step)|null}
|
||||
*/
|
||||
qa: function (results, options) {
|
||||
var onStage = options && options.onStage;
|
||||
var onQuestion = options && options.onQuestion;
|
||||
var questions = results.questions;
|
||||
var maxVotes = Math.max.apply(null, questions.map(function (q) { return q.votes; }).concat([1]));
|
||||
var children = [Qa.steps(results.stage, onStage)];
|
||||
|
||||
function votes(question) {
|
||||
return el('span', {
|
||||
class: 'qa-votes',
|
||||
'aria-label': question.votes + (question.votes === 1 ? ' Stimme' : ' Stimmen'),
|
||||
text: '▲ ' + question.votes
|
||||
});
|
||||
}
|
||||
|
||||
if (results.stage === 'collect') {
|
||||
children.push(el('p', { class: 'qa-summary', text: questions.length === 0
|
||||
? 'Noch keine Fragen – jetzt mitmachen und Fragen einreichen!'
|
||||
: questions.length + (questions.length === 1 ? ' Frage eingereicht' : ' Fragen eingereicht') }));
|
||||
children.push(el('ul', { class: 'answers' }, questions.slice().reverse().map(function (question) {
|
||||
return el('li', { class: 'answer', text: question.text });
|
||||
})));
|
||||
} else if (results.stage === 'vote') {
|
||||
children.push(el('p', { class: 'qa-summary', text: 'Abstimmen: jede Person hat '
|
||||
+ results.maxUpvotes + (results.maxUpvotes === 1 ? ' Stimme' : ' Stimmen')
|
||||
+ ' · bisher ' + results.upvotes + ' vergeben' }));
|
||||
children.push(el('ol', { class: 'qa-list' }, questions.map(function (question) {
|
||||
return el('li', { class: 'qa-item' }, [
|
||||
el('span', { class: 'qa-item__text', text: question.text }),
|
||||
votes(question),
|
||||
el('span', { class: 'qa-item__bar', style: 'width:' + (question.votes / maxVotes * 100) + '%' })
|
||||
]);
|
||||
})));
|
||||
} else if (questions.length === 0) {
|
||||
children.push(el('p', { class: 'qa-summary', text: 'Es wurden keine Fragen eingereicht.' }));
|
||||
} else {
|
||||
var index = results.focusIndex === null ? 0 : results.focusIndex;
|
||||
var focus = questions[index];
|
||||
var nav = function (step, label, symbol, disabled) {
|
||||
if (!onQuestion) {
|
||||
return null;
|
||||
}
|
||||
var button = el('button', { type: 'button', class: 'ctrl', title: label }, [
|
||||
el('span', { 'aria-hidden': 'true', text: symbol }),
|
||||
el('span', { class: 'sr-only', text: label })
|
||||
]);
|
||||
button.disabled = disabled;
|
||||
button.addEventListener('click', function () { onQuestion(step); });
|
||||
return button;
|
||||
};
|
||||
children.push(el('div', { class: 'qa-focus', 'aria-live': 'polite' }, [
|
||||
el('p', { class: 'qa-focus__meta' }, [
|
||||
el('span', { text: 'Frage ' + (index + 1) + ' von ' + questions.length }),
|
||||
votes(focus)
|
||||
]),
|
||||
el('p', { class: 'qa-focus__text', text: focus.text }),
|
||||
el('div', { class: 'qa-focus__nav' }, [
|
||||
nav(-1, 'Vorherige Frage', '←', index === 0),
|
||||
nav(1, 'Nächste Frage', '→', index === questions.length - 1)
|
||||
])
|
||||
]));
|
||||
children.push(el('ol', { class: 'qa-list qa-list--compact' }, questions.map(function (question, i) {
|
||||
var attrs = { class: 'qa-item' + (i < index ? ' is-done' : '') + (i === index ? ' is-current' : '') };
|
||||
if (i === index) {
|
||||
attrs['aria-current'] = 'true';
|
||||
}
|
||||
return el('li', attrs, [
|
||||
el('span', { class: 'qa-item__text', text: (i < index ? '✓ ' : '') + question.text }),
|
||||
votes(question)
|
||||
]);
|
||||
})));
|
||||
}
|
||||
return el('div', { class: 'qa-results qa-results--' + results.stage }, children);
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------ Q&A
|
||||
|
||||
var Qa = {
|
||||
labels: { collect: 'Fragen sammeln', vote: 'Abstimmen', discuss: 'Besprechen' },
|
||||
|
||||
/** Stepper of the three stages; clickable for the presenter (onStage). */
|
||||
steps: function (stage, onStage) {
|
||||
return el('ol', { class: 'qa-steps', 'aria-label': 'Ablauf' }, ['collect', 'vote', 'discuss'].map(function (key, i) {
|
||||
var current = key === stage;
|
||||
var label = (i + 1) + ' ' + Qa.labels[key];
|
||||
var item = onStage
|
||||
? el('button', { type: 'button', class: 'qa-steps__step', text: label })
|
||||
: el('span', { class: 'qa-steps__step', text: label });
|
||||
if (current) {
|
||||
item.setAttribute('aria-current', 'step');
|
||||
}
|
||||
if (onStage) {
|
||||
item.disabled = current;
|
||||
item.addEventListener('click', function () { onStage(key); });
|
||||
}
|
||||
return el('li', { class: current ? 'is-current' : '' }, [item]);
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -704,29 +810,38 @@
|
||||
}
|
||||
|
||||
var quizPhase = slide.type === 'quiz' && state.results ? state.results.phase : null;
|
||||
var qaStage = slide.type === 'qa' && state.results ? state.results.stage : null;
|
||||
q('[data-type]').textContent = quizPhase
|
||||
? slide.typeLabel + ' · ' + { ready: 'bereit', running: 'läuft', finished: 'Auflösung' }[quizPhase]
|
||||
: slide.typeLabel;
|
||||
: (qaStage ? slide.typeLabel + ' · ' + Qa.labels[qaStage] : 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--video', slide.type === 'youtube');
|
||||
renderMedia(slide);
|
||||
root.classList.toggle('stage--closed', slide.isInteractive && !slide.isVotingOpen && !quizPhase);
|
||||
root.classList.toggle('stage--closed', slide.isInteractive && !slide.isVotingOpen && !quizPhase && !qaStage);
|
||||
root.classList.toggle('stage--qa', !!qaStage);
|
||||
|
||||
var voting = q('[data-voting]');
|
||||
voting.hidden = !slide.isInteractive;
|
||||
// Q&A: V switches to the next stage, there is none after "discuss".
|
||||
voting.hidden = !slide.isInteractive || qaStage === 'discuss';
|
||||
voting.querySelector('[data-label]').textContent = quizPhase
|
||||
? { ready: 'Quiz starten', running: 'Quiz beenden', finished: 'Quiz erneut öffnen' }[quizPhase]
|
||||
: (slide.isVotingOpen ? 'Abstimmung schließen' : 'Abstimmung öffnen');
|
||||
: (qaStage
|
||||
? { collect: 'Einreichen beenden', vote: 'Abstimmung beenden', discuss: '' }[qaStage]
|
||||
: (slide.isVotingOpen ? 'Abstimmung schließen' : 'Abstimmung öffnen'));
|
||||
|
||||
q('[data-participants]').textContent = slide.isInteractive
|
||||
? state.results.participants + ' ' + (state.results.participants === 1 ? 'Antwort' : 'Antworten')
|
||||
: '';
|
||||
var count = qaStage ? state.results.questions.length : (slide.isInteractive ? state.results.participants : 0);
|
||||
q('[data-participants]').textContent = !slide.isInteractive ? '' : (qaStage
|
||||
? count + (count === 1 ? ' Frage' : ' Fragen')
|
||||
: count + ' ' + (count === 1 ? 'Antwort' : 'Antworten'));
|
||||
|
||||
var container = q('[data-results]');
|
||||
container.classList.toggle('is-hidden', hideResults);
|
||||
Results.render(container, slide.isInteractive ? state.results : null);
|
||||
Results.render(container, slide.isInteractive ? state.results : null, {
|
||||
onStage: function (stage) { control('stage', { stage: stage }); },
|
||||
onQuestion: function (step) { control('question', { step: step }); }
|
||||
});
|
||||
Countdown.start();
|
||||
}
|
||||
|
||||
@@ -833,8 +948,178 @@
|
||||
&& state.isVotingOpen);
|
||||
}
|
||||
|
||||
// --- Q&A: submit questions, upvote, follow the discussion ----------
|
||||
var qaRoot = root.querySelector('[data-qa]');
|
||||
var qaList = qaRoot ? qaRoot.querySelector('[data-qa-list]') : null;
|
||||
var qaMessage = qaRoot ? qaRoot.querySelector('[data-qa-message]') : null;
|
||||
var qaForm = qaRoot ? qaRoot.querySelector('[data-qa-form]') : null;
|
||||
var qaRendered = '';
|
||||
var qaSending = false;
|
||||
|
||||
function qaSay(text, isError) {
|
||||
qaMessage.textContent = text;
|
||||
qaMessage.classList.toggle('is-error', !!isError);
|
||||
}
|
||||
|
||||
function sendQa(data) {
|
||||
if (qaSending) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
qaSending = true;
|
||||
data.slide_id = root.querySelector('[name=slide_id]').value;
|
||||
return postJson(voteUrl, data).then(function (response) {
|
||||
qaSay(response.message, !response.ok);
|
||||
if (response.state.version !== version) {
|
||||
window.location.reload();
|
||||
return null;
|
||||
}
|
||||
renderQa(response.state);
|
||||
return response;
|
||||
}).catch(function () {
|
||||
qaSay('Das hat nicht geklappt. Bitte versuche es noch einmal.', true);
|
||||
return null;
|
||||
}).then(function (response) {
|
||||
qaSending = false;
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
function renderQa(state) {
|
||||
var qa = state.qa;
|
||||
if (!qaList || !qa) {
|
||||
return;
|
||||
}
|
||||
var key = JSON.stringify(qa);
|
||||
if (key === qaRendered) {
|
||||
return;
|
||||
}
|
||||
qaRendered = key;
|
||||
// Keep keyboard focus on the same question after re-rendering.
|
||||
var focused = document.activeElement && document.activeElement.getAttribute('data-question-id');
|
||||
qaList.textContent = '';
|
||||
|
||||
if (qa.stage === 'collect') {
|
||||
// All questions so far, so participants can spot duplicates before asking.
|
||||
qaList.appendChild(el('h2', { class: 'qa-heading', text: 'Bereits gestellte Fragen (' + qa.questions.length + ')' }));
|
||||
if (!qa.questions.length) {
|
||||
qaList.appendChild(el('p', { class: 'results-empty', text: 'Noch keine – stell gern die erste Frage!' }));
|
||||
return;
|
||||
}
|
||||
qaList.appendChild(el('ul', { class: 'qa-list' }, qa.questions.map(function (question) {
|
||||
var mine = qa.mine.indexOf(question.id) >= 0;
|
||||
return el('li', { class: 'qa-item' + (mine ? ' is-mine' : '') }, [
|
||||
el('span', { class: 'qa-item__text', text: question.text }),
|
||||
mine ? el('span', { class: 'qa-own', text: 'deine Frage' }) : null
|
||||
]);
|
||||
})));
|
||||
return;
|
||||
}
|
||||
|
||||
if (qa.stage === 'vote') {
|
||||
var used = qa.maxUpvotes - qa.votesLeft;
|
||||
qaList.appendChild(el('p', { class: 'qa-budget', 'aria-live': 'polite' }, [
|
||||
el('strong', { text: String(qa.votesLeft) }),
|
||||
el('span', { text: ' von ' + qa.maxUpvotes + (qa.maxUpvotes === 1 ? ' Stimme' : ' Stimmen') + ' übrig' })
|
||||
].concat(Array.apply(null, Array(qa.maxUpvotes)).map(function (_, i) {
|
||||
return el('span', { class: 'qa-budget__dot' + (i < used ? ' is-used' : ''), 'aria-hidden': 'true' });
|
||||
}))));
|
||||
if (!qa.questions.length) {
|
||||
qaList.appendChild(el('p', { class: 'results-empty', text: 'Es wurden keine Fragen eingereicht.' }));
|
||||
return;
|
||||
}
|
||||
qaList.appendChild(el('ul', { class: 'qa-list' }, qa.questions.map(function (question) {
|
||||
var mine = qa.mine.indexOf(question.id) >= 0;
|
||||
// Own upvotes on this question – several are allowed to push important questions.
|
||||
var given = (qa.upvoted || {})[question.id] || 0;
|
||||
var action;
|
||||
if (mine) {
|
||||
action = el('span', { class: 'qa-own', text: 'deine Frage' });
|
||||
} else {
|
||||
var button = function (vote, symbol, label, disabled) {
|
||||
var b = el('button', {
|
||||
type: 'button',
|
||||
class: 'qa-upvote qa-upvote--' + vote,
|
||||
'aria-label': label + ': ' + question.text,
|
||||
'data-question-id': question.id + '-' + vote
|
||||
}, [el('span', { 'aria-hidden': 'true', text: symbol })]);
|
||||
b.disabled = disabled;
|
||||
b.addEventListener('click', function () {
|
||||
sendQa({ vote: vote, question_id: question.id });
|
||||
});
|
||||
return b;
|
||||
};
|
||||
action = el('span', { class: 'qa-stepper' + (given > 0 ? ' is-active' : '') }, [
|
||||
button('remove', '−', 'Stimme zurücknehmen', given === 0),
|
||||
el('span', {
|
||||
class: 'qa-stepper__count',
|
||||
'aria-label': given === 0 ? 'keine Stimme von dir' : given + (given === 1 ? ' Stimme' : ' Stimmen') + ' von dir',
|
||||
text: '▲ ' + given
|
||||
}),
|
||||
button('up', '+', 'Stimme geben', qa.votesLeft === 0)
|
||||
]);
|
||||
}
|
||||
return el('li', { class: 'qa-item' + (mine ? ' is-mine' : '') + (given > 0 ? ' is-upvoted' : '') }, [
|
||||
el('span', { class: 'qa-item__text', text: question.text }),
|
||||
action
|
||||
]);
|
||||
})));
|
||||
} else {
|
||||
if (!qa.questions.length) {
|
||||
qaList.appendChild(el('p', { class: 'results-empty', text: 'Es wurden keine Fragen eingereicht.' }));
|
||||
return;
|
||||
}
|
||||
var index = -1;
|
||||
qa.questions.forEach(function (question, i) {
|
||||
if (question.id === qa.focusId) {
|
||||
index = i;
|
||||
}
|
||||
});
|
||||
if (index >= 0) {
|
||||
qaList.appendChild(el('div', { class: 'qa-focus', 'aria-live': 'polite' }, [
|
||||
el('p', { class: 'qa-focus__meta', text: 'Wird gerade besprochen · Frage ' + (index + 1) + ' von ' + qa.questions.length }),
|
||||
el('p', { class: 'qa-focus__text', text: qa.questions[index].text })
|
||||
]));
|
||||
}
|
||||
qaList.appendChild(el('ol', { class: 'qa-list qa-list--compact' }, qa.questions.map(function (question, i) {
|
||||
var mine = qa.mine.indexOf(question.id) >= 0;
|
||||
var attrs = { class: 'qa-item' + (i < index ? ' is-done' : '') + (i === index ? ' is-current' : '') + (mine ? ' is-mine' : '') };
|
||||
if (i === index) {
|
||||
attrs['aria-current'] = 'true';
|
||||
}
|
||||
return el('li', attrs, [
|
||||
el('span', { class: 'qa-item__text', text: (i < index ? '✓ ' : '') + question.text + (mine ? ' (deine Frage)' : '') }),
|
||||
el('span', { class: 'qa-votes', 'aria-label': question.votes + (question.votes === 1 ? ' Stimme' : ' Stimmen'), text: '▲ ' + question.votes })
|
||||
]);
|
||||
})));
|
||||
}
|
||||
|
||||
if (focused) {
|
||||
var again = qaList.querySelector('[data-question-id="' + focused + '"]');
|
||||
if (again && !again.disabled) {
|
||||
again.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (qaForm) {
|
||||
qaForm.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
var field = qaForm.querySelector('[name=question]');
|
||||
var text = field.value.trim();
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
sendQa({ question: text }).then(function (response) {
|
||||
if (response && response.ok) {
|
||||
field.value = '';
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function renderResults(state) {
|
||||
current = state;
|
||||
renderQa(state);
|
||||
if (!card || !container) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user