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, target: null,
outsideClickListener: null, outsideClickListener: null,
resizeListener: null,
beforeDestroy() { beforeDestroy() {
this.restoreAppend(); this.restoreAppend();
this.unbindResizeListener();
if (this.dismissable) { if (this.dismissable) {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
} }
@ -65,19 +67,16 @@ export default {
onEnter() { onEnter() {
this.appendContainer(); this.appendContainer();
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener();
if (this.dismissable) { this.bindResizeListener();
this.bindOutsideClickListener();
}
if (this.autoZIndex) { if (this.autoZIndex) {
this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex()); this.$refs.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
} }
}, },
onLeave() { onLeave() {
if (this.dismissable) { this.unbindOutsideClickListener();
this.unbindOutsideClickListener(); this.unbindResizeListener();
}
}, },
alignOverlay() { alignOverlay() {
DomHandler.absolutePosition(this.$refs.container, this.target); DomHandler.absolutePosition(this.$refs.container, this.target);
@ -102,6 +101,23 @@ export default {
this.outsideClickListener = null; 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() { isTargetClicked() {
return this.target && (this.target === event.target || this.target.contains(event.target)); return this.target && (this.target === event.target || this.target.contains(event.target));
}, },