mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05: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
ed788ef723
commit
e3a5608108
2 changed files with 27 additions and 3 deletions
|
@ -24,7 +24,25 @@ var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, Shortcut
|
||||||
this._super(controller, model);
|
this._super(controller, model);
|
||||||
this.setupPagination(paginationSettings);
|
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: {
|
shortcuts: {
|
||||||
'up': 'moveUp',
|
'up': 'moveUp',
|
||||||
'down': 'moveDown'
|
'down': 'moveDown'
|
||||||
|
@ -34,10 +52,10 @@ var PostsRoute = Ember.Route.extend(SimpleAuth.AuthenticatedRouteMixin, Shortcut
|
||||||
this.transitionTo('editor.edit', post);
|
this.transitionTo('editor.edit', post);
|
||||||
},
|
},
|
||||||
moveUp: function () {
|
moveUp: function () {
|
||||||
window.alert('@todo keyboard post navigation: up');
|
this.stepThroughPosts(-1);
|
||||||
},
|
},
|
||||||
moveDown: function () {
|
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');
|
return self.transitionTo('posts.index');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
setupController: function (controller, model) {
|
||||||
|
this._super(controller, model);
|
||||||
|
|
||||||
|
this.controllerFor('posts').set('currentPost', model);
|
||||||
|
},
|
||||||
|
|
||||||
shortcuts: {
|
shortcuts: {
|
||||||
'enter': 'openEditor'
|
'enter': 'openEditor'
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue