Skip to content

A platform for community discussion. Free, open, simple.

DEV: introduces setup for d-popover (#16720)

Joffrey JAFFEUXbc87c1bd5eb1
diff --git a/app/assets/javascripts/discourse/app/lib/d-popover.js b/app/assets/javascripts/discourse/app/lib/d-popover.js
index 0162bf2a013..052ae5c2018 100644
--- a/app/assets/javascripts/discourse/app/lib/d-popover.js
+++ b/app/assets/javascripts/discourse/app/lib/d-popover.js
@@ -26,15 +26,38 @@ export const hideOnEscapePlugin = {
},
};
+// legacy, shouldn't be needed with setup
export function hidePopover(event) {
if (event?.target?._tippy) {
showPopover(event);
}
}
+// legacy, setup() should be used
+export function showPopover(event, options = {}) {
+ const instance = event.target._tippy
+ ? event.target._tippy
+ : setup(event.target, options);
+
+ // hangs on legacy ember
+ if (!isLegacyEmber) {
+ run.begin();
+ instance.popper.addEventListener("transitionend", run.end, {
+ once: true,
+ });
+ }
+
+ if (instance.state.isShown) {
+ instance.hide();
+ } else {
+ instance.show();
+ }
+}
+
+// target is the element that triggers the display of the popover
// options accepts all tippy.js options as defined in their documentation
// https://atomiks.github.io/tippyjs/v6/all-props/
-export function showPopover(event, options = {}) {
+export default function setup(target, options) {
const tippyOptions = Object.assign(
{
arrow: iconHTML("tippy-rounded-arrow"),
@@ -44,6 +67,7 @@ export function showPopover(event, options = {}) {
hideOnClick: true,
zIndex: 1400,
plugins: [hideOnEscapePlugin],
+ touch: ["hold", 500],
},
options
);
@@ -52,21 +76,5 @@ export function showPopover(event, options = {}) {
delete tippyOptions.textContent;
delete tippyOptions.htmlContent;
- const instance = event.target._tippy
- ? event.target._tippy
- : tippy(event.target, tippyOptions);
-
- // hangs on legacy ember
- if (!isLegacyEmber) {
- run.begin();
- instance.popper.addEventListener("transitionend", run.end, {
- once: true,
- });
- }
-
- if (instance.state.isShown) {
- instance.hide();
- } else {
- instance.show();
- }
+ return tippy(target, tippyOptions);
}