Skip to content

Commit

Permalink
Wrap around for previous/next buttons
Browse files Browse the repository at this point in the history
Fixes go-gitea#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.
  • Loading branch information
jpraet committed Jun 30, 2021
1 parent ce286f9 commit 13fa3b4
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,21 +947,19 @@ async function initRepository() {
const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
const $conversations = $('.comment-code-cloud:not(.hide)');
const index = $conversations.index($conversation);
if (index !== 0) {
const $previousConversation = $conversations.eq(index - 1);
const anchor = $previousConversation.find('.comment').first().attr('id');
window.location.href = `#${anchor}`;
}
const previousIndex = index > 0 ? index - 1 : $conversations.length - 1;
const $previousConversation = $conversations.eq(previousIndex);
const anchor = $previousConversation.find('.comment').first().attr('id');
window.location.href = `#${anchor}`;
});
$(document).on('click', '.next-conversation', (e) => {
const $conversation = $(e.currentTarget).closest('.comment-code-cloud');
const $conversations = $('.comment-code-cloud:not(.hide)');
const index = $conversations.index($conversation);
if (index !== $conversations.length - 1) {
const $nextConversation = $conversations.eq(index + 1);
const anchor = $nextConversation.find('.comment').first().attr('id');
window.location.href = `#${anchor}`;
}
const nextIndex = index < $conversations.length - 1 ? index + 1 : 0;
const $nextConversation = $conversations.eq(nextIndex);
const anchor = $nextConversation.find('.comment').first().attr('id');
window.location.href = `#${anchor}`;
});

// Quote reply
Expand Down

0 comments on commit 13fa3b4

Please sign in to comment.