mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-29 15:12:58 +03:00
2f4f6db133
no issue - add ember-suave dependency - upgrade grunt-jscs dependency - add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc - separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc - standardize es6 usage across client
41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
import Ember from 'ember';
|
|
|
|
const {Mixin, run} = Ember;
|
|
|
|
export default Mixin.create({
|
|
isLoading: false,
|
|
triggerPoint: 100,
|
|
|
|
/**
|
|
* Determines if we are past a scroll point where we need to fetch the next page
|
|
* @param {object} event The scroll event
|
|
*/
|
|
checkScroll(event) {
|
|
let element = event.target;
|
|
let triggerPoint = this.get('triggerPoint');
|
|
let isLoading = this.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;
|
|
}
|
|
|
|
this.sendAction('fetch');
|
|
},
|
|
|
|
didInsertElement() {
|
|
let el = this.get('element');
|
|
|
|
el.onscroll = run.bind(this, this.checkScroll);
|
|
|
|
if (el.scrollHeight <= el.clientHeight) {
|
|
this.sendAction('fetch');
|
|
}
|
|
},
|
|
|
|
willDestroyElement() {
|
|
// turn off the scroll handler
|
|
this.get('element').onscroll = null;
|
|
}
|
|
});
|