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:
Matt Enlow 2014-07-30 20:33:05 -06:00
parent 3de308dc20
commit 420500ffab
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'
},