remove popover's document click handler, related to #2561 (#2570)

* popover memory leak fix

* actual fix
This commit is contained in:
badpunman 2017-01-23 08:21:25 +02:00 committed by 杨奕
parent 1f53559c20
commit 36bed61f97

View File

@ -60,15 +60,7 @@ export default {
}
if (this.trigger === 'click') {
on(reference, 'click', () => { this.showPopper = !this.showPopper; });
on(document, 'click', (e) => {
if (!this.$el ||
!reference ||
this.$el.contains(e.target) ||
reference.contains(e.target) ||
!popper ||
popper.contains(e.target)) return;
this.showPopper = false;
});
on(document, 'click', this.handleDocumentClick);
} else if (this.trigger === 'hover') {
on(reference, 'mouseenter', this.handleMouseEnter);
on(popper, 'mouseenter', this.handleMouseEnter);
@ -111,6 +103,21 @@ export default {
this._timer = setTimeout(() => {
this.showPopper = false;
}, 200);
},
handleDocumentClick(e) {
let reference = this.reference || this.$refs.reference;
const popper = this.popper || this.$refs.popper;
if (!reference && this.$slots.reference && this.$slots.reference[0]) {
reference = this.referenceElm = this.$slots.reference[0].elm;
}
if (!this.$el ||
!reference ||
this.$el.contains(e.target) ||
reference.contains(e.target) ||
!popper ||
popper.contains(e.target)) return;
this.showPopper = false;
}
},
@ -123,6 +130,7 @@ export default {
off(reference, 'blur');
off(reference, 'mouseleave');
off(reference, 'mouseenter');
off(document, 'click', this.handleDocumentClick);
}
};
</script>