Add internal feedback and comments to scale slides

- Setting "private": distribution and average are only shown in the
  admin evaluation page and CSV export, the stage shows just the count.
- Setting "comments": optional comment field for participants; on public
  scales the comments rotate on the results ("Kommentar X von N") with
  previous/next/pause controls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-08 15:52:55 +01:00
1 parent a138425ab0
commit 238797ecfd
15 files changed
+665 -23

No files matched your search

+137 -1
View File
@@ -289,6 +289,122 @@
}
};
// ------------------------------------------------------------------ comments
/**
* Rotating comments of a scale slide. The results are re-rendered on every poll,
* so position, pause and timer live here and survive the re-render.
*/
var Comments = {
intervalMs: 8000,
key: null,
index: 0,
paused: false,
timer: null,
items: [],
node: null,
render: function (items) {
// A different first comment means a different slide (or a reset): start over.
var key = String(items[0].id);
if (key !== Comments.key) {
Comments.key = key;
Comments.index = 0;
Comments.paused = false;
}
Comments.items = items;
Comments.index = Math.min(Comments.index, items.length - 1);
var button = function (action, label, text) {
return el('button', {
type: 'button',
class: 'button button--small comments__button',
'data-comment-action': action,
'aria-label': label,
title: label,
text: text
});
};
var node = el('section', { class: 'comments', 'data-comments': '', 'aria-label': 'Kommentare' }, [
el('p', { class: 'comments__counter', 'data-comment-counter': '' }),
el('blockquote', { class: 'comments__text', 'data-comment-text': '' }),
el('p', { class: 'comments__value', 'data-comment-value': '' }),
items.length < 2 ? null : el('div', { class: 'comments__nav' }, [
button('prev', 'Vorheriger Kommentar', '‹'),
button('toggle', '', ''),
button('next', 'Nächster Kommentar', '›')
])
]);
node.addEventListener('click', function (event) {
var target = event.target.closest('[data-comment-action]');
if (!target) {
return;
}
var action = target.getAttribute('data-comment-action');
if (action === 'toggle') {
Comments.paused = !Comments.paused;
} else {
Comments.step(action === 'next' ? 1 : -1);
Comments.restart();
}
Comments.update(false);
});
Comments.node = node;
Comments.update(false);
if (!Comments.timer) {
Comments.restart();
}
return node;
},
step: function (delta) {
var n = Comments.items.length;
Comments.index = (Comments.index + delta + n) % n;
},
restart: function () {
clearInterval(Comments.timer);
Comments.timer = setInterval(function () {
if (!Comments.node || !document.body.contains(Comments.node)) {
// Slide changed: stop until the next comment list is rendered.
clearInterval(Comments.timer);
Comments.timer = null;
return;
}
if (Comments.paused || Comments.items.length < 2 || document.hidden) {
return;
}
Comments.step(1);
Comments.update(true);
}, Comments.intervalMs);
},
update: function (animate) {
var node = Comments.node;
var item = Comments.items[Comments.index];
var text = node.querySelector('[data-comment-text]');
node.querySelector('[data-comment-counter]').textContent =
'Kommentar ' + (Comments.index + 1) + ' von ' + Comments.items.length;
text.textContent = item.text;
node.querySelector('[data-comment-value]').textContent = 'Bewertung: ' + item.value;
// Only announce changes the viewer triggered, not every automatic rotation.
node.setAttribute('aria-live', Comments.paused ? 'polite' : 'off');
text.classList.remove('is-entering');
if (animate) {
void text.offsetWidth; // restart the CSS animation
text.classList.add('is-entering');
}
var toggle = node.querySelector('[data-comment-action="toggle"]');
if (toggle) {
var label = Comments.paused ? 'Kommentare automatisch weiterblättern' : 'Automatisches Weiterblättern anhalten';
toggle.textContent = Comments.paused ? '▶' : '❚❚';
toggle.setAttribute('aria-label', label);
toggle.setAttribute('title', label);
toggle.setAttribute('aria-pressed', Comments.paused ? 'true' : 'false');
}
}
};
// ------------------------------------------------------------------ results
var Results = {
@@ -296,6 +412,9 @@
* @param {Object} [options] renderer specific; wordcloud: {mine: [keys], onUpvote: fn(word)|null}
*/
render: function (container, results, options) {
// Keep keyboard focus on controls inside the results (e.g. comment buttons) across re-renders.
var active = document.activeElement;
var focusKey = active && container.contains(active) ? active.getAttribute('data-comment-action') : null;
container.innerHTML = '';
if (!results) {
return;
@@ -313,6 +432,10 @@
return;
}
container.appendChild(renderer(results, options || {}));
var refocus = focusKey && container.querySelector('[data-comment-action="' + focusKey + '"]');
if (refocus) {
refocus.focus();
}
},
choice: function (results) {
@@ -329,6 +452,15 @@
},
scale: function (results) {
if (results.private) {
// Internal feedback: the ratings never reach the stage, only the count.
var n = results.participants;
return el('div', { class: 'private-summary' }, [
el('p', { class: 'private-summary__count', text: String(n) }),
el('p', { text: (n === 1 ? 'Bewertung' : 'Bewertungen') + ' eingegangen' }),
el('p', { class: 'private-summary__hint', text: '🔒 Ergebnis wird nicht öffentlich angezeigt.' })
]);
}
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
var hasAverage = results.average !== null;
@@ -375,7 +507,8 @@
]),
gauge
]);
return el('div', { class: 'scale-results' }, [average, columns, labels]);
var comments = results.comments && results.comments.length ? Comments.render(results.comments) : null;
return el('div', { class: 'scale-results' }, [average, columns, labels, comments]);
},
/**
@@ -1039,6 +1172,9 @@
if (event.target.closest('input, textarea, select')) {
return;
}
if ((event.key === ' ' || event.key === 'Enter') && event.target.closest('[data-comments]')) {
return; // activates the focused comment button, not the next slide
}
if (embedded && ['ArrowRight', 'ArrowLeft', 'PageUp', 'PageDown', ' ', 'p', 'P', 'f', 'F', 'q', 'Q'].indexOf(event.key) >= 0) {
return; // slide navigation belongs to the surrounding presentation
}