// Shared utility functions document.addEventListener('DOMContentLoaded', function() { // Initialize tooltips const tooltipTriggers = document.querySelectorAll('[data-tooltip]'); tooltipTriggers.forEach(trigger => { trigger.addEventListener('mouseenter', showTooltip); trigger.addEventListener('mouseleave', hideTooltip); }); // Initialize copy buttons const copyButtons = document.querySelectorAll('[data-copy]'); copyButtons.forEach(button => { button.addEventListener('click', copyToClipboard); }); }); function showTooltip(e) { const tooltipText = this.getAttribute('data-tooltip'); const tooltip = document.createElement('div'); tooltip.className = 'absolute z-10 bg-gray-800 text-white text-sm px-2 py-1 rounded'; tooltip.textContent = tooltipText; this.appendChild(tooltip); // Position tooltip const rect = this.getBoundingClientRect(); tooltip.style.left = `${rect.width / 2 - tooltip.offsetWidth / 2}px`; tooltip.style.bottom = `${rect.height + 5}px`; } function hideTooltip() { const tooltip = this.querySelector('div[class*="bg-gray-800"]'); if (tooltip) { this.removeChild(tooltip); } } async function copyToClipboard() { const textToCopy = this.getAttribute('data-copy'); try { await navigator.clipboard.writeText(textToCopy); showToast('✓ Copié dans le presse-papier'); } catch (err) { showToast('✗ Échec de la copie'); } } function showToast(message) { const toast = document.createElement('div'); toast.className = 'fixed bottom-4 right-4 bg-gray-800 text-white px-4 py-2 rounded-lg shadow-lg'; toast.textContent = message; document.body.appendChild(toast); setTimeout(() => { toast.classList.add('opacity-0', 'transition-opacity', 'duration-300'); setTimeout(() => { document.body.removeChild(toast); }, 300); }, 2000); }