2014-06-07 23:07:25 +04:00
|
|
|
import setScrollClassName from 'ghost/utils/set-scroll-classname';
|
|
|
|
|
2014-05-24 07:25:20 +04:00
|
|
|
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.$();
|
2014-06-07 23:07:25 +04:00
|
|
|
el.on('scroll', Ember.run.bind(this, this.checkScroll));
|
|
|
|
el.on('scroll', Ember.run.bind(el, setScrollClassName, {
|
|
|
|
target: el.closest('.content-list'),
|
|
|
|
offset: 10
|
|
|
|
}));
|
2014-05-24 07:25:20 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement: function () {
|
|
|
|
var el = this.$();
|
2014-06-07 23:07:25 +04:00
|
|
|
el.off('scroll');
|
2014-05-24 07:25:20 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default PostsListView;
|