Resize listener for OverlayPanel

pull/12/head
cagataycivici 2019-02-04 09:58:05 +03:00
parent 65562cda09
commit 3231c569ed
1 changed files with 24 additions and 8 deletions

View File

@ -41,8 +41,10 @@ export default {
},
target: null,
outsideClickListener: null,
resizeListener: null,
beforeDestroy() {
this.restoreAppend();
this.unbindResizeListener();
if (this.dismissable) {
this.unbindOutsideClickListener();
}
@ -65,19 +67,16 @@ export default {
onEnter() {
this.appendContainer();
this.alignOverlay();
if (this.dismissable) {
this.bindOutsideClickListener();
}
this.bindOutsideClickListener();
this.bindResizeListener();
if (this.autoZIndex) {
this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
}
},
onLeave() {
if (this.dismissable) {
this.unbindOutsideClickListener();
}
this.unbindOutsideClickListener();
this.unbindResizeListener();
},
alignOverlay() {
DomHandler.absolutePosition(this.$refs.container, this.target);
@ -102,6 +101,23 @@ export default {
this.outsideClickListener = null;
}
},
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = (event) => {
console.log('x');
if (this.visible) {
this.visible = false;
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
isTargetClicked() {
return this.target && (this.target === event.target || this.target.contains(event.target));
},