mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 16:14:25 +03:00
Add keyboard navigation of posts
Closes #3015 - Added stepThroughPosts method to PostsRouter, takes a integer, goes that far, wraps around the array. - PostsPostRoute notifies the PostsController of which model it currently has, to help stepThroughPosts know who's selected
This commit is contained in:
parent
3de308dc20
commit
420500ffab
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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'
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user