2022-02-07 19:53:12 +03:00
|
|
|
import Modifier from 'ember-modifier';
|
2022-08-02 11:23:43 +03:00
|
|
|
import {registerDestructor} from '@ember/destroyable';
|
2022-02-07 19:53:12 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class MovableModifier extends Modifier {
|
|
|
|
@service resizeDetector;
|
|
|
|
|
2022-08-02 11:23:43 +03:00
|
|
|
constructor(owner, args) {
|
|
|
|
super(owner, args);
|
|
|
|
registerDestructor(this, this.cleanup);
|
2022-02-07 19:53:12 +03:00
|
|
|
}
|
|
|
|
|
2022-08-02 11:23:43 +03:00
|
|
|
modify(element, [callback]) {
|
|
|
|
if (!this.didSetup) {
|
|
|
|
this.elem = element;
|
|
|
|
this.callback = callback;
|
|
|
|
|
|
|
|
this.resizeDetector.setup(element, callback);
|
|
|
|
|
|
|
|
this.didSetup = true;
|
|
|
|
}
|
2022-02-07 19:53:12 +03:00
|
|
|
}
|
2022-08-02 11:23:43 +03:00
|
|
|
|
|
|
|
cleanup = () => {
|
|
|
|
this.resizeDetector.teardown(this.elem, this.callback);
|
|
|
|
};
|
2022-02-07 19:53:12 +03:00
|
|
|
}
|