Flatlogic Bot c8018254dd V5
2025-10-28 08:22:29 +00:00

84 lines
2.4 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
"use strict";
/**
* Header scroll class
*/
const selectHeader = document.querySelector('.header');
if (selectHeader) {
const headerScrolled = () => {
if (window.scrollY > 100) {
selectHeader.classList.add('header-scrolled');
} else {
selectHeader.classList.remove('header-scrolled');
}
}
window.addEventListener('load', headerScrolled);
document.addEventListener('scroll', headerScrolled);
}
/**
* Contact form submission
*/
const contactForm = document.querySelector('.php-email-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const action = this.getAttribute('action');
fetch(action, {
method: 'POST',
body: formData,
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
showToast('Success', 'Your message has been sent successfully!', 'success');
contactForm.reset();
} else {
showToast('Error', data.error || 'An error occurred. Please try again.', 'danger');
}
})
.catch(error => {
showToast('Error', 'A network error occurred. Please try again.', 'danger');
});
});
}
/**
* Toast notification handler
*/
function showToast(title, message, type) {
const toastContainer = document.getElementById('toast-container');
if (!toastContainer) return;
const toastId = 'toast-' + Date.now();
const toastHTML = `
<div id="${toastId}" class="toast align-items-center text-white bg-${type} border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<strong>${title}:</strong> ${message}
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
`;
toastContainer.insertAdjacentHTML('beforeend', toastHTML);
const toastElement = document.getElementById(toastId);
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
toast.show();
toastElement.addEventListener('hidden.bs.toast', () => {
toastElement.remove();
});
}
});