2018-04-30 19:03:29 +03:00
|
|
|
import Service from '@ember/service';
|
2022-02-03 01:11:11 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
2019-01-22 16:09:38 +03:00
|
|
|
import erd from 'element-resize-detector';
|
2018-04-30 19:03:29 +03:00
|
|
|
|
2022-02-03 01:11:11 +03:00
|
|
|
@classic
|
|
|
|
export default class ResizeDetectorService extends Service {
|
2018-04-30 19:03:29 +03:00
|
|
|
init() {
|
2022-02-03 01:11:11 +03:00
|
|
|
super.init(...arguments);
|
2018-04-30 19:03:29 +03:00
|
|
|
this.detector = erd({
|
|
|
|
strategy: 'scroll'
|
|
|
|
});
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|
2018-04-30 19:03:29 +03:00
|
|
|
|
|
|
|
setup(selector, callback) {
|
|
|
|
let element = document.querySelector(selector);
|
|
|
|
if (!element) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
console.error(`service:resize-detector - could not find element matching ${selector}`);
|
|
|
|
}
|
|
|
|
this.detector.listenTo(element, callback);
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|
2018-04-30 19:03:29 +03:00
|
|
|
|
|
|
|
teardown(selector, callback) {
|
|
|
|
let element = document.querySelector(selector);
|
|
|
|
if (element) {
|
|
|
|
this.detector.removeListener(element, callback);
|
|
|
|
}
|
|
|
|
}
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|