diff options
author | Johan Sørensen <johan@johansorensen.com> | 2009-10-14 12:52:57 +0200 |
---|---|---|
committer | Johan Sørensen <johan@johansorensen.com> | 2009-11-04 15:23:26 +0100 |
commit | 9081a5621fd295ecba196fae6ccc9f5fc12cdc3d (patch) | |
tree | 1024f78b51b8c4435774b361577550539867e82d /public/javascripts/application.js | |
parent | 3aa0892e98be4d387e93c14fff2d8cfa4fe1820f (diff) | |
download | gitorious-mainline-outdated-9081a5621fd295ecba196fae6ccc9f5fc12cdc3d.zip gitorious-mainline-outdated-9081a5621fd295ecba196fae6ccc9f5fc12cdc3d.tar.gz gitorious-mainline-outdated-9081a5621fd295ecba196fae6ccc9f5fc12cdc3d.tar.bz2 |
Support navigating diff comments up/down with the j/k keys
Diffstat (limited to 'public/javascripts/application.js')
-rw-r--r-- | public/javascripts/application.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 16ca192..0ebd927 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -653,6 +653,7 @@ Gitorious.DiffBrowser = function(shas) Gitorious.MergeRequestController.getInstance().didReceiveVersion(shaSpec); Gitorious.setDiffBrowserHunkStateFromCookie(); Gitorious.enableCommenting(); + Gitorious.DiffBrowser.KeyNavigation.enable(); } }, "error": function(xhr, statusText, errorThrown) { @@ -662,6 +663,49 @@ Gitorious.DiffBrowser = function(shas) }); } +Gitorious.DiffBrowser.KeyNavigation = { + _currentIndex: 0, + + _callback: function(event) { + var scrollToCommentAtCurrentIndex = function(commentElement) { + var elements = $("table tr td .diff-comments .diff-comment"); + if (Gitorious.DiffBrowser.KeyNavigation._currentIndex >= elements.length || + Gitorious.DiffBrowser.KeyNavigation._currentIndex <= 0) + { + Gitorious.DiffBrowser.KeyNavigation._currentIndex = 0; + } + var element = $(elements[Gitorious.DiffBrowser.KeyNavigation._currentIndex]); + element.parents(".diff-comments:hidden").slideDown(); + window.scrollTo(0, element.position().top + window.innerHeight); + }; + + if (event.keyCode === 74) { // j + scrollToCommentAtCurrentIndex(); + Gitorious.DiffBrowser.KeyNavigation._currentIndex++; + } else if (event.keyCode === 75) { // k + Gitorious.DiffBrowser.KeyNavigation._currentIndex--; + scrollToCommentAtCurrentIndex(); + } + }, + + enable: function() { + $(window).keypress(function(e) { + $(window).keydown(Gitorious.DiffBrowser.KeyNavigation._callback); + }); + // unbind whenever we're in an input field + Gitorious.DiffBrowser.KeyNavigation.disable(); + $(":input").blur(function() { + $(window).keydown(Gitorious.DiffBrowser.KeyNavigation._callback); + }); + }, + + disable: function() { + $(":input").focus(function() { + $(window).unbind("keypress", Gitorious.DiffBrowser.KeyNavigation._callback); + }); + } +} + Gitorious.MergeRequestController = function() { this.willSelectShas = function() { $("#current_shas .label").html("Selecting"); |