idsk_frontend_toolkit 7.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.gitmodules +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis/govuk_frontend_toolkit_gem_push.enc +0 -0
  6. data/.travis/govuk_frontend_toolkit_gem_push.pub +1 -0
  7. data/.travis.yml +23 -0
  8. data/CONTRIBUTING.md +13 -0
  9. data/Gemfile +3 -0
  10. data/LICENCE +20 -0
  11. data/README.md +61 -0
  12. data/Rakefile +10 -0
  13. data/app/assets/.gitignore +5 -0
  14. data/app/assets/.ruby-version +1 -0
  15. data/app/assets/.travis/README.md +23 -0
  16. data/app/assets/.travis/govuk_frontend_toolkit_push.enc +0 -0
  17. data/app/assets/.travis/govuk_frontend_toolkit_push.pub +1 -0
  18. data/app/assets/.travis.yml +18 -0
  19. data/app/assets/CHANGELOG.md +381 -0
  20. data/app/assets/CONTRIBUTING.md +23 -0
  21. data/app/assets/Gemfile +4 -0
  22. data/app/assets/Gemfile.lock +48 -0
  23. data/app/assets/Gruntfile.js +68 -0
  24. data/app/assets/LICENCE +20 -0
  25. data/app/assets/README.md +170 -0
  26. data/app/assets/VERSION.txt +1 -0
  27. data/app/assets/create-release.sh +38 -0
  28. data/app/assets/docs/analytics.md +270 -0
  29. data/app/assets/docs/functions.md +62 -0
  30. data/app/assets/docs/javascript.md +337 -0
  31. data/app/assets/docs/mixins.md +617 -0
  32. data/app/assets/images/accordion-arrow-2x.png +0 -0
  33. data/app/assets/images/accordion-arrow.png +0 -0
  34. data/app/assets/images/arrow-sprite.png +0 -0
  35. data/app/assets/images/crests/bis_crest_13px.png +0 -0
  36. data/app/assets/images/crests/bis_crest_13px_x2.png +0 -0
  37. data/app/assets/images/crests/bis_crest_18px.png +0 -0
  38. data/app/assets/images/crests/bis_crest_18px_x2.png +0 -0
  39. data/app/assets/images/crests/bis_crest_27px.png +0 -0
  40. data/app/assets/images/crests/bis_crest_27px_x2.png +0 -0
  41. data/app/assets/images/crests/coastguard_13px.png +0 -0
  42. data/app/assets/images/crests/coastguard_13px_x2.png +0 -0
  43. data/app/assets/images/crests/coastguard_18px.png +0 -0
  44. data/app/assets/images/crests/coastguard_18px_x2.png +0 -0
  45. data/app/assets/images/crests/coastguard_27px.png +0 -0
  46. data/app/assets/images/crests/coastguard_27px_x2.png +0 -0
  47. data/app/assets/images/crests/dit_crest_13px.png +0 -0
  48. data/app/assets/images/crests/dit_crest_13px_x2.png +0 -0
  49. data/app/assets/images/crests/dit_crest_18px.png +0 -0
  50. data/app/assets/images/crests/dit_crest_18px_x2.png +0 -0
  51. data/app/assets/images/crests/dit_crest_27px.png +0 -0
  52. data/app/assets/images/crests/dit_crest_27px_x2.png +0 -0
  53. data/app/assets/images/crests/hmrc_crest_13px.png +0 -0
  54. data/app/assets/images/crests/hmrc_crest_13px_x2.png +0 -0
  55. data/app/assets/images/crests/hmrc_crest_18px.png +0 -0
  56. data/app/assets/images/crests/hmrc_crest_18px_x2.png +0 -0
  57. data/app/assets/images/crests/hmrc_crest_27px.png +0 -0
  58. data/app/assets/images/crests/hmrc_crest_27px_x2.png +0 -0
  59. data/app/assets/images/crests/ho_crest_13px.png +0 -0
  60. data/app/assets/images/crests/ho_crest_13px_x2.png +0 -0
  61. data/app/assets/images/crests/ho_crest_18px.png +0 -0
  62. data/app/assets/images/crests/ho_crest_18px_x2.png +0 -0
  63. data/app/assets/images/crests/ho_crest_27px.png +0 -0
  64. data/app/assets/images/crests/ho_crest_27px_x2.png +0 -0
  65. data/app/assets/images/crests/mod_crest_13px.png +0 -0
  66. data/app/assets/images/crests/mod_crest_13px_x2.png +0 -0
  67. data/app/assets/images/crests/mod_crest_18px.png +0 -0
  68. data/app/assets/images/crests/mod_crest_18px_x2.png +0 -0
  69. data/app/assets/images/crests/mod_crest_27px.png +0 -0
  70. data/app/assets/images/crests/mod_crest_27px_x2.png +0 -0
  71. data/app/assets/images/crests/org_crest_13px.png +0 -0
  72. data/app/assets/images/crests/org_crest_13px_x2.png +0 -0
  73. data/app/assets/images/crests/org_crest_18px.png +0 -0
  74. data/app/assets/images/crests/org_crest_18px_x2.png +0 -0
  75. data/app/assets/images/crests/org_crest_27px.png +0 -0
  76. data/app/assets/images/crests/org_crest_27px_x2.png +0 -0
  77. data/app/assets/images/crests/portcullis_13px.png +0 -0
  78. data/app/assets/images/crests/portcullis_13px_x2.png +0 -0
  79. data/app/assets/images/crests/portcullis_18px.png +0 -0
  80. data/app/assets/images/crests/portcullis_18px_x2.png +0 -0
  81. data/app/assets/images/crests/portcullis_27px.png +0 -0
  82. data/app/assets/images/crests/portcullis_27px_x2.png +0 -0
  83. data/app/assets/images/crests/so_crest_13px.png +0 -0
  84. data/app/assets/images/crests/so_crest_13px_x2.png +0 -0
  85. data/app/assets/images/crests/so_crest_18px.png +0 -0
  86. data/app/assets/images/crests/so_crest_18px_x2.png +0 -0
  87. data/app/assets/images/crests/so_crest_27px.png +0 -0
  88. data/app/assets/images/crests/so_crest_27px_x2.png +0 -0
  89. data/app/assets/images/crests/ukaea_crest_13px.png +0 -0
  90. data/app/assets/images/crests/ukaea_crest_13px_x2.png +0 -0
  91. data/app/assets/images/crests/ukaea_crest_18px.png +0 -0
  92. data/app/assets/images/crests/ukaea_crest_18px_x2.png +0 -0
  93. data/app/assets/images/crests/ukaea_crest_27px.png +0 -0
  94. data/app/assets/images/crests/ukaea_crest_27px_x2.png +0 -0
  95. data/app/assets/images/crests/ukho_13px.png +0 -0
  96. data/app/assets/images/crests/ukho_13px_x2.png +0 -0
  97. data/app/assets/images/crests/ukho_18px.png +0 -0
  98. data/app/assets/images/crests/ukho_18px_x2.png +0 -0
  99. data/app/assets/images/crests/ukho_27px.png +0 -0
  100. data/app/assets/images/crests/ukho_27px_x2.png +0 -0
  101. data/app/assets/images/crests/wales_crest_13px.png +0 -0
  102. data/app/assets/images/crests/wales_crest_13px_x2.png +0 -0
  103. data/app/assets/images/crests/wales_crest_18px.png +0 -0
  104. data/app/assets/images/crests/wales_crest_18px_x2.png +0 -0
  105. data/app/assets/images/crests/wales_crest_27px.png +0 -0
  106. data/app/assets/images/crests/wales_crest_27px_x2.png +0 -0
  107. data/app/assets/images/icon-arrow-left.png +0 -0
  108. data/app/assets/images/icon-calendar-2x.png +0 -0
  109. data/app/assets/images/icon-calendar.png +0 -0
  110. data/app/assets/images/icon-file-download-2x.png +0 -0
  111. data/app/assets/images/icon-file-download.png +0 -0
  112. data/app/assets/images/icon-important-2x.png +0 -0
  113. data/app/assets/images/icon-important.png +0 -0
  114. data/app/assets/images/icon-information-2x.png +0 -0
  115. data/app/assets/images/icon-information.png +0 -0
  116. data/app/assets/images/icon-locator-2x.png +0 -0
  117. data/app/assets/images/icon-locator.png +0 -0
  118. data/app/assets/images/icon-pointer-2x.png +0 -0
  119. data/app/assets/images/icon-pointer-black-2x.png +0 -0
  120. data/app/assets/images/icon-pointer-black.png +0 -0
  121. data/app/assets/images/icon-pointer-indexed.png +0 -0
  122. data/app/assets/images/icon-pointer.png +0 -0
  123. data/app/assets/images/icon-search-2x.png +0 -0
  124. data/app/assets/images/icon-search.png +0 -0
  125. data/app/assets/images/icon-steps/icon-step-1-2x.png +0 -0
  126. data/app/assets/images/icon-steps/icon-step-1.png +0 -0
  127. data/app/assets/images/icon-steps/icon-step-10-2x.png +0 -0
  128. data/app/assets/images/icon-steps/icon-step-10.png +0 -0
  129. data/app/assets/images/icon-steps/icon-step-11-2x.png +0 -0
  130. data/app/assets/images/icon-steps/icon-step-11.png +0 -0
  131. data/app/assets/images/icon-steps/icon-step-12-2x.png +0 -0
  132. data/app/assets/images/icon-steps/icon-step-12.png +0 -0
  133. data/app/assets/images/icon-steps/icon-step-13-2x.png +0 -0
  134. data/app/assets/images/icon-steps/icon-step-13.png +0 -0
  135. data/app/assets/images/icon-steps/icon-step-14-2x.png +0 -0
  136. data/app/assets/images/icon-steps/icon-step-14.png +0 -0
  137. data/app/assets/images/icon-steps/icon-step-2-2x.png +0 -0
  138. data/app/assets/images/icon-steps/icon-step-2.png +0 -0
  139. data/app/assets/images/icon-steps/icon-step-3-2x.png +0 -0
  140. data/app/assets/images/icon-steps/icon-step-3.png +0 -0
  141. data/app/assets/images/icon-steps/icon-step-4-2x.png +0 -0
  142. data/app/assets/images/icon-steps/icon-step-4.png +0 -0
  143. data/app/assets/images/icon-steps/icon-step-5-2x.png +0 -0
  144. data/app/assets/images/icon-steps/icon-step-5.png +0 -0
  145. data/app/assets/images/icon-steps/icon-step-6-2x.png +0 -0
  146. data/app/assets/images/icon-steps/icon-step-6.png +0 -0
  147. data/app/assets/images/icon-steps/icon-step-7-2x.png +0 -0
  148. data/app/assets/images/icon-steps/icon-step-7.png +0 -0
  149. data/app/assets/images/icon-steps/icon-step-8-2x.png +0 -0
  150. data/app/assets/images/icon-steps/icon-step-8.png +0 -0
  151. data/app/assets/images/icon-steps/icon-step-9-2x.png +0 -0
  152. data/app/assets/images/icon-steps/icon-step-9.png +0 -0
  153. data/app/assets/images/player-icon-forward.png +0 -0
  154. data/app/assets/images/player-icon-pause.png +0 -0
  155. data/app/assets/images/player-icon-play.png +0 -0
  156. data/app/assets/images/player-icon-rewind.png +0 -0
  157. data/app/assets/images/player-icon-volume.png +0 -0
  158. data/app/assets/images/separator-2x.png +0 -0
  159. data/app/assets/images/separator.png +0 -0
  160. data/app/assets/javascripts/govuk/analytics/analytics.js +143 -0
  161. data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +41 -0
  162. data/app/assets/javascripts/govuk/analytics/error-tracking.js +51 -0
  163. data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +56 -0
  164. data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +166 -0
  165. data/app/assets/javascripts/govuk/analytics/govuk-tracker.js +134 -0
  166. data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +38 -0
  167. data/app/assets/javascripts/govuk/analytics/print-intent.js +39 -0
  168. data/app/assets/javascripts/govuk/details.polyfill.js +240 -0
  169. data/app/assets/javascripts/govuk/modules/auto-track-event.js +30 -0
  170. data/app/assets/javascripts/govuk/modules.js +61 -0
  171. data/app/assets/javascripts/govuk/primary-links.js +57 -0
  172. data/app/assets/javascripts/govuk/selection-buttons.js +116 -0
  173. data/app/assets/javascripts/govuk/shim-links-with-button-role.js +34 -0
  174. data/app/assets/javascripts/govuk/show-hide-content.js +172 -0
  175. data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +128 -0
  176. data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +139 -0
  177. data/app/assets/javascripts/govuk_toolkit.js +1 -0
  178. data/app/assets/javascripts/stageprompt.js +69 -0
  179. data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +25 -0
  180. data/app/assets/javascripts/vendor/polyfills/bind.js +40 -0
  181. data/app/assets/package.json +25 -0
  182. data/app/assets/spec/manifest.js +41 -0
  183. data/app/assets/spec/stylesheets/_colour_contrast_spec.scss +12 -0
  184. data/app/assets/spec/support/LocalTestRunner.html +21 -0
  185. data/app/assets/spec/support/console-runner.js +102 -0
  186. data/app/assets/spec/support/load.js +47 -0
  187. data/app/assets/spec/support/run_jasmine_test.js +62 -0
  188. data/app/assets/spec/unit/analytics/analytics.spec.js +315 -0
  189. data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +72 -0
  190. data/app/assets/spec/unit/analytics/error-tracking.spec.js +65 -0
  191. data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +109 -0
  192. data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +180 -0
  193. data/app/assets/spec/unit/analytics/govuk-tracker.spec.js +171 -0
  194. data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +62 -0
  195. data/app/assets/spec/unit/details.polyfill.spec.js +91 -0
  196. data/app/assets/spec/unit/modules/auto-track-event.spec.js +54 -0
  197. data/app/assets/spec/unit/modules.spec.js +93 -0
  198. data/app/assets/spec/unit/primary-links.spec.js +55 -0
  199. data/app/assets/spec/unit/selection-button.spec.js +761 -0
  200. data/app/assets/spec/unit/shim-links-with-button-role.spec.js +41 -0
  201. data/app/assets/spec/unit/show-hide-content.spec.js +306 -0
  202. data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +137 -0
  203. data/app/assets/stylesheets/.gitkeep +0 -0
  204. data/app/assets/stylesheets/_colours.scss +2 -0
  205. data/app/assets/stylesheets/_conditionals.scss +81 -0
  206. data/app/assets/stylesheets/_css3.scss +90 -0
  207. data/app/assets/stylesheets/_device-pixels.scss +10 -0
  208. data/app/assets/stylesheets/_font_stack.scss +25 -0
  209. data/app/assets/stylesheets/_grid_layout.scss +136 -0
  210. data/app/assets/stylesheets/_helpers.scss +16 -0
  211. data/app/assets/stylesheets/_measurements.scss +14 -0
  212. data/app/assets/stylesheets/_shims.scss +55 -0
  213. data/app/assets/stylesheets/_typography.scss +249 -0
  214. data/app/assets/stylesheets/_url-helpers.scss +16 -0
  215. data/app/assets/stylesheets/colours/_organisation.scss +104 -0
  216. data/app/assets/stylesheets/colours/_palette.scss +77 -0
  217. data/app/assets/stylesheets/design-patterns/_alpha-beta.scss +67 -0
  218. data/app/assets/stylesheets/design-patterns/_breadcrumbs.scss +53 -0
  219. data/app/assets/stylesheets/design-patterns/_buttons.scss +145 -0
  220. data/app/assets/stylesheets/design-patterns/_media-player.scss +264 -0
  221. data/app/assets/trigger.sh +24 -0
  222. data/idsk_frontend_toolkit.gemspec +49 -0
  223. data/lib/idsk_frontend_toolkit/engine.rb +4 -0
  224. data/lib/idsk_frontend_toolkit/version.rb +5 -0
  225. data/lib/idsk_frontend_toolkit.rb +4 -0
  226. data/publish.sh +30 -0
  227. 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
+ ```