40161-vm/assets/js/main.js
Flatlogic Bot 7e76255737 0
2026-05-29 14:48:07 +00:00

44 lines
1.5 KiB
JavaScript

document.addEventListener('DOMContentLoaded', () => {
const toastEl = document.getElementById('siteToast');
const showToast = (message) => {
if (!toastEl || !window.bootstrap) return;
const body = toastEl.querySelector('.toast-body');
if (body) body.textContent = message;
window.bootstrap.Toast.getOrCreateInstance(toastEl, { delay: 3600 }).show();
};
document.querySelectorAll('a[href^="#"]').forEach((link) => {
link.addEventListener('click', (event) => {
const target = document.querySelector(link.getAttribute('href'));
if (!target) return;
event.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
history.pushState(null, '', link.getAttribute('href'));
});
});
document.querySelectorAll('.needs-validation').forEach((form) => {
form.addEventListener('submit', (event) => {
if (!form.checkValidity()) {
event.preventDefault();
event.stopPropagation();
showToast('Please review the highlighted fields before submitting.');
}
form.classList.add('was-validated');
});
});
if (window.location.hash === '#quote') {
const firstInvalid = document.querySelector('.is-invalid');
if (firstInvalid) {
firstInvalid.focus({ preventScroll: true });
showToast('A few fields need attention.');
}
}
const url = new URL(window.location.href);
if (url.searchParams.get('saved') === '1') {
showToast('Lead updated.');
}
});