File size: 1,972 Bytes
6bbf181 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | // 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);
} |