diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index e48485471..b130c050b 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -1,27 +1,38 @@ -window.GOVUK.Frontend.initAll(); - -$(() => $("time.timeago").timeago()); +// Initialize GOV.UK Frontend components (modern init) +window.GOVUKFrontend.initAll(); var showHideContent = new GOVUK.ShowHideContent(); showHideContent.init(); -$(() => GOVUK.modules.start()); - -$(() => $('.error-message, .usa-error-message').eq(0).parent('label').next('input').trigger('focus')); - -$(() => $('.govuk-header__container').on('click', function() { - $(this).css('border-color', '#005ea5'); -})); - -// Applies our expanded focus style to the siblings of links when that link is wrapped in a heading. -// -// This will be possible in CSS in the future, using the :has pseudo-class. When :has is available -// in the browsers we support, this code can be replaced with a CSS-only solution. -$('.js-mark-focus-on-parent').on('focus blur', '*', e => { - $target = $(e.target); - if (e.type === 'focusin') { - $target.parent().addClass('js-child-has-focus'); - } else { - $target.parent().removeClass('js-child-has-focus'); +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(); + } + } } + + // Optional: highlight header on click + const header = document.querySelector('.govuk-header__container'); + if (header) { + header.addEventListener('click', () => { + header.style.borderColor = '#005ea5'; + }); + } + + // 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'); + }); + }); }); diff --git a/app/templates/views/api/index.html b/app/templates/views/api/index.html index 0bd3e2a94..cf295c0c0 100644 --- a/app/templates/views/api/index.html +++ b/app/templates/views/api/index.html @@ -57,7 +57,7 @@ {{notification.key_name}} - diff --git a/app/templates/views/find-users/user-information.html b/app/templates/views/find-users/user-information.html index 3a90b7bc6..4575f4748 100644 --- a/app/templates/views/find-users/user-information.html +++ b/app/templates/views/find-users/user-information.html @@ -60,7 +60,7 @@

This person has never logged in

{% else %}

Last logged in -

diff --git a/gulpfile.js b/gulpfile.js index f360747b2..5e8f3ab32 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -47,7 +47,6 @@ const javascripts = () => { paths.npm + 'hogan.js/dist/hogan-3.0.2.js', paths.npm + 'jquery/dist/jquery.min.js', paths.npm + 'query-command-supported/dist/queryCommandSupported.min.js', - paths.npm + 'timeago/jquery.timeago.js', paths.npm + 'textarea-caret/index.js', paths.npm + 'cbor-js/cbor.js', paths.npm + 'd3/dist/d3.min.js', diff --git a/package-lock.json b/package-lock.json index 0c71924da..b1c514b65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,6 @@ "query-command-supported": "1.0.0", "sass-embedded": "^1.86.3", "textarea-caret": "3.1.0", - "timeago": "1.6.7", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0" }, @@ -12680,14 +12679,6 @@ "node": ">=0.10.0" } }, - "node_modules/timeago": { - "version": "1.6.7", - "resolved": "https://registry.npmjs.org/timeago/-/timeago-1.6.7.tgz", - "integrity": "sha512-FikcjN98+ij0siKH4VO4dZ358PR3oDDq4Vdl1+sN9gWz1/+JXGr3uZbUShYH/hL7bMhcTpPbplJU5Tej4b4jbQ==", - "dependencies": { - "jquery": ">=1.5.0 <4.0" - } - }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", diff --git a/package.json b/package.json index bed81b47c..3eed62930 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "query-command-supported": "1.0.0", "sass-embedded": "^1.86.3", "textarea-caret": "3.1.0", - "timeago": "1.6.7", "vinyl-buffer": "^1.0.1", "vinyl-source-stream": "^2.0.0" }, diff --git a/poetry.lock b/poetry.lock index 1d0262110..a23a0e07c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -17,7 +17,6 @@ version = "5.0.1" description = "Timeout context manager for asyncio programs" optional = false python-versions = ">=3.8" -groups = ["main"] files = [ {file = "async_timeout-5.0.1-py3-none-any.whl", hash = "sha256:39e3809566ff85354557ec2398b55e096c8364bacac9405a7a1fa429e77fe76c"}, {file = "async_timeout-5.0.1.tar.gz", hash = "sha256:d9321a7a3d5a6a5e187e824d2fa0793ce379a202935782d555d6e9d2735677d3"}, @@ -1486,7 +1485,6 @@ version = "3.0.2" description = "Safely add untrusted strings to HTML/XML markup." optional = false python-versions = ">=3.9" -groups = ["main", "dev"] files = [ {file = "MarkupSafe-3.0.2-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:7e94c425039cde14257288fd61dcfb01963e658efbc0ff54f5306b06054700f8"}, {file = "MarkupSafe-3.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:9e2d922824181480953426608b81967de705c3cef4d1af983af849d7bd619158"}, diff --git a/tests/javascripts/main.test.js b/tests/javascripts/main.test.js new file mode 100644 index 000000000..e69de29bb