/** * JavaScript principale della piattaforma */ // Esegui quando il DOM รจ caricato document.addEventListener('DOMContentLoaded', function() { // Auto-chiudi gli alert dopo 5 secondi const alerts = document.querySelectorAll('.alert'); alerts.forEach(function(alert) { setTimeout(function() { alert.style.transition = 'opacity 0.3s ease'; alert.style.opacity = '0'; setTimeout(function() { alert.remove(); }, 300); }, 5000); }); // Conferma eliminazione const deleteButtons = document.querySelectorAll('[data-confirm-delete]'); deleteButtons.forEach(function(button) { button.addEventListener('click', function(e) { if (!confirm('Sei sicuro di voler eliminare questo elemento?')) { e.preventDefault(); } }); }); // Scroll smooth per link con anchor document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function (e) { const href = this.getAttribute('href'); if (href !== '#' && href.length > 1) { e.preventDefault(); const target = document.querySelector(href); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } }); }); }); /** * Valida un form prima dell'invio */ function validateForm(formId) { const form = document.getElementById(formId); if (!form) return false; let isValid = true; const requiredFields = form.querySelectorAll('[required]'); requiredFields.forEach(function(field) { if (!field.value.trim()) { field.classList.add('error'); isValid = false; } else { field.classList.remove('error'); } }); return isValid; }