mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
7a56ded8d0
Merged About and What's new? page.
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import getScrollParent from '../utils/get-scroll-parent';
|
|
import {action} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
export default class GhScrollTrigger extends Component {
|
|
@service inViewport;
|
|
|
|
@action
|
|
setupInViewport(element) {
|
|
this.loaderElement = element;
|
|
|
|
let viewportTolerance = this.args.triggerOffset || {};
|
|
|
|
// if triggerOffset is a number we use it for all dimensions
|
|
if (typeof viewportTolerance === 'number') {
|
|
viewportTolerance = {
|
|
top: viewportTolerance,
|
|
bottom: viewportTolerance,
|
|
left: viewportTolerance,
|
|
right: viewportTolerance
|
|
};
|
|
}
|
|
|
|
let options = {
|
|
viewportSpy: true,
|
|
viewportTolerance,
|
|
scrollableArea: this.args.scrollable || getScrollParent(element)
|
|
};
|
|
|
|
let {onEnter, onExit} = this.inViewport.watchElement(element, options);
|
|
|
|
onEnter(this.didEnterViewport.bind(this));
|
|
onExit(this.didExitViewport.bind(this));
|
|
|
|
this.args.registerElement?.(element);
|
|
}
|
|
|
|
didEnterViewport() {
|
|
this.args.enter?.();
|
|
}
|
|
|
|
didExitViewport() {
|
|
this.args.exit?.();
|
|
}
|
|
|
|
@action
|
|
teardownInViewport(element) {
|
|
this.inViewport.stopWatching(element);
|
|
}
|
|
}
|