Run the comment progress around the border of the box
Two lines start at opposite corners (top left along the top, bottom right along the bottom) and meet when the next comment is due. Drawn as an SVG outline with pathLength 100 and a dash pattern repeating every half perimeter, so it follows the rounded corners. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
12b10121ec
commit
7a378a0bc5
3 files changed
+31
-12
No files matched your search
+19
-5
@@ -360,9 +360,7 @@
|
||||
])
|
||||
])),
|
||||
// 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 : Comments.progressBorder(),
|
||||
items.length < 2 ? null : el('div', { class: 'comments__nav' }, [
|
||||
button('prev', 'Vorheriger Kommentar', '‹'),
|
||||
button('toggle', '', ''),
|
||||
@@ -459,6 +457,22 @@
|
||||
}, Comments.duration);
|
||||
},
|
||||
|
||||
/**
|
||||
* Progress as the border of the box: an SVG outline (follows the rounded corners) whose
|
||||
* dash pattern repeats every half perimeter, so two lines start at opposite corners
|
||||
* (top left along the top, bottom right along the bottom) and meet when the time is up.
|
||||
*/
|
||||
progressBorder: function () {
|
||||
var ns = 'http://www.w3.org/2000/svg';
|
||||
var svg = document.createElementNS(ns, 'svg');
|
||||
var rect = document.createElementNS(ns, 'rect');
|
||||
rect.setAttribute('class', 'comments__progress-fill');
|
||||
rect.setAttribute('pathLength', '100');
|
||||
rect.setAttribute('data-comment-progress-fill', '');
|
||||
svg.appendChild(rect);
|
||||
return el('div', { class: 'comments__progress', 'data-comment-progress': '', 'aria-hidden': 'true' }, [svg]);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -468,10 +482,10 @@
|
||||
if (!bar) {
|
||||
return;
|
||||
}
|
||||
var fill = bar.firstChild;
|
||||
var fill = bar.querySelector('[data-comment-progress-fill]');
|
||||
bar.hidden = Comments.paused;
|
||||
fill.style.animation = 'none';
|
||||
void fill.offsetWidth; // restart the CSS animation
|
||||
void fill.getBoundingClientRect(); // restart the CSS animation (SVG has no offsetWidth)
|
||||
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';
|
||||
|
||||
Reference in new issue
Block a user