diff --git a/resources/views/components/video-comments.blade.php b/resources/views/components/video-comments.blade.php index 4e2880d..73d60c6 100644 --- a/resources/views/components/video-comments.blade.php +++ b/resources/views/components/video-comments.blade.php @@ -156,20 +156,12 @@ @endif - {{-- Reply form --}} + {{-- Reply form is lazy-cloned from #ytc-reply-form-tpl on + first click; the ~13-line markup used to render for + every top-level comment (so a 50-comment video shipped + ~650 lines of hidden form markup to every viewer). --}} @auth -
+ @endauth {{-- Replies --}} @@ -1062,10 +1054,29 @@ async function toggleTranslate(btn) { } } -// ── Reply form ──────────────────────────────────────── +// ── Reply form (lazy-rendered from a ) ────── +// Replaces the per-comment inline markup that used to live in the DOM +// pre-hidden. First click on "Reply" clones the template into the comment's +// .ytc-reply-slot and wires its IDs. Subsequent toggles just show/hide. function toggleReplyForm(commentId) { - const form = document.getElementById('replyForm' + commentId); - if (!form) return; + let form = document.getElementById('replyForm' + commentId); + if (!form) { + const slot = document.querySelector('.ytc-reply-slot[data-comment-id="' + commentId + '"]'); + const tpl = document.getElementById('ytc-reply-form-tpl'); + if (!slot || !tpl) return; + const frag = tpl.content.cloneNode(true); + const root = frag.querySelector('.ytc-reply-form'); + const ta = frag.querySelector('.ytc-reply-textarea'); + const cancel = frag.querySelector('._comment-cancel-reply-trigger'); + const submit = frag.querySelector('._comment-submit-reply-trigger'); + root.id = 'replyForm' + commentId; + ta.id = 'replyBody' + commentId; + cancel.dataset.commentId = commentId; + submit.dataset.parentId = commentId; + submit.dataset.videoId = slot.dataset.videoId || YTC.videoId; + slot.appendChild(frag); + form = root; + } const isOpen = form.classList.contains('open'); document.querySelectorAll('.ytc-reply-form.open').forEach(f => f.classList.remove('open')); if (!isOpen) { @@ -1513,3 +1524,22 @@ window._comment = { })(); + +@auth +{{-- Reply-form template. Cloned into .ytc-reply-slot the first time a user + clicks Reply on a given comment. Keeping it here (not in the layout) + means the markup travels with the comments component — the only place + that uses it. --}} + + + +@endauth