diff --git a/lib/metalsmith.js b/lib/metalsmith.js index 1425d479fc..936d1761e7 100644 --- a/lib/metalsmith.js +++ b/lib/metalsmith.js @@ -136,25 +136,15 @@ module.exports = metalsmith copyAssets('{fonts,images}/*', { cwd: join(dirname(require.resolve('govuk-frontend')), 'assets'), dest: 'assets' - }), - - copyAssets('**/iframeResizer.contentWindow.@(map|min.js)', { - cwd: join(dirname(require.resolve('iframe-resizer')), 'js'), - dest: 'javascripts/vendor' }) ]) 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/package-lock.json b/package-lock.json index b606fc7075..2ae4702db8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "accessible-autocomplete": "^2.0.4", "clipboard": "^2.0.11", "govuk-frontend": "^4.7.0", - "iframe-resizer": "^4.3.7", + "iframe-resizer": "^4.3.9", "lunr": "^2.3.9" }, "devDependencies": { @@ -9098,9 +9098,9 @@ ] }, "node_modules/iframe-resizer": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/iframe-resizer/-/iframe-resizer-4.3.7.tgz", - "integrity": "sha512-a3EGVScU9NtUpj6lWvGhVw3EfOw5AopRs5xGsQU385kWdgQt++OsD6PCnTV+8YkgBu/g28rLIh0EztFg9UQr1Q==", + "version": "4.3.9", + "resolved": "https://registry.npmjs.org/iframe-resizer/-/iframe-resizer-4.3.9.tgz", + "integrity": "sha512-MCt+V/THB4a9OcAdrWo5NsI2CRpeMM4ijhTfiLtsdgDJXWYXf62Ve8yO8rKGmYNs991zty/EolYOxActlkfU+A==", "engines": { "node": ">=0.8.0" }, diff --git a/package.json b/package.json index a683d030d3..bfee2a08be 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "accessible-autocomplete": "^2.0.4", "clipboard": "^2.0.11", "govuk-frontend": "^4.7.0", - "iframe-resizer": "^4.3.7", + "iframe-resizer": "^4.3.9", "lunr": "^2.3.9" }, "devDependencies": { 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 5351f36846..90ce28cd70 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' @@ -14,6 +16,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"]' diff --git a/src/javascripts/example.mjs b/src/javascripts/components/example-page.mjs similarity index 85% rename from src/javascripts/example.mjs rename to src/javascripts/components/example-page.mjs index 01eb479c98..58410519ca 100644 --- a/src/javascripts/example.mjs +++ b/src/javascripts/components/example-page.mjs @@ -1,6 +1,9 @@ +import 'iframe-resizer/js/iframeResizer.contentWindow.js' + function ExamplePage($module) { this.$module = $module } + ExamplePage.prototype.init = function () { var $module = this.$module if (!$module) { @@ -9,6 +12,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 +23,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 b8bdb37838..5499fd6298 100644 --- a/src/styles/page-template/block-areas/index.njk +++ b/src/styles/page-template/block-areas/index.njk @@ -83,7 +83,6 @@ 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/index.njk b/src/styles/page-template/custom/index.njk index 8c243c6adb..f37c998f28 100644 --- a/src/styles/page-template/custom/index.njk +++ b/src/styles/page-template/custom/index.njk @@ -151,7 +151,5 @@ ignoreInSitemap: true {% endblock %} {% block bodyEnd %} - - - + {% endblock %} diff --git a/src/styles/page-template/default/index.njk b/src/styles/page-template/default/index.njk index 80a53fcb55..8e7ea45b08 100644 --- a/src/styles/page-template/default/index.njk +++ b/src/styles/page-template/default/index.njk @@ -17,6 +17,5 @@ layout: false {% endblock %} {% block bodyEnd %} - - + {% endblock %} diff --git a/views/layouts/_generic.njk b/views/layouts/_generic.njk index 697408f5ac..d3965adccf 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..e5121f7127 100644 --- a/views/layouts/layout-example-full-page-govuk.njk +++ b/views/layouts/layout-example-full-page-govuk.njk @@ -22,7 +22,5 @@ {{ 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..d0bbf432d0 100644 --- a/views/layouts/layout-example-full-page.njk +++ b/views/layouts/layout-example-full-page.njk @@ -24,7 +24,5 @@ {{ contents | safe }} {% endblock %} {% block bodyEnd %} - - - + {% endblock %} diff --git a/views/layouts/layout-example.njk b/views/layouts/layout-example.njk index 749079f825..8294b5a8c6 100644 --- a/views/layouts/layout-example.njk +++ b/views/layouts/layout-example.njk @@ -32,9 +32,7 @@ {% endblock %} {% block bodyEnd %} - - - + {% endblock %} {# Example pages shouldn't have a footer, so blank the one provided by the template #}