75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
|
|
const alerts = document.querySelectorAll('.js-autodismiss');
|
|
alerts.forEach((alertEl) => {
|
|
window.setTimeout(() => {
|
|
if (window.bootstrap && bootstrap.Alert) {
|
|
bootstrap.Alert.getOrCreateInstance(alertEl).close();
|
|
}
|
|
}, 3800);
|
|
});
|
|
|
|
const companySwitcher = document.querySelector('.js-company-switcher');
|
|
if (companySwitcher) {
|
|
companySwitcher.addEventListener('change', () => {
|
|
companySwitcher.form.submit();
|
|
});
|
|
}
|
|
|
|
const reasonInput = document.querySelector('.js-reason-input');
|
|
const reasonCount = document.querySelector('.js-reason-count');
|
|
if (reasonInput && reasonCount) {
|
|
const syncCount = () => {
|
|
reasonCount.textContent = String(reasonInput.value.length);
|
|
};
|
|
syncCount();
|
|
reasonInput.addEventListener('input', syncCount);
|
|
}
|
|
|
|
const dateInputs = document.querySelectorAll('.js-date-input');
|
|
const daysPreview = document.querySelector('.js-days-preview');
|
|
if (dateInputs.length === 2 && daysPreview) {
|
|
const syncDays = () => {
|
|
const [startInput, endInput] = dateInputs;
|
|
const start = startInput.value ? new Date(startInput.value) : null;
|
|
const end = endInput.value ? new Date(endInput.value) : null;
|
|
if (!start || !end || Number.isNaN(start.getTime()) || Number.isNaN(end.getTime()) || end < start) {
|
|
daysPreview.textContent = '0';
|
|
return;
|
|
}
|
|
const diffDays = Math.floor((end - start) / 86400000) + 1;
|
|
daysPreview.textContent = String(diffDays);
|
|
};
|
|
syncDays();
|
|
dateInputs.forEach((input) => input.addEventListener('input', syncDays));
|
|
dateInputs.forEach((input) => input.addEventListener('change', syncDays));
|
|
}
|
|
|
|
const revealTargets = document.querySelectorAll('.hero-panel, .metric-card, .panel-card, .toast-stack .alert');
|
|
revealTargets.forEach((element, index) => {
|
|
element.classList.add('js-reveal');
|
|
element.style.setProperty('--reveal-delay', `${Math.min(index * 70, 360)}ms`);
|
|
});
|
|
|
|
if (prefersReducedMotion || !('IntersectionObserver' in window)) {
|
|
revealTargets.forEach((element) => element.classList.add('is-visible'));
|
|
return;
|
|
}
|
|
|
|
const observer = new IntersectionObserver((entries, currentObserver) => {
|
|
entries.forEach((entry) => {
|
|
if (!entry.isIntersecting) {
|
|
return;
|
|
}
|
|
entry.target.classList.add('is-visible');
|
|
currentObserver.unobserve(entry.target);
|
|
});
|
|
}, {
|
|
threshold: 0.14,
|
|
rootMargin: '0px 0px -28px 0px'
|
|
});
|
|
|
|
revealTargets.forEach((element) => observer.observe(element));
|
|
});
|