diff --git a/lib/metalsmith.js b/lib/metalsmith.js index cfce2dc89b..32ab52fa19 100644 --- a/lib/metalsmith.js +++ b/lib/metalsmith.js @@ -163,14 +163,9 @@ module.exports = metalsmith done() }) - // build the entrypoint for application specific JavaScript + // build the entrypoints for application specific JavaScript .use(rollup('javascripts/application.mjs')) - - // build GOV.UK Frontend JavaScript - .use(rollup('javascripts/govuk-frontend.mjs')) - - // build the entrypoint for example specific JavaScript - .use(rollup('javascripts/example.mjs')) + .use(rollup('javascripts/application-example.mjs')) // add hash to files in production .use((files, metalsmith, done) => { diff --git a/src/javascripts/application-example.mjs b/src/javascripts/application-example.mjs new file mode 100644 index 0000000000..abcb0bdd98 --- /dev/null +++ b/src/javascripts/application-example.mjs @@ -0,0 +1,13 @@ +import { initAll } from 'govuk-frontend' + +import ExamplePage from './components/example-page.mjs' + +// Initialise GOV.UK Frontend +initAll({ + // Auto focusing the error summary and notification banner is not useful + // when used in examples, and causes the viewport to scroll + errorSummary: { disableAutoFocus: true }, + notificationBanner: { disableAutoFocus: true } +}) + +new ExamplePage(document).init() diff --git a/src/javascripts/application.mjs b/src/javascripts/application.mjs index 2e96adc6bd..078cf557e3 100644 --- a/src/javascripts/application.mjs +++ b/src/javascripts/application.mjs @@ -1,3 +1,5 @@ +import { initAll } from 'govuk-frontend' + import Analytics from './components/analytics.mjs' import BackToTop from './components/back-to-top.mjs' import CookieBanner from './components/cookie-banner.mjs' @@ -11,6 +13,9 @@ import OptionsTable from './components/options-table.mjs' import Search from './components/search.mjs' import AppTabs from './components/tabs.mjs' +// Initialise GOV.UK Frontend +initAll() + // Initialise cookie banner var $cookieBanner = document.querySelector('[data-module="govuk-cookie-banner"]') new CookieBanner($cookieBanner).init() diff --git a/src/javascripts/example.mjs b/src/javascripts/components/example-page.mjs similarity index 93% rename from src/javascripts/example.mjs rename to src/javascripts/components/example-page.mjs index 08e08eeb83..710ec3df74 100644 --- a/src/javascripts/example.mjs +++ b/src/javascripts/components/example-page.mjs @@ -1,6 +1,7 @@ function ExamplePage ($module) { this.$module = $module } + ExamplePage.prototype.init = function () { var $module = this.$module if (!$module) { @@ -9,6 +10,7 @@ ExamplePage.prototype.init = function () { var $form = $module.querySelector('form[action="/form-handler"]') this.preventFormSubmission($form) } + ExamplePage.prototype.preventFormSubmission = function ($form) { // we should only have one form per example if (!$form) { @@ -19,4 +21,4 @@ ExamplePage.prototype.preventFormSubmission = function ($form) { }) } -new ExamplePage(document).init() +export default ExamplePage diff --git a/src/javascripts/govuk-frontend.mjs b/src/javascripts/govuk-frontend.mjs deleted file mode 100644 index 82ae24143c..0000000000 --- a/src/javascripts/govuk-frontend.mjs +++ /dev/null @@ -1,12 +0,0 @@ -import { initAll } from 'govuk-frontend' - -initAll({ - // auto focusing the error summary and notification banner is not useful - // when used in examples, and causes the viewport to scroll - errorSummary: { - disableAutoFocus: true - }, - notificationBanner: { - disableAutoFocus: true - } -}) diff --git a/src/styles/page-template/block-areas/index.njk b/src/styles/page-template/block-areas/index.njk index aa24904476..c1639f62b5 100644 --- a/src/styles/page-template/block-areas/index.njk +++ b/src/styles/page-template/block-areas/index.njk @@ -81,7 +81,7 @@ stylesheets: block: bodyEnd {{ super() }} {# Since we’re not extending the Design System layout we need to add this manually #} - - + + {%- endblock %} diff --git a/src/styles/page-template/custom/code.njk b/src/styles/page-template/custom/code.njk index 22975b38c1..a0b27187f6 100644 --- a/src/styles/page-template/custom/code.njk +++ b/src/styles/page-template/custom/code.njk @@ -147,5 +147,9 @@ ignoreInSitemap: true {% endblock %} {% block bodyEnd %} - + + {% endblock %} diff --git a/src/styles/page-template/custom/index.njk b/src/styles/page-template/custom/index.njk index d1540c91c9..81076eb2e7 100644 --- a/src/styles/page-template/custom/index.njk +++ b/src/styles/page-template/custom/index.njk @@ -149,6 +149,6 @@ ignoreInSitemap: true {% endblock %} {% block bodyEnd %} - - + + {% endblock %} diff --git a/src/styles/page-template/default/code.njk b/src/styles/page-template/default/code.njk index 76095337eb..2ce7fe282f 100644 --- a/src/styles/page-template/default/code.njk +++ b/src/styles/page-template/default/code.njk @@ -15,6 +15,9 @@ ignoreInSitemap: true {% block bodyEnd %} {# Run JavaScript at end of the
, to avoid blocking the initial render. #} - - + + {% endblock %} diff --git a/src/styles/page-template/default/index.njk b/src/styles/page-template/default/index.njk index 9b3ef57fc3..ab54fc22f2 100644 --- a/src/styles/page-template/default/index.njk +++ b/src/styles/page-template/default/index.njk @@ -14,6 +14,6 @@ layout: false {% endblock %} {% block bodyEnd %} - - + + {% endblock %} diff --git a/views/layouts/_generic.njk b/views/layouts/_generic.njk index 50506c3011..7420ad854d 100644 --- a/views/layouts/_generic.njk +++ b/views/layouts/_generic.njk @@ -37,6 +37,5 @@ {% block footer %}{% endblock %} {% block bodyEnd %} - - + {% endblock %} diff --git a/views/layouts/layout-example-full-page-govuk.njk b/views/layouts/layout-example-full-page-govuk.njk index f7cfe9b2ea..74bafa4534 100644 --- a/views/layouts/layout-example-full-page-govuk.njk +++ b/views/layouts/layout-example-full-page-govuk.njk @@ -22,7 +22,6 @@ {{ contents | safe }} {% endblock %} {% block bodyEnd %} - - - + + {% endblock %} diff --git a/views/layouts/layout-example-full-page.njk b/views/layouts/layout-example-full-page.njk index c039ebe140..440cce9093 100644 --- a/views/layouts/layout-example-full-page.njk +++ b/views/layouts/layout-example-full-page.njk @@ -24,7 +24,6 @@ {{ contents | safe }} {% endblock %} {% block bodyEnd %} - - - + + {% endblock %} diff --git a/views/layouts/layout-example.njk b/views/layouts/layout-example.njk index 73dd013f5b..440bbf6ada 100644 --- a/views/layouts/layout-example.njk +++ b/views/layouts/layout-example.njk @@ -35,9 +35,8 @@ {% endblock %} {% block bodyEnd %} - - - + + {% endblock %} {# Example pages shouldn't have a footer, so blank the one provided by the template #} diff --git a/views/partials/_cookie-banner.njk b/views/partials/_cookie-banner.njk index 0a51c356ae..8a65cc469f 100644 --- a/views/partials/_cookie-banner.njk +++ b/views/partials/_cookie-banner.njk @@ -72,25 +72,31 @@ to avoid a high cumulative layout shift (CLS) score https://web.dev/cls/ #}