mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-12 06:25:51 +03:00
577a749e12
no issue - followed the migration guide to switch to from lifecycle hooks to single `modify()` method - https://togithub.com/ember-modifier/ember-modifier/blob/master/MIGRATIONS.md - forced resolution of `ember-in-viewport@4.0.2` to avoid older version of `ember-modifier` being pulled in through `ember-infinity`
32 lines
897 B
JavaScript
32 lines
897 B
JavaScript
import Modifier from 'ember-modifier';
|
|
import {action} from '@ember/object';
|
|
import {registerDestructor} from '@ember/destroyable';
|
|
|
|
export default class OnScrollModifier extends Modifier {
|
|
constructor(owner, args) {
|
|
super(owner, args);
|
|
registerDestructor(this, this.cleanup);
|
|
}
|
|
|
|
modify(element, [callback], named) {
|
|
this.elem = element;
|
|
this.callback = callback;
|
|
this.scrollContainer = element;
|
|
|
|
if (named.scrollContainer) {
|
|
this.scrollContainer = element.closest(named.scrollContainer);
|
|
}
|
|
|
|
this.scrollContainer?.addEventListener('scroll', this.onScroll, {passive: true});
|
|
}
|
|
|
|
cleanup = () => {
|
|
this.scrollContainer?.removeEventListener('scroll', this.onScroll, {passive: true});
|
|
};
|
|
|
|
@action
|
|
onScroll(event) {
|
|
this.callback(this.elem, this.scrollContainer, event);
|
|
}
|
|
}
|