]> source.dussan.org Git - gitea.git/commitdiff
Wrap around for previous/next buttons (#16319)
authorJimmy Praet <jimmy.praet@telenet.be>
Thu, 1 Jul 2021 22:02:48 +0000 (00:02 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Jul 2021 22:02:48 +0000 (00:02 +0200)
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.

web_src/js/index.js

index 0693175a00985c04a010b69f7e013ed2166d6b30..0b5ac493ed6a87cb356549bdfb89e0ce43ca19c5 100644 (file)
@@ -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