mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
99bfde4417
no issue - added `{{on-scroll}}` modifier to replace custom setup and teardown of event handlers inside the component
24 lines
683 B
JavaScript
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});
|
|
}
|
|
}
|