FIX: popover should use target when no data attributes

FIX: popover should use target when no data attributes

diff --git a/app/assets/javascripts/discourse/initializers/d-popover.js.es6 b/app/assets/javascripts/discourse/initializers/d-popover.js.es6
index d27837d..ffed73a 100644
--- a/app/assets/javascripts/discourse/initializers/d-popover.js.es6
+++ b/app/assets/javascripts/discourse/initializers/d-popover.js.es6
@@ -1,7 +1,8 @@
-import { showPopover, hidePopover } from "discourse/lib/d-popover";
-
-const SELECTORS =
-  "[data-html-popover],[data-tooltip],[data-popover],[data-html-tooltip]";
+import {
+  showPopover,
+  hidePopover,
+  POPOVER_SELECTORS
+} from "discourse/lib/d-popover";
 
 export default {
   name: "d-popover",
@@ -10,12 +11,8 @@ export default {
     const router = container.lookup("router:main");
     router.on("routeWillChange", hidePopover);
 
-    $("#main").on("click.d-popover mouseenter.d-popover", SELECTORS, event =>
-      showPopover(event)
-    );
-
-    $("#main").on("mouseleave.d-popover", SELECTORS, event =>
-      hidePopover(event)
-    );
+    $("#main")
+      .on("click.d-popover mouseenter.d-popover", POPOVER_SELECTORS, e => showPopover(e))
+      .on("mouseleave.d-popover", POPOVER_SELECTORS, e => hidePopover(e));
   }
 };
diff --git a/app/assets/javascripts/discourse/lib/d-popover.js.es6 b/app/assets/javascripts/discourse/lib/d-popover.js.es6
index a1a7076..597d472 100644
--- a/app/assets/javascripts/discourse/lib/d-popover.js.es6
+++ b/app/assets/javascripts/discourse/lib/d-popover.js.es6
@@ -16,6 +16,8 @@ const D_ARROW_HEIGHT = 10;
 
 const D_HORIZONTAL_MARGIN = 5;
 
+export const POPOVER_SELECTORS = "[data-html-popover], [data-html-tooltip], [data-popover], [data-tooltip]";
+
 export function hidePopover() {
   getPopover()
     .fadeOut()
@@ -25,7 +27,13 @@ export function hidePopover() {
 }
 
 export function showPopover(event, options = {}) {
-  const $enteredElement = $(event.currentTarget);
+  let $enteredElement = $(event.target)
+    .closest(POPOVER_SELECTORS)
+    .first();
+
+  if (!$enteredElement.length) {
+    $enteredElement = $(event.target);
+  }
 
   if (isRetina()) {
     getPopover().addClass("retina");

GitHub sha: 0cc81f95

1 Like