2018-04-30 19:03:29 +03:00
|
|
|
import Service from '@ember/service';
|
2019-01-22 16:09:38 +03:00
|
|
|
import erd from 'element-resize-detector';
|
2018-04-30 19:03:29 +03:00
|
|
|
|
|
|
|
export default Service.extend({
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.detector = erd({
|
|
|
|
strategy: 'scroll'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
teardown(selector, callback) {
|
|
|
|
let element = document.querySelector(selector);
|
|
|
|
if (element) {
|
|
|
|
this.detector.removeListener(element, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|