idsk_frontend_toolkit 7.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.gitmodules +3 -0
- data/.ruby-version +1 -0
- data/.travis/govuk_frontend_toolkit_gem_push.enc +0 -0
- data/.travis/govuk_frontend_toolkit_gem_push.pub +1 -0
- data/.travis.yml +23 -0
- data/CONTRIBUTING.md +13 -0
- data/Gemfile +3 -0
- data/LICENCE +20 -0
- data/README.md +61 -0
- data/Rakefile +10 -0
- data/app/assets/.gitignore +5 -0
- data/app/assets/.ruby-version +1 -0
- data/app/assets/.travis/README.md +23 -0
- data/app/assets/.travis/govuk_frontend_toolkit_push.enc +0 -0
- data/app/assets/.travis/govuk_frontend_toolkit_push.pub +1 -0
- data/app/assets/.travis.yml +18 -0
- data/app/assets/CHANGELOG.md +381 -0
- data/app/assets/CONTRIBUTING.md +23 -0
- data/app/assets/Gemfile +4 -0
- data/app/assets/Gemfile.lock +48 -0
- data/app/assets/Gruntfile.js +68 -0
- data/app/assets/LICENCE +20 -0
- data/app/assets/README.md +170 -0
- data/app/assets/VERSION.txt +1 -0
- data/app/assets/create-release.sh +38 -0
- data/app/assets/docs/analytics.md +270 -0
- data/app/assets/docs/functions.md +62 -0
- data/app/assets/docs/javascript.md +337 -0
- data/app/assets/docs/mixins.md +617 -0
- data/app/assets/images/accordion-arrow-2x.png +0 -0
- data/app/assets/images/accordion-arrow.png +0 -0
- data/app/assets/images/arrow-sprite.png +0 -0
- data/app/assets/images/crests/bis_crest_13px.png +0 -0
- data/app/assets/images/crests/bis_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/bis_crest_18px.png +0 -0
- data/app/assets/images/crests/bis_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/bis_crest_27px.png +0 -0
- data/app/assets/images/crests/bis_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/coastguard_13px.png +0 -0
- data/app/assets/images/crests/coastguard_13px_x2.png +0 -0
- data/app/assets/images/crests/coastguard_18px.png +0 -0
- data/app/assets/images/crests/coastguard_18px_x2.png +0 -0
- data/app/assets/images/crests/coastguard_27px.png +0 -0
- data/app/assets/images/crests/coastguard_27px_x2.png +0 -0
- data/app/assets/images/crests/dit_crest_13px.png +0 -0
- data/app/assets/images/crests/dit_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/dit_crest_18px.png +0 -0
- data/app/assets/images/crests/dit_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/dit_crest_27px.png +0 -0
- data/app/assets/images/crests/dit_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/hmrc_crest_13px.png +0 -0
- data/app/assets/images/crests/hmrc_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/hmrc_crest_18px.png +0 -0
- data/app/assets/images/crests/hmrc_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/hmrc_crest_27px.png +0 -0
- data/app/assets/images/crests/hmrc_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/ho_crest_13px.png +0 -0
- data/app/assets/images/crests/ho_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/ho_crest_18px.png +0 -0
- data/app/assets/images/crests/ho_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/ho_crest_27px.png +0 -0
- data/app/assets/images/crests/ho_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/mod_crest_13px.png +0 -0
- data/app/assets/images/crests/mod_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/mod_crest_18px.png +0 -0
- data/app/assets/images/crests/mod_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/mod_crest_27px.png +0 -0
- data/app/assets/images/crests/mod_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/org_crest_13px.png +0 -0
- data/app/assets/images/crests/org_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/org_crest_18px.png +0 -0
- data/app/assets/images/crests/org_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/org_crest_27px.png +0 -0
- data/app/assets/images/crests/org_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/portcullis_13px.png +0 -0
- data/app/assets/images/crests/portcullis_13px_x2.png +0 -0
- data/app/assets/images/crests/portcullis_18px.png +0 -0
- data/app/assets/images/crests/portcullis_18px_x2.png +0 -0
- data/app/assets/images/crests/portcullis_27px.png +0 -0
- data/app/assets/images/crests/portcullis_27px_x2.png +0 -0
- data/app/assets/images/crests/so_crest_13px.png +0 -0
- data/app/assets/images/crests/so_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/so_crest_18px.png +0 -0
- data/app/assets/images/crests/so_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/so_crest_27px.png +0 -0
- data/app/assets/images/crests/so_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/ukaea_crest_13px.png +0 -0
- data/app/assets/images/crests/ukaea_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/ukaea_crest_18px.png +0 -0
- data/app/assets/images/crests/ukaea_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/ukaea_crest_27px.png +0 -0
- data/app/assets/images/crests/ukaea_crest_27px_x2.png +0 -0
- data/app/assets/images/crests/ukho_13px.png +0 -0
- data/app/assets/images/crests/ukho_13px_x2.png +0 -0
- data/app/assets/images/crests/ukho_18px.png +0 -0
- data/app/assets/images/crests/ukho_18px_x2.png +0 -0
- data/app/assets/images/crests/ukho_27px.png +0 -0
- data/app/assets/images/crests/ukho_27px_x2.png +0 -0
- data/app/assets/images/crests/wales_crest_13px.png +0 -0
- data/app/assets/images/crests/wales_crest_13px_x2.png +0 -0
- data/app/assets/images/crests/wales_crest_18px.png +0 -0
- data/app/assets/images/crests/wales_crest_18px_x2.png +0 -0
- data/app/assets/images/crests/wales_crest_27px.png +0 -0
- data/app/assets/images/crests/wales_crest_27px_x2.png +0 -0
- data/app/assets/images/icon-arrow-left.png +0 -0
- data/app/assets/images/icon-calendar-2x.png +0 -0
- data/app/assets/images/icon-calendar.png +0 -0
- data/app/assets/images/icon-file-download-2x.png +0 -0
- data/app/assets/images/icon-file-download.png +0 -0
- data/app/assets/images/icon-important-2x.png +0 -0
- data/app/assets/images/icon-important.png +0 -0
- data/app/assets/images/icon-information-2x.png +0 -0
- data/app/assets/images/icon-information.png +0 -0
- data/app/assets/images/icon-locator-2x.png +0 -0
- data/app/assets/images/icon-locator.png +0 -0
- data/app/assets/images/icon-pointer-2x.png +0 -0
- data/app/assets/images/icon-pointer-black-2x.png +0 -0
- data/app/assets/images/icon-pointer-black.png +0 -0
- data/app/assets/images/icon-pointer-indexed.png +0 -0
- data/app/assets/images/icon-pointer.png +0 -0
- data/app/assets/images/icon-search-2x.png +0 -0
- data/app/assets/images/icon-search.png +0 -0
- data/app/assets/images/icon-steps/icon-step-1-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-1.png +0 -0
- data/app/assets/images/icon-steps/icon-step-10-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-10.png +0 -0
- data/app/assets/images/icon-steps/icon-step-11-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-11.png +0 -0
- data/app/assets/images/icon-steps/icon-step-12-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-12.png +0 -0
- data/app/assets/images/icon-steps/icon-step-13-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-13.png +0 -0
- data/app/assets/images/icon-steps/icon-step-14-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-14.png +0 -0
- data/app/assets/images/icon-steps/icon-step-2-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-2.png +0 -0
- data/app/assets/images/icon-steps/icon-step-3-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-3.png +0 -0
- data/app/assets/images/icon-steps/icon-step-4-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-4.png +0 -0
- data/app/assets/images/icon-steps/icon-step-5-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-5.png +0 -0
- data/app/assets/images/icon-steps/icon-step-6-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-6.png +0 -0
- data/app/assets/images/icon-steps/icon-step-7-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-7.png +0 -0
- data/app/assets/images/icon-steps/icon-step-8-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-8.png +0 -0
- data/app/assets/images/icon-steps/icon-step-9-2x.png +0 -0
- data/app/assets/images/icon-steps/icon-step-9.png +0 -0
- data/app/assets/images/player-icon-forward.png +0 -0
- data/app/assets/images/player-icon-pause.png +0 -0
- data/app/assets/images/player-icon-play.png +0 -0
- data/app/assets/images/player-icon-rewind.png +0 -0
- data/app/assets/images/player-icon-volume.png +0 -0
- data/app/assets/images/separator-2x.png +0 -0
- data/app/assets/images/separator.png +0 -0
- data/app/assets/javascripts/govuk/analytics/analytics.js +143 -0
- data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +41 -0
- data/app/assets/javascripts/govuk/analytics/error-tracking.js +51 -0
- data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +56 -0
- data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +166 -0
- data/app/assets/javascripts/govuk/analytics/govuk-tracker.js +134 -0
- data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +38 -0
- data/app/assets/javascripts/govuk/analytics/print-intent.js +39 -0
- data/app/assets/javascripts/govuk/details.polyfill.js +240 -0
- data/app/assets/javascripts/govuk/modules/auto-track-event.js +30 -0
- data/app/assets/javascripts/govuk/modules.js +61 -0
- data/app/assets/javascripts/govuk/primary-links.js +57 -0
- data/app/assets/javascripts/govuk/selection-buttons.js +116 -0
- data/app/assets/javascripts/govuk/shim-links-with-button-role.js +34 -0
- data/app/assets/javascripts/govuk/show-hide-content.js +172 -0
- data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +128 -0
- data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +139 -0
- data/app/assets/javascripts/govuk_toolkit.js +1 -0
- data/app/assets/javascripts/stageprompt.js +69 -0
- data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +25 -0
- data/app/assets/javascripts/vendor/polyfills/bind.js +40 -0
- data/app/assets/package.json +25 -0
- data/app/assets/spec/manifest.js +41 -0
- data/app/assets/spec/stylesheets/_colour_contrast_spec.scss +12 -0
- data/app/assets/spec/support/LocalTestRunner.html +21 -0
- data/app/assets/spec/support/console-runner.js +102 -0
- data/app/assets/spec/support/load.js +47 -0
- data/app/assets/spec/support/run_jasmine_test.js +62 -0
- data/app/assets/spec/unit/analytics/analytics.spec.js +315 -0
- data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +72 -0
- data/app/assets/spec/unit/analytics/error-tracking.spec.js +65 -0
- data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +109 -0
- data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +180 -0
- data/app/assets/spec/unit/analytics/govuk-tracker.spec.js +171 -0
- data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +62 -0
- data/app/assets/spec/unit/details.polyfill.spec.js +91 -0
- data/app/assets/spec/unit/modules/auto-track-event.spec.js +54 -0
- data/app/assets/spec/unit/modules.spec.js +93 -0
- data/app/assets/spec/unit/primary-links.spec.js +55 -0
- data/app/assets/spec/unit/selection-button.spec.js +761 -0
- data/app/assets/spec/unit/shim-links-with-button-role.spec.js +41 -0
- data/app/assets/spec/unit/show-hide-content.spec.js +306 -0
- data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +137 -0
- data/app/assets/stylesheets/.gitkeep +0 -0
- data/app/assets/stylesheets/_colours.scss +2 -0
- data/app/assets/stylesheets/_conditionals.scss +81 -0
- data/app/assets/stylesheets/_css3.scss +90 -0
- data/app/assets/stylesheets/_device-pixels.scss +10 -0
- data/app/assets/stylesheets/_font_stack.scss +25 -0
- data/app/assets/stylesheets/_grid_layout.scss +136 -0
- data/app/assets/stylesheets/_helpers.scss +16 -0
- data/app/assets/stylesheets/_measurements.scss +14 -0
- data/app/assets/stylesheets/_shims.scss +55 -0
- data/app/assets/stylesheets/_typography.scss +249 -0
- data/app/assets/stylesheets/_url-helpers.scss +16 -0
- data/app/assets/stylesheets/colours/_organisation.scss +104 -0
- data/app/assets/stylesheets/colours/_palette.scss +77 -0
- data/app/assets/stylesheets/design-patterns/_alpha-beta.scss +67 -0
- data/app/assets/stylesheets/design-patterns/_breadcrumbs.scss +53 -0
- data/app/assets/stylesheets/design-patterns/_buttons.scss +145 -0
- data/app/assets/stylesheets/design-patterns/_media-player.scss +264 -0
- data/app/assets/trigger.sh +24 -0
- data/idsk_frontend_toolkit.gemspec +49 -0
- data/lib/idsk_frontend_toolkit/engine.rb +4 -0
- data/lib/idsk_frontend_toolkit/version.rb +5 -0
- data/lib/idsk_frontend_toolkit.rb +4 -0
- data/publish.sh +30 -0
- metadata +314 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
## JavaScript
|
|
2
|
+
|
|
3
|
+
The gem also includes some JavaScript which by itself will have no effect on a
|
|
4
|
+
page. It can be included with the asset_pipeline by adding the line:
|
|
5
|
+
|
|
6
|
+
//=require govuk_toolkit
|
|
7
|
+
|
|
8
|
+
## Modules
|
|
9
|
+
|
|
10
|
+
The toolkit comes with a module pattern that makes it easy to write re-usable modular components, without having to worry about where and when the module should be instantiated.
|
|
11
|
+
|
|
12
|
+
### Usage
|
|
13
|
+
|
|
14
|
+
Javascript modules can be specified in markup using `data-` attributes:
|
|
15
|
+
|
|
16
|
+
```html
|
|
17
|
+
<div data-module="some-module">
|
|
18
|
+
<strong>Some other markup inside the module</strong>
|
|
19
|
+
</div>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Modules can be found and started by including `govuk/modules.js` and running:
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
$(document).ready(function(){
|
|
26
|
+
GOVUK.modules.start()
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This will attempt to find and start all modules in the page. For the example above it will look for a module at `GOVUK.Modules.SomeModule`. Note the value of the data attribute has been converted to _PascalCase_.
|
|
31
|
+
|
|
32
|
+
The module will be instantiated and then its `start` method called. The HTML element with the `data-module` attribute is passed as the first argument to the module. This limits modules to acting only within their containing elements.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
module = new GOVUK.Modules[type]()
|
|
36
|
+
module.start(element)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Running `GOVUK.modules.start()` multiple times will have no additional affect. When a module is started a flag is set on the element using the data attribute `module-started`. `data-module-started` is a reserved attribute. It can however be called with an element as the first argument, to allow modules to be started in dynamically loaded content:
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
var $container = $('.dynamic-content')
|
|
43
|
+
GOVUK.modules.start($container)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Module structure
|
|
47
|
+
|
|
48
|
+
A module must add its constructor to `GOVUK.Modules` and it must have a `start` method.
|
|
49
|
+
The simplest module looks like:
|
|
50
|
+
|
|
51
|
+
```javascript
|
|
52
|
+
;(function(Modules) {
|
|
53
|
+
'use strict'
|
|
54
|
+
|
|
55
|
+
Modules.SomeModule = function() {
|
|
56
|
+
this.start = function($element) {
|
|
57
|
+
// module code
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
})(window.GOVUK.Modules)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Writing modules
|
|
64
|
+
|
|
65
|
+
Whilst this isn’t prescriptive, it helps if modules look and behave in a similar manner.
|
|
66
|
+
|
|
67
|
+
#### Use `js-` prefixed classes for interaction hooks
|
|
68
|
+
|
|
69
|
+
Make it clear where a javascript module will be applying behaviour:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<div data-module="toggle-thing">
|
|
73
|
+
<a href="/" class="js-toggle">Toggle</a>
|
|
74
|
+
<div class="js-toggle-target">Target</div>
|
|
75
|
+
</div>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Declare event listeners at the start
|
|
79
|
+
|
|
80
|
+
Beginning with a set of event listeners clearly indicates the module’s intentions.
|
|
81
|
+
|
|
82
|
+
```js
|
|
83
|
+
this.start = function($element) {
|
|
84
|
+
$element.on('click', '.js-toggle', toggle)
|
|
85
|
+
$element.on('click', '.js-cancel', cancel)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Where possible, assign listeners to the module element to minimise the number of listeners and to allow for flexible markup:
|
|
90
|
+
|
|
91
|
+
```html
|
|
92
|
+
<div data-module="toggle-thing">
|
|
93
|
+
<a href="/" class="js-toggle">This toggles</a>
|
|
94
|
+
<div class="js-toggle-target">
|
|
95
|
+
<p>Some content</p>
|
|
96
|
+
<a href="/" class="js-toggle">This also toggles</a>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### Use data-attributes for configuration
|
|
102
|
+
|
|
103
|
+
Keep modules flexible by moving configuration to data attributes on the module’s element:
|
|
104
|
+
|
|
105
|
+
```html
|
|
106
|
+
<div
|
|
107
|
+
data-module="html-stream"
|
|
108
|
+
data-url="/some/endpoint"
|
|
109
|
+
data-refresh-ms="5000">
|
|
110
|
+
<!-- updates with content from end point -->
|
|
111
|
+
</div>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
#### Include Jasmine specs
|
|
115
|
+
|
|
116
|
+
Modules should have their own tests, whether they’re being included with the toolkit or are app specific.
|
|
117
|
+
|
|
118
|
+
## Media player
|
|
119
|
+
|
|
120
|
+
There is a forked version of the Nomensa video player included and custom
|
|
121
|
+
GOV.UK styles to be used with it. To use it you will need to include the script
|
|
122
|
+
on your page and include the styles nested under an appropriate selector. For
|
|
123
|
+
example:
|
|
124
|
+
|
|
125
|
+
@import "design-patterns/media-player";
|
|
126
|
+
|
|
127
|
+
.media-player {
|
|
128
|
+
@include media-player;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
You will also need to create your own initalizer to target the links you want
|
|
132
|
+
to turn into videos. There are examples of how this works in the [Nomensa
|
|
133
|
+
Accesible Media Player][nomensa] repository.
|
|
134
|
+
|
|
135
|
+
[nomensa]: https://github.com/nomensa/Accessible-Media-Player/tree/master/example
|
|
136
|
+
|
|
137
|
+
## Primary Links
|
|
138
|
+
|
|
139
|
+
`GOVUK.PrimaryList` hides elements in a list which don't have a supplied
|
|
140
|
+
selector, they will then be shown when the user clicks. `GOVUK.primaryLinks` is
|
|
141
|
+
a helper to add this behaviour to many elements.
|
|
142
|
+
|
|
143
|
+
Example markup:
|
|
144
|
+
|
|
145
|
+
```html
|
|
146
|
+
<ul id="primary-list">
|
|
147
|
+
<li class="primary-item">Item 1</li>
|
|
148
|
+
<li>Item 2</li>
|
|
149
|
+
<li>Item 3</li>
|
|
150
|
+
</ul>
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
To add it to all lists which have items with the class `primary-item` use
|
|
154
|
+
something like:
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
GOVUK.primaryLinks.init('.primary-item')
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Or to add it just to that list you could use:
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
new GOVUK.PrimaryList($('#primary-list'), '.primary-item')
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Stick at top when scrolling
|
|
167
|
+
|
|
168
|
+
`GOVUK.stickAtTopWhenScrolling` tries to add a class to an element when the top
|
|
169
|
+
of that element would be scrolled out of the viewport.
|
|
170
|
+
|
|
171
|
+
The following would cause the element to stay when you scroll:
|
|
172
|
+
|
|
173
|
+
```html
|
|
174
|
+
<div class="js-stick-at-top-when-scrolling">something</div>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```css
|
|
178
|
+
.content-fixed {
|
|
179
|
+
position: fixed;
|
|
180
|
+
top: 0;
|
|
181
|
+
}
|
|
182
|
+
.shim {
|
|
183
|
+
display: block;
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```javascript
|
|
188
|
+
GOVUK.stickAtTopWhenScrolling.init()
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
If you also include `stop-scrolling-at-footer.js` this will stop
|
|
192
|
+
the elements overlapping the footer.
|
|
193
|
+
|
|
194
|
+
## Selection buttons
|
|
195
|
+
|
|
196
|
+
>If you are using GOV.UK Elements version 3.0.0 or above you *do not need* to include and initialise `GOVUK.SelectionButtons` to apply the correct radio button and checkbox styling. This module is deprecated and will be removed in the future.
|
|
197
|
+
|
|
198
|
+
`GOVUK.SelectionButtons` adds classes to a parent `<label>` of a radio button or checkbox, allowing you to style it based on the input’s state. Given this example HTML structure:
|
|
199
|
+
|
|
200
|
+
```html
|
|
201
|
+
<label>
|
|
202
|
+
<input type="radio" name="size" value="medium" />
|
|
203
|
+
Medium size
|
|
204
|
+
</label>
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
When the input is focused or its `checked` attribute is set, representative classes are added to the label.
|
|
208
|
+
|
|
209
|
+
### Usage
|
|
210
|
+
|
|
211
|
+
#### GOVUK.SelectionButtons
|
|
212
|
+
|
|
213
|
+
To apply this behaviour to elements that follow the above HTML, call the `GOVUK.SelectionButtons` constructor with a jQuery collection of the inputs:
|
|
214
|
+
|
|
215
|
+
```javascript
|
|
216
|
+
var $buttons = $('label input[type=radio], label input[type=checkbox]')
|
|
217
|
+
var selectionButtons = new GOVUK.SelectionButtons($buttons)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
If you want to bind your events to the document instead of the elements directly (delegated events) you can call `GOVUK.SelectionButtons` with a selector string:
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
var selectionButtons = new GOVUK.SelectionButtons('label input[type=radio], label input[type=checkbox]')
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
This will bind all events to the document meaning any new elements (for example, by AJAX) that match this selector will automatically gain this functionality.
|
|
227
|
+
|
|
228
|
+
If you do add elements that need this functionality dynamically to the page, you will need to initialise their state. You can do this by calling `SelectionButtons.setInitialState` with the same selector string:
|
|
229
|
+
|
|
230
|
+
```javascript
|
|
231
|
+
var buttonSelector = 'label input[type=radio], label input[type=checkbox]'
|
|
232
|
+
var selectionButtons = new GOVUK.SelectionButtons(buttonSelector)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
then later, after adding more elements:
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
selectionButtons.setInitialState(buttonSelector)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The classes that get added to the `<label>` tags can be passed in as options:
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
var $buttons = $('label input[type=radio], label input[type=checkbox]')
|
|
245
|
+
var selectionButtons = new GOVUK.SelectionButtons($buttons, {
|
|
246
|
+
focusedClass: 'selectable-focused',
|
|
247
|
+
selectedClass: 'selectable-selected'
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
or, using delegated events:
|
|
252
|
+
|
|
253
|
+
```javascript
|
|
254
|
+
var buttonSelector = 'label input[type=radio], label input[type=checkbox]'
|
|
255
|
+
var selectionButtons = new GOVUK.SelectionButtons($buttonSelector, {
|
|
256
|
+
focusedClass: 'selectable-focused',
|
|
257
|
+
selectedClass: 'selectable-selected'
|
|
258
|
+
})
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
#### destroy method
|
|
262
|
+
|
|
263
|
+
The returned instance object includes a `destroy` method to remove all events bound to either the elements or the document.
|
|
264
|
+
|
|
265
|
+
Using any of the `selectionButtons` objects created above, it can be called like so:
|
|
266
|
+
|
|
267
|
+
```javascript
|
|
268
|
+
selectionButtons.destroy();
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Deprecated functionality
|
|
272
|
+
|
|
273
|
+
The previous method of calling selection buttons is now deprecated. If you need to call them using this method, you will need to define this function:
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
GOVUK.selectionButtons = function (elms, opts) {
|
|
277
|
+
new GOVUK.SelectionButtons(elms, opts)
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
This method will mean the `destroy` method is not available to call.
|
|
282
|
+
|
|
283
|
+
## Shim links with button role
|
|
284
|
+
|
|
285
|
+
Links styled to look like buttons lack button behaviour. This script will allow them to be triggered with a space key after they’ve been focused, to match standard buttons.
|
|
286
|
+
|
|
287
|
+
### Usage
|
|
288
|
+
|
|
289
|
+
This behaviour will be applied to elements with a role of button.
|
|
290
|
+
|
|
291
|
+
```html
|
|
292
|
+
<a class="button" role="button">A button</a>
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
```javascript
|
|
296
|
+
GOVUK.shimLinksWithButtonRole.init()
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Show/Hide content
|
|
300
|
+
|
|
301
|
+
Script to support show/hide content, toggled by radio buttons and checkboxes. This allows for progressive disclosure of question and answer forms based on selected values:
|
|
302
|
+
|
|
303
|
+
<div class="multiple-choice" data-target="show-me">
|
|
304
|
+
<input type="radio" name="enabled" value="yes" />
|
|
305
|
+
<label>Yes</label>
|
|
306
|
+
</div>
|
|
307
|
+
|
|
308
|
+
<div class="multiple-choice">
|
|
309
|
+
<input type="radio" name="enabled" value="no" />
|
|
310
|
+
<label>No</label>
|
|
311
|
+
</div>
|
|
312
|
+
|
|
313
|
+
<div id="show-me" class="panel js-hidden">
|
|
314
|
+
<p>Show/Hide content to be toggled</p>
|
|
315
|
+
</div>
|
|
316
|
+
|
|
317
|
+
When the input's `checked` attribute is set, the show/hide content's `.js-hidden` class is removed and ARIA attributes are added to enable it. Note the sample `show-me` id attribute used to link the label to show/hide content.
|
|
318
|
+
|
|
319
|
+
### Usage
|
|
320
|
+
|
|
321
|
+
#### GOVUK.ShowHideContent
|
|
322
|
+
|
|
323
|
+
To apply this behaviour to elements with the above HTML pattern, call the `GOVUK.ShowHideContent` constructor:
|
|
324
|
+
|
|
325
|
+
```
|
|
326
|
+
var showHideContent = new GOVUK.ShowHideContent()
|
|
327
|
+
showHideContent.init()
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
This will bind two event handlers to $(document.body), one for radio inputs and one for checkboxes. By listening for events bubbling up to the `body` tag, additional show/hide content added to the page will still be picked up after `.init()` is called.
|
|
331
|
+
|
|
332
|
+
Alternatively, pass in your own selector. In the example below, event handlers are bound to the form instead.
|
|
333
|
+
|
|
334
|
+
```
|
|
335
|
+
var showHideContent = new GOVUK.ShowHideContent()
|
|
336
|
+
showHideContent.init($('form.example'))
|
|
337
|
+
```
|