diff --git a/assets/js/comment-pagination.js b/assets/js/comment-pagination.js new file mode 100644 index 0000000..f952338 --- /dev/null +++ b/assets/js/comment-pagination.js @@ -0,0 +1,35 @@ +document.addEventListener("DOMContentLoaded", function () { + const commentsContainer = document.getElementById("comments-container"); + const loadMoreBtn = document.getElementById("load-more-btn"); + const comments = commentsContainer.getElementsByClassName("comment-item"); + const commentsPerPage = 10; + let currentlyShown = commentsPerPage; + + // Initially hide comments beyond the first 10 + for (let i = commentsPerPage; i < comments.length; i++) { + comments[i].style.display = "none"; + } + + // Hide the "Load more" button if there are 10 or fewer comments + if (comments.length <= commentsPerPage) { + loadMoreBtn.style.display = "none"; + } + + loadMoreBtn.addEventListener("click", function () { + // Show the next set of comments + for ( + let i = currentlyShown; + i < currentlyShown + commentsPerPage && i < comments.length; + i++ + ) { + comments[i].style.display = "block"; + } + + currentlyShown += commentsPerPage; + + // Hide the "Load more" button if all comments are shown + if (currentlyShown >= comments.length) { + loadMoreBtn.style.display = "none"; + } + }); +}); diff --git a/assets/views/artwork.jet.html b/assets/views/artwork.jet.html index 1b4dc67..5fceb89 100644 --- a/assets/views/artwork.jet.html +++ b/assets/views/artwork.jet.html @@ -44,10 +44,10 @@ {{- else if .Illust.Comments == 0 }}
There are no comments yet
{{- else }} -