Ghost/ghost/admin/views/content-list-content-view.js
David Arvelo 6ab475860d Infinite Scroll on Posts List
closes #2414
- Add PostsController with loadNextPage action
- Collect and store pagination info from PostsRoute into PostsController
- Use `store.filter` on PostsRoute model hook to auto-update posts list template as post models are added to the store
- Add content list view and use it to check for scroll event
- Make PostRoute only load a post that's already in the store, until we figure how to load multiple pages on refresh
- Add util function from clientold that concats error messages from server response
2014-05-30 22:14:45 -04:00

30 lines
805 B
JavaScript

var PostsListView = Ember.View.extend({
classNames: ['content-list-content'],
checkScroll: function (event) {
var element = event.target,
triggerPoint = 100,
controller = this.get('controller'),
isLoading = controller.get('isLoading');
// If we haven't passed our threshold, exit
if (isLoading || (element.scrollTop + element.clientHeight + triggerPoint <= element.scrollHeight)) {
return;
}
controller.send('loadNextPage');
},
didInsertElement: function () {
var el = this.$();
el.bind('scroll', Ember.run.bind(this, this.checkScroll));
},
willDestroyElement: function () {
var el = this.$();
el.unbind('scroll');
}
});
export default PostsListView;