2025-04-14 14:27:22 -04:00
|
|
|
// Initialize GOV.UK Frontend components (modern init)
|
|
|
|
|
window.GOVUKFrontend.initAll();
|
2016-09-28 17:47:40 +01:00
|
|
|
|
2018-08-09 11:59:05 +01:00
|
|
|
var showHideContent = new GOVUK.ShowHideContent();
|
|
|
|
|
showHideContent.init();
|
|
|
|
|
|
2025-04-14 14:27:22 -04:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
// Autofocus the first error input
|
|
|
|
|
const errorEl = document.querySelector('.error-message, .usa-error-message');
|
|
|
|
|
if (errorEl) {
|
|
|
|
|
const label = errorEl.closest('label');
|
|
|
|
|
if (label) {
|
|
|
|
|
const input = label.nextElementSibling;
|
|
|
|
|
if (input && input.focus) {
|
|
|
|
|
input.focus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-08 11:07:57 +00:00
|
|
|
|
2025-04-14 14:27:22 -04:00
|
|
|
// Optional: highlight header on click
|
|
|
|
|
const header = document.querySelector('.govuk-header__container');
|
|
|
|
|
if (header) {
|
|
|
|
|
header.addEventListener('click', () => {
|
|
|
|
|
header.style.borderColor = '#005ea5';
|
|
|
|
|
});
|
2022-02-08 11:07:57 +00:00
|
|
|
}
|
2025-04-14 14:27:22 -04:00
|
|
|
|
|
|
|
|
// Focus styling for heading-wrapped links
|
|
|
|
|
const containers = document.querySelectorAll('.js-mark-focus-on-parent');
|
|
|
|
|
containers.forEach(container => {
|
|
|
|
|
container.addEventListener('focusin', e => {
|
|
|
|
|
e.target.parentElement.classList.add('js-child-has-focus');
|
|
|
|
|
});
|
|
|
|
|
container.addEventListener('focusout', e => {
|
|
|
|
|
e.target.parentElement.classList.remove('js-child-has-focus');
|
|
|
|
|
});
|
|
|
|
|
});
|
2022-02-08 11:07:57 +00:00
|
|
|
});
|