Ghost/core/client/mixins/pagination-view-infinite-scroll.js
Maurice Williams a8ca517c54 Pagination for Users Management screen
closes #3222
- implementing server-side pagination for /users API
- passing /users?limit=none will return all users
- passing /users?status=invited will filter base on user status
- creating 3 mixins (route, controller and view) to keep pagination logic DRY
- updating route, controller and view for Posts to use new mixing
- implementing infinite scrolling for Users Management screen (using new mixins)
- Users Management screen displays all invited users, but paginates active users
2014-07-21 14:03:26 -04:00

40 lines
1.1 KiB
JavaScript

var PaginationViewInfiniteScrollMixin = Ember.Mixin.create({
/**
* Determines if we are past a scroll point where we need to fetch the next page
* @param event The scroll event
*/
checkScroll: function (event) {
var element = event.target,
triggerPoint = 100,
controller = this.get('controller'),
isLoading = controller.get('isLoading');
// If we haven't passed our threshold or we are already fetching content, exit
if (isLoading || (element.scrollTop + element.clientHeight + triggerPoint <= element.scrollHeight)) {
return;
}
controller.send('loadNextPage');
},
/**
* Bind to the scroll event once the element is in the DOM
*/
didInsertElement: function () {
var el = this.$();
el.on('scroll', Ember.run.bind(this, this.checkScroll));
},
/**
* Unbind from the scroll event when the element is no longer in the DOM
*/
willDestroyElement: function () {
var el = this.$();
el.off('scroll');
}
});
export default PaginationViewInfiniteScrollMixin;