Browse Source

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

* popover memory leak fix

* actual fix
badpunman 8 years ago
parent
commit
36bed61f97
1 changed files with 17 additions and 9 deletions
  1. 17 9
      packages/popover/src/main.vue

+ 17 - 9
packages/popover/src/main.vue

@@ -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>