2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-07-20 20:42:03 +04:00
|
|
|
var PaginationViewInfiniteScrollMixin = Ember.Mixin.create({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if we are past a scroll point where we need to fetch the next page
|
2014-10-25 01:09:50 +04:00
|
|
|
* @param {object} event The scroll event
|
2014-07-20 20:42:03 +04:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2014-09-10 05:22:11 +04:00
|
|
|
attachCheckScroll: function () {
|
2015-01-07 02:16:16 +03:00
|
|
|
var el = this.$(),
|
|
|
|
controller = this.get('controller');
|
2014-07-20 20:42:03 +04:00
|
|
|
|
|
|
|
el.on('scroll', Ember.run.bind(this, this.checkScroll));
|
2015-01-07 02:16:16 +03:00
|
|
|
|
|
|
|
if (this.element.scrollHeight <= this.element.clientHeight) {
|
|
|
|
controller.send('loadNextPage');
|
|
|
|
}
|
2014-09-10 05:22:11 +04:00
|
|
|
}.on('didInsertElement'),
|
2014-07-20 20:42:03 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind from the scroll event when the element is no longer in the DOM
|
|
|
|
*/
|
2014-09-10 05:22:11 +04:00
|
|
|
detachCheckScroll: function () {
|
2014-07-20 20:42:03 +04:00
|
|
|
var el = this.$();
|
|
|
|
el.off('scroll');
|
2014-09-10 05:22:11 +04:00
|
|
|
}.on('willDestroyElement')
|
2014-07-20 20:42:03 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default PaginationViewInfiniteScrollMixin;
|