Don't load comments until details element is expanded

This commit is contained in:
Shadowfacts 2019-09-16 17:30:51 -04:00
parent 897015f3f2
commit 6b276fdbe0
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 9 additions and 1 deletions

View File

@ -1,4 +1,12 @@
fetchComments();
let commentsLoaded = false;
const details = document.getElementById("comments-container");
details.addEventListener("toggle", (even) => {
if (details.open && !commentsLoaded) {
fetchComments().then(() => {
commentsLoaded = true;
});
}
});
async function fetchComments() {
const res = await fetch(`/comments?id=${permalink}`);