Show a progress bar until the next scale comment
CI / Deploy / test (push) Successful in 1m2s
CI / Deploy / deploy (push) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 11:40:24 +01:00
1 parent d518b7a37e
commit e6f52a0449
2 files changed
+44 -6

No files matched your search

+38 -4
View File
@@ -303,6 +303,9 @@
timer: null,
items: [],
node: null,
// Countdown of the comment shown (drives the progress bar across re-renders).
startedAt: 0,
duration: 0,
// Time per comment: enough to read it on the stage, within sensible bounds.
BASE_MS: 2500,
@@ -338,6 +341,10 @@
el('p', { class: 'comments__counter', 'data-comment-counter': '' }),
el('blockquote', { class: 'comments__text', 'data-comment-text': '' }),
el('p', { class: 'comments__value', 'data-comment-value': '' }),
// Time left until the next comment; decorative, the counter carries the information.
items.length < 2 ? null : el('div', { class: 'comments__progress', 'data-comment-progress': '', 'aria-hidden': 'true' }, [
el('div', { class: 'comments__progress-fill' })
]),
items.length < 2 ? null : el('div', { class: 'comments__nav' }, [
button('prev', 'Vorheriger Kommentar', '‹'),
button('toggle', '', ''),
@@ -360,10 +367,10 @@
Comments.update(false);
});
Comments.node = node;
Comments.update(false);
if (!Comments.timer) {
Comments.restart();
}
Comments.update(false);
return node;
},
@@ -388,18 +395,44 @@
/** (Re)start the countdown for the comment currently shown. */
restart: function () {
clearTimeout(Comments.timer);
Comments.startedAt = Date.now();
Comments.duration = Comments.delay(Comments.items[Comments.index]);
Comments.timer = setTimeout(function () {
if (!Comments.node || !document.body.contains(Comments.node)) {
// Slide changed: stop until the next comment list is rendered.
Comments.timer = null;
return;
}
if (!Comments.paused && Comments.items.length > 1 && !document.hidden) {
var advance = !Comments.paused && Comments.items.length > 1 && !document.hidden;
if (advance) {
Comments.step(1);
Comments.update(true);
}
Comments.restart();
}, Comments.delay(Comments.items[Comments.index]));
if (advance) {
Comments.update(true);
} else {
Comments.progress();
}
}, Comments.duration);
},
/**
* Fills the progress bar over the remaining time of the current comment.
* Picks up where it was after a re-render (negative animation delay); hidden while paused.
*/
progress: function () {
var bar = Comments.node && Comments.node.querySelector('[data-comment-progress]');
if (!bar) {
return;
}
var fill = bar.firstChild;
bar.hidden = Comments.paused;
fill.style.animation = 'none';
void fill.offsetWidth; // restart the CSS animation
if (!Comments.paused) {
var elapsed = Math.min(Date.now() - Comments.startedAt, Comments.duration);
fill.style.animation = 'comment-progress ' + Comments.duration + 'ms linear -' + elapsed + 'ms forwards';
}
},
update: function (animate) {
@@ -427,6 +460,7 @@
toggle.setAttribute('title', label);
toggle.setAttribute('aria-pressed', Comments.paused ? 'true' : 'false');
}
Comments.progress();
}
};