From c7ccc6b5aaf70048091c41932052bded4578a06f Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Wed, 28 Oct 2020 20:34:55 +0000 Subject: [PATCH 1/2] 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 --- 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 cdabffe04d1c0..49670fd288024 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1172,6 +1172,22 @@ async function initRepository() { } function initPullRequestReview() { + if (window.location.hash && 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.parents('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'); From 20c1f66194fedf0fb508a452e1f6d4ff6ab60c6f Mon Sep 17 00:00:00 2001 From: zeripath Date: Wed, 28 Oct 2020 22:22:11 +0000 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: silverwind --- web_src/js/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 49670fd288024..7c56703144751 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -1172,11 +1172,11 @@ async function initRepository() { } function initPullRequestReview() { - if (window.location.hash && window.location.hash !== '' && window.location.hash.startsWith('#issuecomment-')) { - const commentDiv = $(`${window.location.hash}`); + 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.parents('div[id^="code-comments-"]').attr('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');