diff --git a/src/main/resources/i18n/en.properties b/src/main/resources/i18n/en.properties index 8a5d0bb5..e309d35f 100644 --- a/src/main/resources/i18n/en.properties +++ b/src/main/resources/i18n/en.properties @@ -107,6 +107,8 @@ about.shortcuts.open_next_entry=open next entry about.shortcuts.open_previous_entry=open previous entry about.shortcuts.focus_next_entry=set focus on next entry without opening it about.shortcuts.focus_previous_entry=set focus on previous entry without opening it +about.shortcuts.open_next_feed=open next feed or category +about.shortcuts.open_previous_feed=open previous feed or category about.shortcuts.open_close_current_entry=open/close current entry about.shortcuts.open_current_entry_in_new_window=open current entry in a new window about.shortcuts.open_current_entry_in_new_window_background=open current entry in a new window in the background diff --git a/src/main/webapp/js/controllers.js b/src/main/webapp/js/controllers.js index f3d5437f..02131048 100644 --- a/src/main/webapp/js/controllers.js +++ b/src/main/webapp/js/controllers.js @@ -196,6 +196,82 @@ function($scope, $timeout, $stateParams, $window, $location, $state, $route, Cat } } }; + + var flat = function() { + var a = []; + a.push([ 'all', 'category' ]); + a.push([ 'starred', 'category' ]); + for ( var i = 1; i < CategoryService.flatCategories.length; i++) { + var cat = CategoryService.flatCategories[i]; + a.push([ cat.id, 'category' ]); + + var feeds = cat.orig.feeds; + if (feeds) { + for ( var j = 0; j < feeds.length; j++) { + a.push([ feeds[j].id, 'feed' ]); + } + } + } + return a; + } + + var getCurrentIndex = function (id, type, flat) { + var index = -1; + for ( var i = 0; i < flat.length; i++) { + var node = flat[i]; + if (node[0] == id && node[1] == type) { + index = i; + break; + } + } + return index; + } + + var openNextNode = function() { + var f = flat(); + var current = getCurrentIndex($scope.selectedId, $scope.selectedType, f); + current++; + if(current < f.length) { + $state.transitionTo('feeds.view', { + _type : f[current][1], + _id : f[current][0] + }); + } + } + + var openPreviousNode = function() { + var f = flat(); + var current = getCurrentIndex($scope.selectedId, $scope.selectedType, f); + current--; + if(current >= 0) { + $state.transitionTo('feeds.view', { + _type : f[current][1], + _id : f[current][0] + }); + } + } + + Mousetrap.bind('shift+j', function(e) { + $scope.$apply(function() { + openNextNode(); + }); + }); + Mousetrap.bind('shift+n', function(e) { + $scope.$apply(function() { + openNextNode(); + }); + }); + + Mousetrap.bind('shift+p', function(e) { + $scope.$apply(function() { + openPreviousNode(); + }); + }); + Mousetrap.bind('shift+k', function(e) { + $scope.$apply(function() { + openPreviousNode(); + }); + }); $scope.$on('mark', function(event, args) { mark($scope.CategoryService.subscriptions, args.entry); diff --git a/src/main/webapp/templates/_shortcuts.html b/src/main/webapp/templates/_shortcuts.html index a69ba685..b5b4d4bf 100644 --- a/src/main/webapp/templates/_shortcuts.html +++ b/src/main/webapp/templates/_shortcuts.html @@ -10,6 +10,12 @@
p
${about.shortcuts.focus_previous_entry}
+ +
shift+j,shift+n
+
${about.shortcuts.open_next_feed}
+ +
shift+k,shift+p
+
${about.shortcuts.open_previous_feed}
o, enter
${about.shortcuts.open_close_current_entry}