Wrap around for previous/next buttons (#16319)

Fixes #16317

Wrap around from last to first comment when clicking "Next" on last comment.
Wrap around from first to last comment when clicking "Previous" on first comment.
tokarchuk/v1.17
Jimmy Praet 3 years ago committed by GitHub
parent 290f458d46
commit a3476e5ad5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      web_src/js/index.js

@ -947,21 +947,19 @@ async function initRepository() {
const $conversation = $(e.currentTarget).closest('.comment-code-cloud'); const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
const $conversations = $('.comment-code-cloud:not(.hide)'); const $conversations = $('.comment-code-cloud:not(.hide)');
const index = $conversations.index($conversation); const index = $conversations.index($conversation);
if (index !== 0) { const previousIndex = index > 0 ? index - 1 : $conversations.length - 1;
const $previousConversation = $conversations.eq(index - 1); const $previousConversation = $conversations.eq(previousIndex);
const anchor = $previousConversation.find('.comment').first().attr('id'); const anchor = $previousConversation.find('.comment').first().attr('id');
window.location.href = `#${anchor}`; window.location.href = `#${anchor}`;
}
}); });
$(document).on('click', '.next-conversation', (e) => { $(document).on('click', '.next-conversation', (e) => {
const $conversation = $(e.currentTarget).closest('.comment-code-cloud'); const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
const $conversations = $('.comment-code-cloud:not(.hide)'); const $conversations = $('.comment-code-cloud:not(.hide)');
const index = $conversations.index($conversation); const index = $conversations.index($conversation);
if (index !== $conversations.length - 1) { const nextIndex = index < $conversations.length - 1 ? index + 1 : 0;
const $nextConversation = $conversations.eq(index + 1); const $nextConversation = $conversations.eq(nextIndex);
const anchor = $nextConversation.find('.comment').first().attr('id'); const anchor = $nextConversation.find('.comment').first().attr('id');
window.location.href = `#${anchor}`; window.location.href = `#${anchor}`;
}
}); });
// Quote reply // Quote reply

Loading…
Cancel
Save