From 77a2d756399b994b238360a0fa528ecc2bf1528c Mon Sep 17 00:00:00 2001 From: zeripath Date: Sat, 31 Oct 2020 11:51:51 +0000 Subject: [PATCH] Fix scrolling to resolved comment anchors (#13343) (#13371) * Fix scrolling to resolved comment anchors As described on discord, when the window.location.hash refers to a resolved comment then the scroll to functionality does not work. This PR fixes this. Signed-off-by: Andrew Thornton * Apply suggestions from code review Co-authored-by: silverwind Co-authored-by: techknowlogick --- web_src/js/index.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/web_src/js/index.js b/web_src/js/index.js index 94238ca3d9b..6aedd8b5491 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1170,6 +1170,22 @@ async function initRepository() { } function initPullRequestReview() { + if (window.location.hash && window.location.hash.startsWith('#issuecomment-')) { + const commentDiv = $(window.location.hash); + if (commentDiv) { + // get the name of the parent id + const groupID = commentDiv.closest('div[id^="code-comments-"]').attr('id'); + if (groupID && groupID.startsWith('code-comments-')) { + const id = groupID.substr(14); + $(`#show-outdated-${id}`).addClass('hide'); + $(`#code-comments-${id}`).removeClass('hide'); + $(`#code-preview-${id}`).removeClass('hide'); + $(`#hide-outdated-${id}`).removeClass('hide'); + $(window).scrollTop(commentDiv.offset().top); + } + } + } + $('.show-outdated').on('click', function (e) { e.preventDefault(); const id = $(this).data('comment');