@@ -504,7 +504,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<span class="comment-time timeago" tooltip="${fullDate}" style="font-size: 0.75em;"${tsAttr}>${timeStr}</span>
|
<span class="comment-time timeago" tooltip="${fullDate}" style="font-size: 0.75em;"${tsAttr}>${timeStr}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment-content has-overflow"><div class="comment-content-inner">${displayContent}${attachmentsHtml}${pollHtml}</div><button class="read-more-btn">${window.f0ckI18n?.sidebar_read_more || 'read more'}</button></div>
|
<div class="comment-content has-overflow"><div class="comment-content-inner">${displayContent}${attachmentsHtml}${pollHtml}</div><button class="read-more-btn" style="display:block">${window.f0ckI18n?.sidebar_read_more || 'read more'}</button></div>
|
||||||
${itemPreview}
|
${itemPreview}
|
||||||
</div>
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
@@ -544,8 +544,11 @@
|
|||||||
|
|
||||||
// Write phase: perform DOM updates after all reads are completed.
|
// Write phase: perform DOM updates after all reads are completed.
|
||||||
// Visibility of the button is controlled entirely by the CSS rule on
|
// Visibility of the button is controlled entirely by the CSS rule on
|
||||||
// .comment-content.has-overflow > .read-more-btn — JS only toggles the class.
|
// .comment-content.has-overflow > .read-more-btn — no btn.style.display here.
|
||||||
results.forEach(({ container, btn, isExpanded, scrollHeight, clientHeight, hasUnloadedImages }) => {
|
results.forEach(({ container, btn, isExpanded, scrollHeight, clientHeight, hasUnloadedImages }) => {
|
||||||
|
// Clear any leftover inline display style (e.g. from the HTML template's
|
||||||
|
// style="display:block") so the CSS class-based rule is the single source of truth.
|
||||||
|
btn.style.display = '';
|
||||||
|
|
||||||
if (isExpanded) {
|
if (isExpanded) {
|
||||||
btn.textContent = window.f0ckI18n?.sidebar_see_less || 'see less';
|
btn.textContent = window.f0ckI18n?.sidebar_see_less || 'see less';
|
||||||
@@ -635,17 +638,19 @@
|
|||||||
}
|
}
|
||||||
attachMediaLoadListeners(container);
|
attachMediaLoadListeners(container);
|
||||||
// has-overflow is set by default in the HTML template so all comments start
|
// has-overflow is set by default in the HTML template so all comments start
|
||||||
// clamped with the "read more" button visible (CSS handles this via the
|
// clamped with the "read more" button visible. We must NOT run checkOverflow
|
||||||
// .has-overflow > .read-more-btn rule). We intentionally do NOT run
|
// synchronously here — the browser has not yet laid out the freshly injected
|
||||||
// checkOverflow eagerly — on production, layout measurements are unreliable
|
// innerHTML, so scrollHeight / clientHeight are 0 and checkOverflow would
|
||||||
// even inside requestAnimationFrame and the function would incorrectly
|
// incorrectly hide every button. Instead we defer to after the first layout
|
||||||
// remove has-overflow from comments that genuinely overflow, causing the
|
// frame so measurements are accurate and short comments get their buttons
|
||||||
// button to disappear and re-appear. Instead we only run checkOverflow
|
// removed while long comments keep them visible from the very first paint.
|
||||||
// after a comfortable delay so short comments get their buttons cleaned up
|
requestAnimationFrame(() => {
|
||||||
// once layout is fully settled.
|
checkOverflow();
|
||||||
setTimeout(checkOverflow, 300);
|
// After 1s, re-check everything — by then even slow ctrl+F5 images will
|
||||||
// Safety-net re-check: images may still be loading at 300ms.
|
// have loaded and been laid out, so scrollHeight is accurate for all
|
||||||
setTimeout(checkOverflow, 1500);
|
// image comments.
|
||||||
|
setTimeout(checkOverflow, 1000);
|
||||||
|
});
|
||||||
fetchSidebarYoutubeTitles(container);
|
fetchSidebarYoutubeTitles(container);
|
||||||
// Auto-play converted GIF videos and webm emoji stickers
|
// Auto-play converted GIF videos and webm emoji stickers
|
||||||
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
|
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
|
||||||
@@ -768,10 +773,13 @@
|
|||||||
fetchSidebarYoutubeTitles(node);
|
fetchSidebarYoutubeTitles(node);
|
||||||
playSidebarEmojiVideos(node);
|
playSidebarEmojiVideos(node);
|
||||||
});
|
});
|
||||||
// Defer overflow checks so layout measurements are accurate.
|
// Defer overflow checks to after layout so measurements are accurate.
|
||||||
setTimeout(() => addedNodes.forEach(node => checkOverflow(node)), 300);
|
requestAnimationFrame(() => {
|
||||||
// Safety-net re-check for image comments whose layout settles later.
|
addedNodes.forEach(node => checkOverflow(node));
|
||||||
setTimeout(() => addedNodes.forEach(node => checkOverflow(node)), 1500);
|
// Deferred re-check for image comments — mirrors renderFromCache behaviour.
|
||||||
|
// Images in newly appended nodes may not be laid out yet at append time.
|
||||||
|
setTimeout(() => addedNodes.forEach(node => checkOverflow(node)), 1000);
|
||||||
|
});
|
||||||
// Auto-play converted GIF videos and webm emoji stickers
|
// Auto-play converted GIF videos and webm emoji stickers
|
||||||
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
|
container.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
|
||||||
}
|
}
|
||||||
@@ -836,7 +844,7 @@
|
|||||||
node.classList.add('new-item-fade');
|
node.classList.add('new-item-fade');
|
||||||
container.prepend(node);
|
container.prepend(node);
|
||||||
attachMediaLoadListeners(node);
|
attachMediaLoadListeners(node);
|
||||||
setTimeout(() => checkOverflow(node), 300);
|
requestAnimationFrame(() => checkOverflow(node));
|
||||||
fetchSidebarYoutubeTitles(container);
|
fetchSidebarYoutubeTitles(container);
|
||||||
playSidebarEmojiVideos(node);
|
playSidebarEmojiVideos(node);
|
||||||
}
|
}
|
||||||
@@ -888,7 +896,7 @@
|
|||||||
void el.offsetWidth;
|
void el.offsetWidth;
|
||||||
el.classList.add('new-item-fade');
|
el.classList.add('new-item-fade');
|
||||||
attachMediaLoadListeners(inner);
|
attachMediaLoadListeners(inner);
|
||||||
setTimeout(() => checkOverflow(inner), 300);
|
requestAnimationFrame(() => checkOverflow(inner));
|
||||||
fetchSidebarYoutubeTitles(el);
|
fetchSidebarYoutubeTitles(el);
|
||||||
// Auto-play converted GIF videos
|
// Auto-play converted GIF videos
|
||||||
inner.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
|
inner.querySelectorAll('video.autoplay-gif').forEach(v => { v.autoplay = true; v.muted = true; v.play().catch(() => { v.addEventListener('canplay', () => v.play().catch(() => { }), { once: true }); }); });
|
||||||
|
|||||||
Reference in New Issue
Block a user