Files
e-ticket/assets/modules/share.js
Serreau Jovann 4e49553c3d Remove console.error in share.js (ESLint no-console)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-23 18:45:22 +01:00

30 lines
909 B
JavaScript

/**
* Handles the click event to copy text and toggle the button icon.
* @param {PointerEvent} event
*/
async function handleCopyClick(event) {
const btn = event.currentTarget;
const url = btn.dataset.shareCopy;
try {
await globalThis.navigator.clipboard.writeText(url);
// Swap UI state
const original = btn.innerHTML;
btn.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>';
setTimeout(() => {
btn.innerHTML = original;
}, 1500);
} catch {
// Clipboard API not available
}
}
export function initShare() {
const shareButtons = document.querySelectorAll('[data-share-copy]');
shareButtons.forEach(btn => {
btn.addEventListener('click', handleCopyClick);
});
}