0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Merge pull request #3470 from novaugust/up-down-posts

Add keyboard navigation of posts
This commit is contained in:
Hannah Wolfe 2014-07-31 07:46:46 +01:00
commit fbc368bae5
2 changed files with 27 additions and 3 deletions

View file

@ -24,7 +24,25 @@ var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, Shortcut
this._super(controller, model);
this.setupPagination(paginationSettings);
},
stepThroughPosts: function (step) {
var currentPost = this.get('controller.currentPost'),
posts = this.get('controller.model'),
length = posts.get('length'),
newPosition;
newPosition = posts.indexOf(currentPost) + step;
//Make sure we're inbounds
if (newPosition >= length) {
newPosition = 0;
}
else if (newPosition < 0) {
newPosition = length - 1;
}
this.transitionTo('posts.post', posts.objectAt(newPosition));
},
shortcuts: {
'up': 'moveUp',
'down': 'moveDown'
@ -34,10 +52,10 @@ var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, Shortcut
this.transitionTo('editor.edit', post);
},
moveUp: function () {
window.alert('@todo keyboard post navigation: up');
this.stepThroughPosts(-1);
},
moveDown: function () {
window.alert('@todo keyboard post navigation: down');
this.stepThroughPosts(1);
}
}
});

View file

@ -34,6 +34,12 @@ var PostsPostRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, load
return self.transitionTo('posts.index');
});
},
setupController: function (controller, model) {
this._super(controller, model);
this.controllerFor('posts').set('currentPost', model);
},
shortcuts: {
'enter': 'openEditor'
},