diff options
author | Jimmy Praet <jimmy.praet@telenet.be> | 2021-07-02 00:02:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-02 00:02:48 +0200 |
commit | a3476e5ad5ee87d4e985b9a3e914bf5348216745 (patch) | |
tree | a640ceb9ad2d1a4190030d6a562fb883b4c65a24 /web_src/js/index.js | |
parent | 290f458d46d4774ac47dca40af4e1c8b9bea755e (diff) | |
download | gitea-a3476e5ad5ee87d4e985b9a3e914bf5348216745.tar.gz gitea-a3476e5ad5ee87d4e985b9a3e914bf5348216745.zip |
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.
Diffstat (limited to 'web_src/js/index.js')
-rw-r--r-- | web_src/js/index.js | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/web_src/js/index.js b/web_src/js/index.js index 0693175a00..0b5ac493ed 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -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 |