carhop__dynamiques-theme__P.../resources/js/singles/share-button.ts
Nonimart 0618304ddc
All checks were successful
continuous-integration/drone/push Build is passing
FEATURE Handling the share copy link and removing twitter
2025-10-21 10:24:13 +02:00

37 lines
1021 B
TypeScript

export default function handleShareButton() {
const shareButton = document.querySelector('.socials-buttons__button--share');
if (!shareButton) return;
shareButton.addEventListener('click', () => {
const isOpen = shareButton.classList.contains('is-open');
if (!isOpen) {
shareButton.classList.add('is-open');
} else {
shareButton.classList.remove('is-open');
}
});
handleCopyLinkButton();
}
function handleCopyLinkButton() {
const copyLinkButton = document.querySelector('.share-button--copy-link a');
if (!copyLinkButton) return;
copyLinkButton.addEventListener('click', (e) => {
e.preventDefault();
const url = copyLinkButton.getAttribute('data-url');
if (!url) return;
navigator.clipboard.writeText(url);
const notyf = new Notyf({
duration: 4000,
ripple: false,
dismissible: true,
position: {
x: 'right',
y: 'top',
},
});
notyf.success('Lien copié !');
});
}