65 lines
2.6 KiB
JavaScript
65 lines
2.6 KiB
JavaScript
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Smooth scroll for navigation links
|
|
const navLinks = document.querySelectorAll('.nav-link');
|
|
navLinks.forEach(link => {
|
|
if (link.hash !== '') {
|
|
link.addEventListener('click', function (e) {
|
|
e.preventDefault();
|
|
const target = document.querySelector(this.hash);
|
|
if (target) {
|
|
window.scrollTo({
|
|
top: target.offsetTop - 70, // Adjust for fixed navbar
|
|
behavior: 'smooth'
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// Contact form submission
|
|
const contactForm = document.getElementById('contactForm');
|
|
const toastContainer = document.getElementById('notificationToast');
|
|
const toastBody = document.querySelector('#notificationToast .toast-body');
|
|
const toast = new bootstrap.Toast(toastContainer);
|
|
|
|
if (contactForm) {
|
|
contactForm.addEventListener('submit', function (e) {
|
|
e.preventDefault();
|
|
const formData = new FormData(this);
|
|
const submitButton = this.querySelector('button[type="submit"]');
|
|
submitButton.disabled = true;
|
|
submitButton.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Sending...';
|
|
|
|
fetch('contact_handler.php', {
|
|
method: 'POST',
|
|
body: formData
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
toastBody.textContent = 'Message sent successfully! Thank you.';
|
|
toastContainer.classList.remove('bg-danger');
|
|
toastContainer.classList.add('bg-success');
|
|
contactForm.reset();
|
|
} else {
|
|
toastBody.textContent = data.error || 'An unknown error occurred.';
|
|
toastContainer.classList.remove('bg-success');
|
|
toastContainer.classList.add('bg-danger');
|
|
}
|
|
toast.show();
|
|
})
|
|
.catch(error => {
|
|
toastBody.textContent = 'A network error occurred. Please try again.';
|
|
toastContainer.classList.remove('bg-success');
|
|
toastContainer.classList.add('bg-danger');
|
|
toast.show();
|
|
})
|
|
.finally(() => {
|
|
submitButton.disabled = false;
|
|
submitButton.innerHTML = 'Send Message';
|
|
});
|
|
});
|
|
}
|
|
});
|