Add resize listeners

pull/525/head
Cagatay Civici 2020-09-28 14:22:17 +03:00
parent 7b0ad66903
commit 8f866252dc
6 changed files with 109 additions and 9 deletions

View File

@ -81,6 +81,7 @@ export default {
}, },
timeout: null, timeout: null,
outsideClickListener: null, outsideClickListener: null,
resizeListener: null,
scrollHandler: null, scrollHandler: null,
overlay: null, overlay: null,
data() { data() {
@ -107,6 +108,7 @@ export default {
beforeUnmount() { beforeUnmount() {
this.restoreAppend(); this.restoreAppend();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindResizeListener();
if (this.scrollHandler) { if (this.scrollHandler) {
this.scrollHandler.destroy(); this.scrollHandler.destroy();
@ -121,10 +123,12 @@ export default {
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener(); this.bindOutsideClickListener();
this.bindScrollListener(); this.bindScrollListener();
this.bindResizeListener();
}, },
onOverlayLeave() { onOverlayLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindScrollListener(); this.unbindScrollListener();
this.unbindResizeListener();
this.overlay = null; this.overlay = null;
}, },
alignOverlay() { alignOverlay() {
@ -160,6 +164,22 @@ export default {
this.scrollHandler.unbindScrollListener(); this.scrollHandler.unbindScrollListener();
} }
}, },
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
if (this.overlayVisible) {
this.hideOverlay();
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
isOutsideClicked(event) { isOutsideClicked(event) {
return !this.overlay.contains(event.target) && !this.isInputClicked(event) && !this.isDropdownClicked(event); return !this.overlay.contains(event.target) && !this.isInputClicked(event) && !this.isDropdownClicked(event);
}, },

View File

@ -310,6 +310,13 @@ export default {
}, },
navigationState: null, navigationState: null,
scrollHandler: null, scrollHandler: null,
outsideClickListener: null,
maskClickListener: null,
resizeListener: null,
overlay: null,
mask: null,
timePickerTimer: null,
isKeydown: false,
created() { created() {
this.updateCurrentMetaData(); this.updateCurrentMetaData();
}, },
@ -342,6 +349,7 @@ export default {
this.restoreAppend(); this.restoreAppend();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindResizeListener();
if (this.scrollHandler) { if (this.scrollHandler) {
this.scrollHandler.destroy(); this.scrollHandler.destroy();
@ -361,12 +369,6 @@ export default {
overlayVisible: false overlayVisible: false
} }
}, },
outsideClickListener: null,
maskClickListener: null,
overlay: null,
mask: null,
timePickerTimer: null,
isKeydown: false,
watch: { watch: {
modelValue() { modelValue() {
this.updateCurrentMetaData(); this.updateCurrentMetaData();
@ -545,10 +547,12 @@ export default {
onOverlayEnterComplete() { onOverlayEnterComplete() {
this.bindOutsideClickListener(); this.bindOutsideClickListener();
this.bindScrollListener(); this.bindScrollListener();
this.bindResizeListener();
}, },
onOverlayLeave() { onOverlayLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindScrollListener(); this.unbindScrollListener();
this.unbindResizeListener();
this.$emit('hide'); this.$emit('hide');
this.overlay = null; this.overlay = null;
}, },
@ -663,6 +667,22 @@ export default {
this.scrollHandler.unbindScrollListener(); this.scrollHandler.unbindScrollListener();
} }
}, },
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
if (this.overlayVisible) {
this.overlayVisible = false;
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
isOutsideClicked(event) { isOutsideClicked(event) {
return !(this.$el.isSameNode(event.target) || this.isNavIconClicked(event) || return !(this.$el.isSameNode(event.target) || this.isNavIconClicked(event) ||
this.$el.contains(event.target) || (this.overlay && this.overlay.contains(event.target))); this.$el.contains(event.target) || (this.overlay && this.overlay.contains(event.target)));

View File

@ -72,6 +72,7 @@ export default {
documentMouseMoveListener: null, documentMouseMoveListener: null,
documentMouseUpListener: null, documentMouseUpListener: null,
scrollHandler: null, scrollHandler: null,
resizeListener: null,
hueDragging: null, hueDragging: null,
colorDragging: null, colorDragging: null,
selfUpdate: null, selfUpdate: null,
@ -84,6 +85,7 @@ export default {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindDocumentMouseMoveListener(); this.unbindDocumentMouseMoveListener();
this.unbindDocumentMouseUpListener(); this.unbindDocumentMouseUpListener();
this.unbindResizeListener();
if (this.scrollHandler) { if (this.scrollHandler) {
this.scrollHandler.destroy(); this.scrollHandler.destroy();
@ -331,6 +333,7 @@ export default {
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener(); this.bindOutsideClickListener();
this.bindScrollListener(); this.bindScrollListener();
this.bindResizeListener();
if (this.autoZIndex) { if (this.autoZIndex) {
this.picker.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex()); this.picker.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
@ -339,6 +342,7 @@ export default {
onOverlayLeave() { onOverlayLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindScrollListener(); this.unbindScrollListener();
this.unbindResizeListener();
this.clearRefs(); this.clearRefs();
}, },
alignOverlay() { alignOverlay() {
@ -427,6 +431,22 @@ export default {
this.scrollHandler.unbindScrollListener(); this.scrollHandler.unbindScrollListener();
} }
}, },
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
if (this.overlayVisible) {
this.overlayVisible = false;
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
bindDocumentMouseMoveListener() { bindDocumentMouseMoveListener() {
if (!this.documentMouseMoveListener) { if (!this.documentMouseMoveListener) {
this.documentMouseMoveListener = (event) => { this.documentMouseMoveListener = (event) => {

View File

@ -85,6 +85,7 @@ export default {
}, },
outsideClickListener: null, outsideClickListener: null,
scrollHandler: null, scrollHandler: null,
resizeListener: null,
searchTimeout: null, searchTimeout: null,
currentSearchChar: null, currentSearchChar: null,
previousSearchChar: null, previousSearchChar: null,
@ -93,6 +94,7 @@ export default {
beforeUnmount() { beforeUnmount() {
this.restoreAppend(); this.restoreAppend();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindResizeListener();
if (this.scrollHandler) { if (this.scrollHandler) {
this.scrollHandler.destroy(); this.scrollHandler.destroy();
@ -315,6 +317,7 @@ export default {
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener(); this.bindOutsideClickListener();
this.bindScrollListener(); this.bindScrollListener();
this.bindResizeListener();
if (this.filter) { if (this.filter) {
this.$refs.filterInput.focus(); this.$refs.filterInput.focus();
@ -325,6 +328,7 @@ export default {
onOverlayLeave() { onOverlayLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindScrollListener(); this.unbindScrollListener();
this.unbindResizeListener();
this.$emit('hide'); this.$emit('hide');
this.overlay = null; this.overlay = null;
}, },
@ -372,6 +376,22 @@ export default {
this.scrollHandler.unbindScrollListener(); this.scrollHandler.unbindScrollListener();
} }
}, },
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
if (this.overlayVisible) {
this.hide();
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
search(event) { search(event) {
if (!this.visibleOptions) { if (!this.visibleOptions) {
return; return;

View File

@ -98,11 +98,13 @@ export default {
}; };
}, },
outsideClickListener: null, outsideClickListener: null,
resizeListener: null,
scrollHandler: null, scrollHandler: null,
overlay: null, overlay: null,
beforeUnmount() { beforeUnmount() {
this.restoreAppend(); this.restoreAppend();
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindResizeListener();
if (this.scrollHandler) { if (this.scrollHandler) {
this.scrollHandler.destroy(); this.scrollHandler.destroy();
@ -283,11 +285,13 @@ export default {
this.alignOverlay(); this.alignOverlay();
this.bindOutsideClickListener(); this.bindOutsideClickListener();
this.bindScrollListener(); this.bindScrollListener();
this.bindResizeListener();
this.$emit('show'); this.$emit('show');
}, },
onOverlayLeave() { onOverlayLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindScrollListener(); this.unbindScrollListener();
this.unbindResizeListener();
this.$emit('hide'); this.$emit('hide');
this.overlay = null; this.overlay = null;
}, },
@ -332,6 +336,22 @@ export default {
this.scrollHandler.unbindScrollListener(); this.scrollHandler.unbindScrollListener();
} }
}, },
bindResizeListener() {
if (!this.resizeListener) {
this.resizeListener = () => {
if (this.overlayVisible) {
this.hide();
}
};
window.addEventListener('resize', this.resizeListener);
}
},
unbindResizeListener() {
if (this.resizeListener) {
window.removeEventListener('resize', this.resizeListener);
this.resizeListener = null;
}
},
isOutsideClicked(event) { isOutsideClicked(event) {
return !(this.$el.isSameNode(event.target) || this.$el.contains(event.target) || (this.overlay && this.overlay.contains(event.target))); return !(this.$el.isSameNode(event.target) || this.$el.contains(event.target) || (this.overlay && this.overlay.contains(event.target)));
}, },

View File

@ -55,7 +55,6 @@ export default {
container: null, container: null,
beforeUnmount() { beforeUnmount() {
this.restoreAppend(); this.restoreAppend();
this.unbindResizeListener();
if (this.dismissable) { if (this.dismissable) {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
} }
@ -64,6 +63,7 @@ export default {
this.scrollHandler.destroy(); this.scrollHandler.destroy();
this.scrollHandler = null; this.scrollHandler = null;
} }
this.unbindResizeListener();
this.target = null; this.target = null;
this.container = null; this.container = null;
}, },
@ -88,8 +88,8 @@ export default {
this.bindOutsideClickListener(); this.bindOutsideClickListener();
} }
this.bindResizeListener();
this.bindScrollListener(); this.bindScrollListener();
this.bindResizeListener();
if (this.autoZIndex) { if (this.autoZIndex) {
this.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex()); this.container.style.zIndex = String(this.baseZIndex + DomHandler.generateZIndex());
@ -97,8 +97,8 @@ export default {
}, },
onLeave() { onLeave() {
this.unbindOutsideClickListener(); this.unbindOutsideClickListener();
this.unbindResizeListener();
this.unbindScrollListener(); this.unbindScrollListener();
this.unbindResizeListener();
}, },
alignOverlay() { alignOverlay() {
DomHandler.absolutePosition(this.container, this.target); DomHandler.absolutePosition(this.container, this.target);