smartstudy-buddyhub / script.js
itamarlifshitz's picture
make the site look bettrer and every button working and doing its job
2a1f177 verified
raw
history blame
1.88 kB
// 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');
}
});
});