From c27f64441738677868d7d9a4dbf8c9d538706962 Mon Sep 17 00:00:00 2001 From: Yo Mama Date: Wed, 15 Sep 2021 00:39:45 +0200 Subject: [PATCH] Improve comment collapse --- files/templates/default.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/files/templates/default.html b/files/templates/default.html index 7172bb4859..58210f9008 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -81,10 +81,17 @@ function collapse_comment(comment_id) { - var comment = "comment-" + comment_id; + const OFFSET = window.innerHeight / 3 - document.getElementById(comment).classList.toggle("collapsed"); + const comment = "comment-" + comment_id; + const element = document.getElementById(comment) + const closed = element.classList.toggle("collapsed"); + const top = element.getBoundingClientRect().y + if (closed && top < OFFSET) { + element.scrollIntoView() + window.scrollBy(0, - OFFSET) + } }; //Commenting form