2020-09-27 15:27:08 +00:00
|
|
|
import DomHandler from './DomHandler';
|
|
|
|
|
|
|
|
export default class ConnectedOverlayScrollHandler {
|
2020-09-28 10:24:10 +00:00
|
|
|
constructor(element, listener = () => {}) {
|
2020-09-27 15:27:08 +00:00
|
|
|
this.element = element;
|
|
|
|
this.listener = listener;
|
|
|
|
}
|
|
|
|
|
|
|
|
bindScrollListener() {
|
|
|
|
this.scrollableParents = DomHandler.getScrollableParents(this.element);
|
2022-09-14 11:26:01 +00:00
|
|
|
|
2020-09-27 15:27:08 +00:00
|
|
|
for (let i = 0; i < this.scrollableParents.length; i++) {
|
2020-09-28 10:24:10 +00:00
|
|
|
this.scrollableParents[i].addEventListener('scroll', this.listener);
|
2020-09-27 15:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unbindScrollListener() {
|
|
|
|
if (this.scrollableParents) {
|
|
|
|
for (let i = 0; i < this.scrollableParents.length; i++) {
|
2020-09-28 10:24:10 +00:00
|
|
|
this.scrollableParents[i].removeEventListener('scroll', this.listener);
|
2020-09-27 15:27:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 10:24:10 +00:00
|
|
|
|
|
|
|
destroy() {
|
|
|
|
this.unbindScrollListener();
|
|
|
|
this.element = null;
|
|
|
|
this.listener = null;
|
|
|
|
this.scrollableParents = null;
|
|
|
|
}
|
2020-09-27 15:27:08 +00:00
|
|
|
}
|