|
|
|
|
|
function showToast(message, type = 'success') { |
|
|
const toast = document.createElement('div'); |
|
|
toast.className = `toast toast-${type}`; |
|
|
toast.textContent = message; |
|
|
document.body.appendChild(toast); |
|
|
|
|
|
setTimeout(() => { |
|
|
toast.classList.add('show'); |
|
|
setTimeout(() => { |
|
|
toast.classList.remove('show'); |
|
|
setTimeout(() => toast.remove(), 300); |
|
|
}, 3000); |
|
|
}, 100); |
|
|
} |
|
|
|
|
|
|
|
|
function setupForms() { |
|
|
document.querySelectorAll('form').forEach(form => { |
|
|
form.addEventListener('submit', async (e) => { |
|
|
e.preventDefault(); |
|
|
const submitBtn = form.querySelector('button[type="submit"]'); |
|
|
const originalText = submitBtn.textContent; |
|
|
|
|
|
try { |
|
|
submitBtn.disabled = true; |
|
|
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> ืืข ืืขืื...'; |
|
|
|
|
|
|
|
|
await new Promise(resolve => setTimeout(resolve, 1500)); |
|
|
|
|
|
showToast('ืืืคืขืืื ืืืฆืขื ืืืฆืืื!', 'success'); |
|
|
form.reset(); |
|
|
} catch (error) { |
|
|
showToast('ืืืจืขื ืฉืืืื. ื ืกื ืฉืื.', 'danger'); |
|
|
console.error(error); |
|
|
} finally { |
|
|
submitBtn.disabled = false; |
|
|
submitBtn.textContent = originalText; |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => { |
|
|
setupForms(); |
|
|
|
|
|
|
|
|
const currentPath = window.location.pathname; |
|
|
document.querySelectorAll('.nav-links a').forEach(link => { |
|
|
if (link.getAttribute('href') === currentPath) { |
|
|
link.classList.add('active'); |
|
|
} |
|
|
}); |
|
|
}); |