Skip to content

Commit

Permalink
Fix scrolling to resolved comment anchors (go-gitea#13343) (go-gitea#…
Browse files Browse the repository at this point in the history
…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 <art27@cantab.net>

* Apply suggestions from code review

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
  • Loading branch information
3 people committed Oct 31, 2020
1 parent 79d9cda commit 77a2d75
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 77a2d75

Please sign in to comment.