From 6b276fdbe0ac71160a8588bfc48f0cb7e4da0759 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 16 Sep 2019 17:30:51 -0400 Subject: [PATCH] Don't load comments until details element is expanded --- site/js/comments.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/site/js/comments.js b/site/js/comments.js index f71a143..eb7ef77 100644 --- a/site/js/comments.js +++ b/site/js/comments.js @@ -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}`);