File size: 1,879 Bytes
2a1f177 |
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 |
// Utility functions
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);
}
// Form handling
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> ืืข ืืขืื...';
// Simulate form submission
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;
}
});
});
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
setupForms();
// Set active nav link
const currentPath = window.location.pathname;
document.querySelectorAll('.nav-links a').forEach(link => {
if (link.getAttribute('href') === currentPath) {
link.classList.add('active');
}
});
}); |