Skip to content

Commit 95080b1

Browse files
committed
IBX-10081: copy link on share dialog doesnt work on safari
1 parent 552fcfa commit 95080b1

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/bundle/Resources/public/js/scripts/helpers/browser.helper.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,24 @@ const isEdge = () => userAgent.includes('Edg'); // Edge previously had Edge but
33
const isChrome = () => userAgent.includes('Chrome') && !isEdge();
44
const isFirefox = () => userAgent.includes('Firefox');
55
const isSafari = () => userAgent.includes('Safari') && !isChrome() && !isEdge();
6+
const checkIsClipboardWriteSupported = async () => {
7+
if (!navigator.clipboard?.writeText) {
8+
return false;
9+
}
610

7-
export { isChrome, isFirefox, isSafari, isEdge };
11+
const isClipboardWriteSupported = await checkGrantedPermissions('clipboard-write');
12+
13+
return isClipboardWriteSupported;
14+
};
15+
const checkGrantedPermissions = async (permissionName) => {
16+
try {
17+
const result = await navigator.permissions.query({ name: permissionName });
18+
19+
return result.state === 'granted';
20+
} catch (error) {
21+
console.warn(`Permission check failed for "${permissionName}":`, error.message);
22+
return false;
23+
}
24+
};
25+
26+
export { isChrome, isFirefox, isSafari, isEdge, checkIsClipboardWriteSupported };

src/bundle/Resources/public/js/scripts/helpers/tooltips.helper.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ import { getBootstrap } from './context.helper';
44
const { document: doc } = window;
55

66
const TOOLTIPS_SELECTOR = '[title], [data-tooltip-title]';
7+
const TOOLTIPS_DEFAULTS_PARAMS = {
8+
delay: {
9+
show: 150,
10+
hide: 75,
11+
},
12+
placement: 'bottom',
13+
trigger: 'hover',
14+
useHtml: false,
15+
template: (extraClass = '') => `<div class="tooltip ibexa-tooltip ${extraClass}">
16+
<div class="tooltip-arrow ibexa-tooltip__arrow"></div>
17+
<div class="tooltip-inner ibexa-tooltip__inner"></div>
18+
</div>`,
19+
};
720
const observerConfig = {
821
childList: true,
922
subtree: true,
@@ -130,15 +143,21 @@ const getContainer = (tooltipNode) => {
130143
return container ?? doc.body;
131144
};
132145
const initializeTooltip = (tooltipNode, hasEllipsisStyle) => {
146+
const {
147+
delay: defaultDelay,
148+
placement: defaultPlacement,
149+
trigger: defaultTrigger,
150+
template: defaultTemplate,
151+
} = TOOLTIPS_DEFAULTS_PARAMS;
133152
const { delayShow, delayHide } = tooltipNode.dataset;
134153
const delay = {
135-
show: delayShow ? parseInt(delayShow, 10) : 150,
136-
hide: delayHide ? parseInt(delayHide, 10) : 75,
154+
show: delayShow ? parseInt(delayShow, 10) : defaultDelay.show,
155+
hide: delayHide ? parseInt(delayHide, 10) : defaultDelay.hide,
137156
};
138157
const { title } = tooltipNode;
139158
const extraClass = tooltipNode.dataset.tooltipExtraClass ?? '';
140-
const placement = tooltipNode.dataset.tooltipPlacement ?? 'bottom';
141-
const trigger = tooltipNode.dataset.tooltipTrigger ?? 'hover';
159+
const placement = tooltipNode.dataset.tooltipPlacement ?? defaultPlacement;
160+
const trigger = tooltipNode.dataset.tooltipTrigger ?? defaultTrigger;
142161
const useHtml = tooltipNode.dataset.tooltipUseHtml !== undefined;
143162
const container = getContainer(tooltipNode);
144163
const iframe = document.querySelector(tooltipNode.dataset.tooltipIframeSelector);
@@ -150,10 +169,7 @@ const initializeTooltip = (tooltipNode, hasEllipsisStyle) => {
150169
container,
151170
popperConfig: modifyPopperConfig.bind(null, iframe),
152171
html: useHtml,
153-
template: `<div class="tooltip ibexa-tooltip ${extraClass}">
154-
<div class="tooltip-arrow ibexa-tooltip__arrow"></div>
155-
<div class="tooltip-inner ibexa-tooltip__inner"></div>
156-
</div>`,
172+
template: defaultTemplate(extraClass),
157173
});
158174

159175
if (isSafari()) {
@@ -241,4 +257,4 @@ const observe = (baseElement = doc) => {
241257
observer.observe(baseElement, observerConfig);
242258
};
243259

244-
export { parse, hideAll, observe };
260+
export { parse, hideAll, observe, TOOLTIPS_DEFAULTS_PARAMS };

0 commit comments

Comments
 (0)