Fix scrolling to resolved comment anchors (#13343)
* 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: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
6c323678d0
commit
ffc8ce7bae
|
@ -1172,6 +1172,22 @@ async function initRepository() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initPullRequestReview() {
|
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) {
|
$('.show-outdated').on('click', function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const id = $(this).data('comment');
|
const id = $(this).data('comment');
|
||||||
|
|
Loading…
Reference in a new issue