Skip to content

Commit

Permalink
Signpost important infos for using our JavaScript components
Browse files Browse the repository at this point in the history
More content to be added in #341
  • Loading branch information
romaricpascal committed Oct 26, 2023
1 parent 4cd839c commit 6299466
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion source/importing-css-assets-and-javascript/index.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ You can also use your own function to generate paths, for example if you're usin

## JavaScript

Before you import JavaScript from GOV.UK Frontend, you'll need to add the following to the top of the `<body class="govuk-template__body">` section of your page template (if you're not [using our Nunjucks macros](https://frontend.design-system.service.gov.uk/use-nunjucks/)):
Before you import JavaScript from GOV.UK Frontend, you'll need to add the following to the top of the `<body class="govuk-template__body">` section of your page template (if you're not [using our Nunjucks macros](/use-nunjucks/)):

```html
<script>document.body.className += ' js-enabled' + ('noModule' in HTMLScriptElement.prototype ? ' govuk-frontend-supported' : '');</script>
Expand Down Expand Up @@ -226,6 +226,10 @@ const { initAll } = require('govuk-frontend')
initAll()
```

### UMD and `window` globals support

We encourage the use of ES modules. For projects that cannot use them and require UMD or `window` globals, our package contains `.bundle.js` files.

### Select and initialise part of a page

If you update a page with new markup, for example a modal dialogue box, you can run `initAll` with a `scope` parameter to initialise the components on part of a page.
Expand Down

0 comments on commit 6299466

Please sign in to comment.