Ghost/ghost/admin/app/modifiers/on-scroll.js
Kevin Ansfield 99bfde4417 Converted <GhCanvasHeader> to glimmer component
no issue

- added `{{on-scroll}}` modifier to replace custom setup and teardown of event handlers inside the component
2022-05-25 10:07:11 +01:00

24 lines
683 B
JavaScript

import Modifier from 'ember-modifier';
import {action} from '@ember/object';
export default class OnScrollModifier extends Modifier {
@action
onScroll(event) {
this.args.positional[0](this.element, this.scrollContainer, event);
}
didInstall() {
this.scrollContainer = this.element;
if (this.args.named.scrollContainer) {
this.scrollContainer = this.element.closest(this.args.named.scrollContainer);
}
this.scrollContainer?.addEventListener('scroll', this.onScroll, {passive: true});
}
willDestroy() {
this.scrollContainer?.removeEventListener('scroll', this.onScroll, {passive: true});
}
}