]> git.mxchange.org Git - friendica.git/commitdiff
Scroll to next/previous thread when pressing j/k (fixes #3327)
authorPierre Rudloff <contact@rudloff.pro>
Wed, 12 Apr 2017 21:16:44 +0000 (23:16 +0200)
committerPierre Rudloff <contact@rudloff.pro>
Thu, 13 Apr 2017 13:16:49 +0000 (15:16 +0200)
js/main.js

index 556e4ed8cf082a32dd8f0578197b3647d76b76c4..98c219d78cabb8e4d06aa1090730c6d2ec146120 100644 (file)
                        }
                });
 
+               $(document).keydown(function (event) {
+                       var threads = $('.thread_level_1');
+                       if ((event.keyCode === 74 || event.keyCode === 75) && !$(event.target).is('textarea, input')) {
+                               var scrollTop = $(window).scrollTop();
+                               if (event.keyCode === 75) {
+                                       threads = $(threads.get().reverse());
+                               }
+                               threads.each(function(key, item) {
+                                       var comparison;
+                                       var top = $(item).offset().top - 100;
+                                       if (event.keyCode === 74) {
+                                               comparison = top > scrollTop + 1;
+                                       } else if (event.keyCode === 75) {
+                                               comparison = top < scrollTop - 1;
+                                       }
+                                       if (comparison) {
+                                               $('html, body').animate({ scrollTop: top }, 200);
+                                               return false;
+                                       }
+                               });
+                       }
+               });
+
                // Set an event listener for infinite scroll
                if(typeof infinite_scroll !== 'undefined') {
                        $(window).scroll(function(e){