govuk_publishing_components 28.2.0 → 28.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-scroll-tracker.js +2 -1
  4. data/app/assets/javascripts/govuk_publishing_components/analytics/auto-track-event.js +22 -22
  5. data/app/assets/javascripts/govuk_publishing_components/analytics/pii.js +9 -5
  6. data/app/assets/javascripts/govuk_publishing_components/analytics/track-click.js +4 -3
  7. data/app/assets/javascripts/govuk_publishing_components/analytics/track-select-change.js +4 -3
  8. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +21 -291
  9. data/app/assets/javascripts/govuk_publishing_components/components/button.js +1 -1
  10. data/app/assets/javascripts/govuk_publishing_components/components/character-count.js +1 -1
  11. data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +1 -2
  12. data/app/assets/javascripts/govuk_publishing_components/components/details.js +3 -4
  13. data/app/assets/javascripts/govuk_publishing_components/components/error-summary.js +1 -1
  14. data/app/assets/javascripts/govuk_publishing_components/components/layout-header.js +1 -1
  15. data/app/assets/javascripts/govuk_publishing_components/components/radio.js +1 -1
  16. data/app/assets/javascripts/govuk_publishing_components/components/skip-link.js +5 -0
  17. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +40 -37
  18. data/app/assets/javascripts/govuk_publishing_components/components/tabs.js +1 -1
  19. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/barchart-enhancement.js +4 -3
  20. data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js +8 -10
  21. data/app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js +4 -3
  22. data/app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js +4 -3
  23. data/app/assets/javascripts/govuk_publishing_components/lib/toggle.js +4 -3
  24. data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +1 -329
  25. data/app/assets/stylesheets/govuk_publishing_components/components/_big-number.scss +5 -2
  26. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +0 -5
  27. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-super-navigation-header.scss +67 -21
  28. data/app/assets/stylesheets/govuk_publishing_components/components/_share-links.scss +3 -3
  29. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +95 -56
  30. data/app/assets/stylesheets/govuk_publishing_components/components/print/_accordion.scss +6 -17
  31. data/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss +0 -9
  32. data/app/views/govuk_publishing_components/components/_accordion.html.erb +30 -15
  33. data/app/views/govuk_publishing_components/components/_action_link.html.erb +1 -1
  34. data/app/views/govuk_publishing_components/components/_big_number.html.erb +12 -8
  35. data/app/views/govuk_publishing_components/components/_button.html.erb +1 -1
  36. data/app/views/govuk_publishing_components/components/_character_count.html.erb +2 -2
  37. data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +2 -2
  38. data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +0 -4
  39. data/app/views/govuk_publishing_components/components/_details.html.erb +1 -1
  40. data/app/views/govuk_publishing_components/components/_error_message.html.erb +1 -1
  41. data/app/views/govuk_publishing_components/components/_error_summary.html.erb +0 -1
  42. data/app/views/govuk_publishing_components/components/_heading.html.erb +1 -1
  43. data/app/views/govuk_publishing_components/components/_hint.html.erb +1 -1
  44. data/app/views/govuk_publishing_components/components/_inset_text.html.erb +12 -1
  45. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +1 -1
  46. data/app/views/govuk_publishing_components/components/_layout_super_navigation_header.html.erb +22 -18
  47. data/app/views/govuk_publishing_components/components/_list.html.erb +1 -1
  48. data/app/views/govuk_publishing_components/components/_modal_dialogue.html.erb +1 -1
  49. data/app/views/govuk_publishing_components/components/_notice.html.erb +1 -1
  50. data/app/views/govuk_publishing_components/components/_print_link.html.erb +2 -2
  51. data/app/views/govuk_publishing_components/components/_radio.html.erb +1 -1
  52. data/app/views/govuk_publishing_components/components/_search.html.erb +2 -2
  53. data/app/views/govuk_publishing_components/components/_select.html.erb +19 -1
  54. data/app/views/govuk_publishing_components/components/_share_links.html.erb +25 -22
  55. data/app/views/govuk_publishing_components/components/_skip_link.html.erb +1 -1
  56. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +1 -1
  57. data/app/views/govuk_publishing_components/components/_textarea.html.erb +1 -1
  58. data/app/views/govuk_publishing_components/components/_title.html.erb +3 -3
  59. data/app/views/govuk_publishing_components/components/docs/accordion.yml +2 -97
  60. data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +0 -47
  61. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +1 -1
  62. data/app/views/govuk_publishing_components/components/docs/inset_text.yml +6 -0
  63. data/app/views/govuk_publishing_components/components/docs/select.yml +12 -0
  64. data/app/views/govuk_publishing_components/components/docs/share_links.yml +1 -1
  65. data/app/views/govuk_publishing_components/components/docs/step_by_step_nav.yml +13 -13
  66. data/app/views/govuk_publishing_components/components/docs/tabs.yml +1 -1
  67. data/app/views/govuk_publishing_components/components/docs/textarea.yml +1 -1
  68. data/app/views/govuk_publishing_components/components/feedback/_problem_form.html.erb +26 -0
  69. data/app/views/govuk_publishing_components/components/feedback/_yes_no_banner.html.erb +14 -8
  70. data/app/views/govuk_publishing_components/components/layout_header/_navigation_items.html.erb +11 -11
  71. data/config/locales/ar.yml +2 -0
  72. data/config/locales/az.yml +2 -1
  73. data/config/locales/be.yml +2 -0
  74. data/config/locales/bg.yml +2 -0
  75. data/config/locales/bn.yml +2 -0
  76. data/config/locales/cs.yml +2 -0
  77. data/config/locales/cy.yml +2 -0
  78. data/config/locales/da.yml +2 -0
  79. data/config/locales/de.yml +2 -0
  80. data/config/locales/dr.yml +2 -0
  81. data/config/locales/el.yml +2 -0
  82. data/config/locales/en.yml +0 -4
  83. data/config/locales/es-419.yml +2 -0
  84. data/config/locales/es.yml +2 -0
  85. data/config/locales/et.yml +2 -0
  86. data/config/locales/fa.yml +2 -1
  87. data/config/locales/fi.yml +2 -0
  88. data/config/locales/fr.yml +2 -0
  89. data/config/locales/gd.yml +2 -0
  90. data/config/locales/gu.yml +2 -0
  91. data/config/locales/he.yml +2 -0
  92. data/config/locales/hi.yml +2 -0
  93. data/config/locales/hr.yml +2 -0
  94. data/config/locales/hu.yml +2 -0
  95. data/config/locales/hy.yml +2 -0
  96. data/config/locales/id.yml +2 -1
  97. data/config/locales/is.yml +2 -0
  98. data/config/locales/it.yml +2 -0
  99. data/config/locales/ja.yml +2 -1
  100. data/config/locales/ka.yml +2 -0
  101. data/config/locales/kk.yml +2 -0
  102. data/config/locales/ko.yml +2 -1
  103. data/config/locales/lt.yml +2 -0
  104. data/config/locales/lv.yml +2 -0
  105. data/config/locales/ms.yml +2 -1
  106. data/config/locales/mt.yml +2 -0
  107. data/config/locales/nl.yml +2 -0
  108. data/config/locales/no.yml +2 -0
  109. data/config/locales/pa-pk.yml +2 -0
  110. data/config/locales/pa.yml +2 -0
  111. data/config/locales/pl.yml +2 -0
  112. data/config/locales/ps.yml +2 -0
  113. data/config/locales/pt.yml +2 -0
  114. data/config/locales/ro.yml +2 -0
  115. data/config/locales/ru.yml +2 -0
  116. data/config/locales/si.yml +2 -0
  117. data/config/locales/sk.yml +2 -0
  118. data/config/locales/sl.yml +2 -0
  119. data/config/locales/so.yml +2 -0
  120. data/config/locales/sq.yml +2 -0
  121. data/config/locales/sr.yml +2 -1
  122. data/config/locales/sv.yml +2 -0
  123. data/config/locales/sw.yml +2 -0
  124. data/config/locales/ta.yml +2 -0
  125. data/config/locales/th.yml +2 -1
  126. data/config/locales/tk.yml +2 -0
  127. data/config/locales/tr.yml +2 -0
  128. data/config/locales/uk.yml +2 -0
  129. data/config/locales/ur.yml +2 -0
  130. data/config/locales/uz.yml +2 -0
  131. data/config/locales/vi.yml +2 -1
  132. data/config/locales/zh-hk.yml +2 -1
  133. data/config/locales/zh-tw.yml +2 -1
  134. data/config/locales/zh.yml +2 -1
  135. data/lib/govuk_publishing_components/presenters/big_number_helper.rb +30 -0
  136. data/lib/govuk_publishing_components/presenters/contextual_navigation.rb +0 -38
  137. data/lib/govuk_publishing_components/version.rb +1 -1
  138. data/lib/govuk_publishing_components.rb +1 -0
  139. data/node_modules/govuk-frontend/govuk/all.js +294 -76
  140. data/node_modules/govuk-frontend/govuk/components/accordion/_index.scss +274 -99
  141. data/node_modules/govuk-frontend/govuk/components/accordion/accordion.js +169 -65
  142. data/node_modules/govuk-frontend/govuk/components/accordion/fixtures.json +37 -5
  143. data/node_modules/govuk-frontend/govuk/components/accordion/macro-options.json +4 -4
  144. data/node_modules/govuk-frontend/govuk/components/button/button.js +2 -2
  145. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +3 -3
  146. data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +15 -2
  147. data/node_modules/govuk-frontend/govuk/components/checkboxes/checkboxes.js +8 -10
  148. data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +52 -15
  149. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_index.scss +0 -2
  150. data/node_modules/govuk-frontend/govuk/components/cookie-banner/fixtures.json +31 -0
  151. data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +25 -25
  152. data/node_modules/govuk-frontend/govuk/components/details/details.js +2 -2
  153. data/node_modules/govuk-frontend/govuk/components/error-message/_index.scss +1 -0
  154. data/node_modules/govuk-frontend/govuk/components/error-message/fixtures.json +8 -8
  155. data/node_modules/govuk-frontend/govuk/components/error-message/template.njk +2 -2
  156. data/node_modules/govuk-frontend/govuk/components/error-summary/error-summary.js +24 -3
  157. data/node_modules/govuk-frontend/govuk/components/error-summary/fixtures.json +25 -16
  158. data/node_modules/govuk-frontend/govuk/components/error-summary/macro-options.json +6 -0
  159. data/node_modules/govuk-frontend/govuk/components/error-summary/template.njk +2 -1
  160. data/node_modules/govuk-frontend/govuk/components/file-upload/fixtures.json +4 -4
  161. data/node_modules/govuk-frontend/govuk/components/footer/_index.scss +3 -37
  162. data/node_modules/govuk-frontend/govuk/components/footer/fixtures.json +119 -15
  163. data/node_modules/govuk-frontend/govuk/components/footer/macro-options.json +6 -0
  164. data/node_modules/govuk-frontend/govuk/components/footer/template.njk +1 -1
  165. data/node_modules/govuk-frontend/govuk/components/header/_index.scss +10 -4
  166. data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +11 -11
  167. data/node_modules/govuk-frontend/govuk/components/header/header.js +4 -4
  168. data/node_modules/govuk-frontend/govuk/components/header/template.njk +4 -3
  169. data/node_modules/govuk-frontend/govuk/components/hint/_index.scss +1 -3
  170. data/node_modules/govuk-frontend/govuk/components/input/_index.scss +1 -1
  171. data/node_modules/govuk-frontend/govuk/components/input/fixtures.json +40 -40
  172. data/node_modules/govuk-frontend/govuk/components/input/template.njk +4 -3
  173. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +499 -2
  174. data/node_modules/govuk-frontend/govuk/components/phase-banner/fixtures.json +2 -2
  175. data/node_modules/govuk-frontend/govuk/components/radios/_index.scss +0 -8
  176. data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +44 -45
  177. data/node_modules/govuk-frontend/govuk/components/radios/radios.js +4 -4
  178. data/node_modules/govuk-frontend/govuk/components/radios/template.njk +2 -9
  179. data/node_modules/govuk-frontend/govuk/components/select/_index.scss +6 -1
  180. data/node_modules/govuk-frontend/govuk/components/select/fixtures.json +3 -3
  181. data/node_modules/govuk-frontend/govuk/components/skip-link/_index.scss +13 -0
  182. data/node_modules/govuk-frontend/govuk/components/skip-link/fixtures.json +9 -9
  183. data/node_modules/govuk-frontend/govuk/components/skip-link/skip-link.js +1108 -0
  184. data/node_modules/govuk-frontend/govuk/components/skip-link/template.njk +1 -1
  185. data/node_modules/govuk-frontend/govuk/components/summary-list/_index.scss +20 -23
  186. data/node_modules/govuk-frontend/govuk/components/summary-list/fixtures.json +86 -1
  187. data/node_modules/govuk-frontend/govuk/components/summary-list/template.njk +1 -4
  188. data/node_modules/govuk-frontend/govuk/components/tabs/_index.scss +2 -2
  189. data/node_modules/govuk-frontend/govuk/components/tabs/tabs.js +2 -2
  190. data/node_modules/govuk-frontend/govuk/components/tag/_index.scss +0 -5
  191. data/node_modules/govuk-frontend/govuk/components/tag/fixtures.json +2 -2
  192. data/node_modules/govuk-frontend/govuk/components/textarea/_index.scss +1 -1
  193. data/node_modules/govuk-frontend/govuk/components/textarea/fixtures.json +4 -4
  194. data/node_modules/govuk-frontend/govuk/core/_all.scss +0 -1
  195. data/node_modules/govuk-frontend/govuk/core/_global-styles.scss +0 -6
  196. data/node_modules/govuk-frontend/govuk/core/_links.scss +0 -6
  197. data/node_modules/govuk-frontend/govuk/core/_lists.scss +0 -6
  198. data/node_modules/govuk-frontend/govuk/core/_section-break.scss +0 -6
  199. data/node_modules/govuk-frontend/govuk/core/_typography.scss +0 -6
  200. data/node_modules/govuk-frontend/govuk/objects/_all.scss +1 -0
  201. data/node_modules/govuk-frontend/govuk/objects/_main-wrapper.scss +15 -30
  202. data/node_modules/govuk-frontend/govuk/{core → objects}/_template.scss +1 -5
  203. data/node_modules/govuk-frontend/govuk/overrides/_display.scss +0 -6
  204. data/node_modules/govuk-frontend/govuk/overrides/_spacing.scss +0 -6
  205. data/node_modules/govuk-frontend/govuk/overrides/_text-align.scss +0 -6
  206. data/node_modules/govuk-frontend/govuk/overrides/_typography.scss +0 -6
  207. data/node_modules/govuk-frontend/govuk/overrides/_width.scss +0 -6
  208. data/node_modules/govuk-frontend/govuk/settings/_colours-organisations.scss +3 -0
  209. data/node_modules/govuk-frontend/govuk/settings/_measurements.scss +0 -10
  210. data/node_modules/govuk-frontend/govuk/tools/_all.scss +0 -1
  211. data/node_modules/govuk-frontend/package.json +1 -1
  212. metadata +11 -16
  213. data/app/views/govuk_publishing_components/components/contextual_sidebar/_covid_cta.html.erb +0 -27
  214. data/node_modules/govuk-frontend/govuk/tools/_iff.scss +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0989b4b0c9bafbc71f0347de67fb337acee0cfb13da092fae2be8c6c35122d32'
4
- data.tar.gz: e56b816c73f788ca8bfd9383fe39db912a84f5a14b141bb258cd7e7fcc526919
3
+ metadata.gz: 85985bab4532c5cbccfa05369e032e61cedfda7468ab5654d10ce0eb937155b8
4
+ data.tar.gz: fd00b4c1e0784b1951f0103412dc7dd2eaf619d2ad72456c77b892903fc1cd9a
5
5
  SHA512:
6
- metadata.gz: 384f96c451155a016bbfea69596892e4ed287afa095a0780570d07842c62498f3de4890819e1d87e173a856178e74d34e3f6561562aa8b5e9e2fe7a5974a2380
7
- data.tar.gz: b8e6166d94e9536640edca9e877f8bec63429596dfe7c563f2521b2254b4acbcadd7decf26ffbc64ca28b14a8a5bd2b02d8fb7ceba35a2d523c3c65641b8d3fb
6
+ metadata.gz: fd73aa7768ba4224e03065bb8b04becf3e4c227c50422eb5255ab52fe82a075a8e5968d143ecb80bbc3f3481432783ab1ef7dad55515801f2905c2449676989d
7
+ data.tar.gz: 6b0541c15147aedcbbd890cb222d280ba02f492fb84d5a280580b5fa6d64a58f6e5a80ae2277bd9667e3e9c7a9c28b22ba2ef590400b5b047230cb3e0036f41b
data/README.md CHANGED
@@ -27,7 +27,7 @@ bundle exec rake
27
27
 
28
28
  To run JavaScript tests (only):
29
29
 
30
- ```
30
+ ```sh
31
31
  # run JS tests in browser
32
32
  bin/rake app:jasmine
33
33
 
@@ -199,7 +199,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
199
199
 
200
200
  for (var i = 0; i < this.config.percentages.length; i++) {
201
201
  var percent = this.config.percentages[i]
202
- var pos = (pageHeight / 100) * percent
202
+ // subtract 1 pixel to solve a bug where 100% can't be reached in some cases
203
+ var pos = ((pageHeight / 100) * percent) - 1
203
204
  var alreadySeen = false
204
205
  if (trackedNodes.length) {
205
206
  alreadySeen = trackedNodes[i].alreadySeen
@@ -1,30 +1,30 @@
1
- ;(function (global) {
2
- 'use strict'
1
+ window.GOVUK = window.GOVUK || {}
2
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
3
3
 
4
- var GOVUK = global.GOVUK || {}
5
- GOVUK.Modules = GOVUK.Modules || {}
4
+ (function (Modules) {
5
+ function AutoTrackEvent ($module) {
6
+ this.$module = $module
7
+ }
6
8
 
7
- GOVUK.Modules.AutoTrackEvent = function () {
8
- this.start = function (element) {
9
- var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
10
- var category = element.data('track-category')
11
- var action = element.data('track-action')
12
- var label = element.data('track-label')
13
- var value = element.data('track-value')
9
+ AutoTrackEvent.prototype.init = function () {
10
+ var options = { nonInteraction: 1 } // automatic events shouldn't affect bounce rate
11
+ var category = this.$module.getAttribute('data-track-category')
12
+ var action = this.$module.getAttribute('data-track-action')
13
+ var label = this.$module.getAttribute('data-track-label')
14
+ var value = parseInt(this.$module.getAttribute('data-track-value'))
14
15
 
15
- if (typeof label === 'string') {
16
- options.label = label
17
- }
16
+ if (typeof label === 'string') {
17
+ options.label = label
18
+ }
18
19
 
19
- if (value || value === 0) {
20
- options.value = value
21
- }
20
+ if (value || value === 0) {
21
+ options.value = value
22
+ }
22
23
 
23
- if (GOVUK.analytics && GOVUK.analytics.trackEvent) {
24
- GOVUK.analytics.trackEvent(category, action, options)
25
- }
24
+ if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
25
+ window.GOVUK.analytics.trackEvent(category, action, options)
26
26
  }
27
27
  }
28
28
 
29
- global.GOVUK = GOVUK
30
- })(window)
29
+ Modules.AutoTrackEvent = AutoTrackEvent
30
+ })(window.GOVUK.Modules)
@@ -1,5 +1,3 @@
1
- /* global $ */
2
-
3
1
  ;(function (global) {
4
2
  'use strict'
5
3
 
@@ -15,15 +13,21 @@
15
13
  var STATE_PATTERN = /state=.[^&]+/g
16
14
 
17
15
  function shouldStripDates () {
18
- return ($('meta[name="govuk:static-analytics:strip-dates"]').length > 0)
16
+ var metas = document.querySelectorAll('meta[name="govuk:static-analytics:strip-dates"]')
17
+ return metas.length > 0
19
18
  }
20
19
 
21
20
  function shouldStripPostcodes () {
22
- return ($('meta[name="govuk:static-analytics:strip-postcodes"]').length > 0)
21
+ var metas = document.querySelectorAll('meta[name="govuk:static-analytics:strip-postcodes"]')
22
+ return metas.length > 0
23
23
  }
24
24
 
25
25
  function queryStringParametersToStrip () {
26
- var value = $('meta[name="govuk:static-analytics:strip-query-string-parameters"]').attr('content')
26
+ var meta = document.querySelector('meta[name="govuk:static-analytics:strip-query-string-parameters"]')
27
+ var value = false
28
+ if (meta) {
29
+ value = meta.getAttribute('content')
30
+ }
27
31
  var parameters = []
28
32
 
29
33
  if (value) {
@@ -4,10 +4,11 @@ window.GOVUK = window.GOVUK || {}
4
4
  window.GOVUK.Modules = window.GOVUK.Modules || {};
5
5
 
6
6
  (function (Modules) {
7
- function GemTrackClick () { }
7
+ function GemTrackClick ($module) {
8
+ this.$module = $module
9
+ }
8
10
 
9
- GemTrackClick.prototype.start = function ($module) {
10
- this.$module = $module[0]
11
+ GemTrackClick.prototype.init = function () {
11
12
  this.$module.handleClick = this.handleClick.bind(this)
12
13
  var trackLinksOnly = this.$module.hasAttribute('data-track-links-only')
13
14
  var limitToElementClass = this.$module.getAttribute('data-limit-to-element-class')
@@ -2,10 +2,11 @@ window.GOVUK = window.GOVUK || {}
2
2
  window.GOVUK.Modules = window.GOVUK.Modules || {};
3
3
 
4
4
  (function (Modules) {
5
- function TrackSelectChange () { }
5
+ function TrackSelectChange ($module) {
6
+ this.$module = $module
7
+ }
6
8
 
7
- TrackSelectChange.prototype.start = function ($module) {
8
- this.$module = $module[0]
9
+ TrackSelectChange.prototype.init = function ($module) {
9
10
  this.$module.trackChange = this.trackChange.bind(this)
10
11
  this.$module.fireTrackingChange = this.fireTrackingChange.bind(this)
11
12
  this.$module.addEventListener('change', this.trackChange)
@@ -1,32 +1,18 @@
1
1
  /* global nodeListForEach */
2
- // = require ../vendor/polyfills/closest.js
3
- // = require ../vendor/polyfills/indexOf.js
4
2
  // = require ../vendor/polyfills/common.js
5
-
3
+ // This component relies on JavaScript from GOV.UK Frontend
4
+ // = require govuk/components/accordion/accordion.js
6
5
  window.GOVUK = window.GOVUK || {}
7
- window.GOVUK.Modules = window.GOVUK.Modules || {};
6
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
7
+ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
8
8
 
9
9
  (function (Modules) {
10
10
  function GemAccordion ($module) {
11
11
  this.$module = $module
12
- this.sectionClass = 'gem-c-accordion__section'
13
- this.moduleId = this.$module.getAttribute('id')
14
- this.sections = this.$module.querySelectorAll('.' + this.sectionClass)
15
- this.openAllButton = ''
16
- this.controlsClass = 'gem-c-accordion__controls'
17
- this.openAllClass = 'gem-c-accordion__open-all'
18
- this.openAllTextClass = 'gem-c-accordion__open-all-text'
19
- this.sectionHeaderClass = 'gem-c-accordion__section-header'
20
- this.sectionHeadingClass = 'gem-c-accordion__section-heading'
21
- this.sectionSummaryClass = 'gem-c-accordion__section-summary'
22
- this.sectionButtonClass = 'gem-c-accordion__section-button'
23
- this.sectionExpandedClass = 'gem-c-accordion__section--expanded'
24
- this.sectionInnerContent = 'gem-c-accordion__section-content'
25
- this.toggleLinkClass = 'js-toggle-link'
26
- this.sectionShowHideIconClass = 'gem-c-accordion__toggle-link'
27
- this.sectionShowHideTextClass = 'gem-c-accordion__toggle-text'
28
- this.upChevonIconClass = 'gem-c-accordion-nav__chevron'
29
- this.downChevonIconClass = 'gem-c-accordion-nav__chevron--down'
12
+ this.sectionClass = 'govuk-accordion__section'
13
+ this.sectionClassExpanded = 'govuk-accordion__section--expanded'
14
+ this.sectionHeaderClass = 'govuk-accordion__section-header'
15
+ this.sectionInnerContent = 'govuk-accordion__section-content'
30
16
 
31
17
  // Translated component content and language attribute pulled from data attributes
32
18
  this.$module.actions = {}
@@ -39,279 +25,14 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
39
25
  }
40
26
 
41
27
  GemAccordion.prototype.init = function () {
42
- this.browserSupportsSessionStorage = helper.checkForSessionStorage()
43
-
44
28
  // Indicate that JavaScript has worked
45
29
  this.$module.classList.add('gem-c-accordion--active')
46
30
 
47
- this.initControls()
48
- this.initSectionHeaders()
49
-
50
31
  // Feature flag for anchor tag navigation used on manuals
51
32
  if (this.$module.getAttribute('data-anchor-navigation') === 'true') {
52
33
  this.openByAnchorOnLoad()
53
34
  this.addEventListenersForAnchors()
54
35
  }
55
-
56
- // See if "Show all sections" button text should be updated
57
- var areAllSectionsOpen = this.checkIfAllSectionsOpen()
58
- this.updateOpenAllButton(areAllSectionsOpen)
59
- }
60
-
61
- // Initialise controls and set attributes
62
- GemAccordion.prototype.initControls = function () {
63
- // Create "Show all" button and set attributes
64
- this.openAllButton = document.createElement('button')
65
- this.openAllButton.setAttribute('class', this.openAllClass)
66
- this.openAllButton.setAttribute('aria-expanded', 'false')
67
-
68
- // Create icon, add to element
69
- var icon = document.createElement('span')
70
- icon.classList.add(this.upChevonIconClass)
71
- this.openAllButton.appendChild(icon)
72
-
73
- // Create control wrapper and add controls to it
74
- var accordionControls = document.createElement('div')
75
- accordionControls.setAttribute('class', this.controlsClass)
76
- accordionControls.appendChild(this.openAllButton)
77
- this.$module.insertBefore(accordionControls, this.$module.firstChild)
78
-
79
- // Build additional wrapper for open all toggle text, place icon after wrapped text.
80
- var wrapperOpenAllText = document.createElement('span')
81
- wrapperOpenAllText.classList.add(this.openAllTextClass)
82
- this.openAllButton.insertBefore(wrapperOpenAllText, this.openAllButton.childNodes[0] || null)
83
-
84
- // Handle events for the controls
85
- this.openAllButton.addEventListener('click', this.onOpenOrCloseAllToggle.bind(this))
86
- }
87
-
88
- // Initialise section headers
89
- GemAccordion.prototype.initSectionHeaders = function () {
90
- // Loop through section headers
91
- nodeListForEach(this.sections, function (section, i) {
92
- // Set header attributes
93
- var header = section.querySelector('.' + this.sectionHeaderClass)
94
-
95
- this.initHeaderAttributes(header, i)
96
- this.setExpanded(this.isExpanded(section), section)
97
-
98
- // Handle events
99
- header.addEventListener('click', this.onSectionToggle.bind(this, section))
100
-
101
- // See if there is any state stored in sessionStorage and set the sections to
102
- // open or closed.
103
- this.setInitialState(section)
104
- }.bind(this))
105
- }
106
-
107
- // Set individual header attributes
108
- GemAccordion.prototype.initHeaderAttributes = function (headerWrapper, index) {
109
- var span = headerWrapper.querySelector('.' + this.sectionButtonClass)
110
- var heading = headerWrapper.querySelector('.' + this.sectionHeadingClass)
111
- var summary = headerWrapper.querySelector('.' + this.sectionSummaryClass)
112
-
113
- // Copy existing span element to an actual button element, for improved accessibility.
114
- var button = document.createElement('button')
115
- button.setAttribute('id', this.moduleId + '-heading-' + (index + 1))
116
- button.setAttribute('aria-controls', this.moduleId + '-content-' + (index + 1))
117
-
118
- // Create show / hide arrow icons with text.
119
- var showIcons = document.createElement('span')
120
- showIcons.classList.add(this.sectionShowHideIconClass, this.toggleLinkClass)
121
-
122
- // Add pause after heading for assistive technology.
123
- var srPause = document.createElement('span')
124
- srPause.classList.add('govuk-visually-hidden')
125
- srPause.innerHTML = ', '
126
-
127
- // Build additional copy for assistive technology
128
- var srAdditionalCopy = document.createElement('span')
129
- srAdditionalCopy.classList.add('govuk-visually-hidden')
130
- srAdditionalCopy.innerHTML = this.$module.actions.thisSectionVisuallyHidden
131
-
132
- if (this.$module.actions.locale) {
133
- srAdditionalCopy.lang = this.filterLocale('this_section_visually_hidden')
134
- }
135
-
136
- // Build additional wrapper for toggle text, place icon after wrapped text.
137
- var wrapperShowHideIcon = document.createElement('span')
138
- var icon = document.createElement('span')
139
- icon.classList.add(this.upChevonIconClass)
140
- showIcons.appendChild(icon)
141
- wrapperShowHideIcon.classList.add(this.sectionShowHideTextClass)
142
- showIcons.insertBefore(wrapperShowHideIcon, showIcons.childNodes[0] || null)
143
-
144
- // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from span to button
145
- for (var i = 0; i < span.attributes.length; i++) {
146
- var attr = span.attributes.item(i)
147
- button.setAttribute(attr.nodeName, attr.nodeValue)
148
- }
149
-
150
- // span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
151
- button.innerHTML = span.innerHTML
152
- heading.removeChild(span)
153
- heading.appendChild(button)
154
- button.appendChild(srPause)
155
-
156
- // If summary content exists add to DOM in correct order
157
- if (typeof (summary) !== 'undefined' && summary !== null) {
158
- button.setAttribute('aria-describedby', this.moduleId + '-summary-' + (index + 1))
159
- button.appendChild(summary)
160
- }
161
-
162
- button.appendChild(showIcons)
163
- button.appendChild(srAdditionalCopy)
164
- }
165
-
166
- // When section toggled, set and store state
167
- GemAccordion.prototype.onSectionToggle = function (section) {
168
- var expanded = this.isExpanded(section)
169
- this.setExpanded(!expanded, section)
170
-
171
- // Store the state in sessionStorage when a change is triggered
172
- this.storeState(section)
173
- }
174
-
175
- // When Open/Close All toggled, set and store state
176
- GemAccordion.prototype.onOpenOrCloseAllToggle = function () {
177
- var module = this
178
- var sections = this.sections
179
- var nowExpanded = !this.checkIfAllSectionsOpen()
180
-
181
- nodeListForEach(sections, function (section) {
182
- module.setExpanded(nowExpanded, section)
183
- // Store the state in sessionStorage when a change is triggered
184
- module.storeState(section)
185
- })
186
-
187
- module.updateOpenAllButton(nowExpanded)
188
- }
189
-
190
- // Set section attributes when opened/closed
191
- GemAccordion.prototype.setExpanded = function (expanded, section) {
192
- var icon = section.querySelector('.' + this.upChevonIconClass)
193
- var showHideText = section.querySelector('.' + this.sectionShowHideTextClass)
194
- var button = section.querySelector('.' + this.sectionButtonClass)
195
- var newButtonText = expanded ? this.$module.actions.hideText : this.$module.actions.showText
196
-
197
- showHideText.innerHTML = newButtonText
198
- button.setAttribute('aria-expanded', expanded)
199
- button.classList.add(this.toggleLinkClass)
200
-
201
- if (this.$module.actions.locale) {
202
- showHideText.lang = this.filterLocale(expanded ? 'hide_text' : 'show_text')
203
- }
204
-
205
- // Swap icon, change class
206
- if (expanded) {
207
- section.classList.add(this.sectionExpandedClass)
208
- icon.classList.remove(this.downChevonIconClass)
209
- } else {
210
- section.classList.remove(this.sectionExpandedClass)
211
- icon.classList.add(this.downChevonIconClass)
212
- }
213
-
214
- // See if "Show all sections" button text should be updated
215
- var areAllSectionsOpen = this.checkIfAllSectionsOpen()
216
- this.updateOpenAllButton(areAllSectionsOpen)
217
- }
218
-
219
- // Get state of section
220
- GemAccordion.prototype.isExpanded = function (section) {
221
- return section.classList.contains(this.sectionExpandedClass)
222
- }
223
-
224
- // Check if all sections are open
225
- GemAccordion.prototype.checkIfAllSectionsOpen = function () {
226
- // Get a count of all the Accordion sections
227
- var sectionsCount = this.sections.length
228
- // Get a count of all Accordion sections that are expanded
229
- var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length
230
- var areAllSectionsOpen = sectionsCount === expandedSectionCount
231
-
232
- return areAllSectionsOpen
233
- }
234
-
235
- // Update "Show all sections" button
236
- GemAccordion.prototype.updateOpenAllButton = function (expanded) {
237
- var icon = this.openAllButton.querySelector('.' + this.upChevonIconClass)
238
- var openAllCopy = this.openAllButton.querySelector('.' + this.openAllTextClass)
239
- var newButtonText = expanded ? this.$module.actions.hideAllText : this.$module.actions.showAllText
240
-
241
- this.openAllButton.setAttribute('aria-expanded', expanded)
242
- openAllCopy.innerHTML = newButtonText
243
-
244
- if (this.$module.actions.locale) {
245
- openAllCopy.lang = this.filterLocale(expanded ? 'hide_all_text' : 'show_all_text')
246
- }
247
-
248
- // Swap icon, toggle class
249
- if (expanded) {
250
- icon.classList.remove(this.downChevonIconClass)
251
- } else {
252
- icon.classList.add(this.downChevonIconClass)
253
- }
254
- }
255
-
256
- var helper = {
257
- checkForSessionStorage: function () {
258
- var testString = 'this is the test string'
259
- var result
260
- try {
261
- window.sessionStorage.setItem(testString, testString)
262
- result = window.sessionStorage.getItem(testString) === testString.toString()
263
- window.sessionStorage.removeItem(testString)
264
- return result
265
- } catch (exception) {
266
- if ((typeof console === 'undefined' || typeof console.log === 'undefined')) {
267
- console.log('Notice: sessionStorage not available.')
268
- }
269
- }
270
- }
271
- }
272
-
273
- // Set the state of the accordions in sessionStorage
274
- GemAccordion.prototype.storeState = function (section) {
275
- if (this.browserSupportsSessionStorage) {
276
- // We need a unique way of identifying each content in the GemAccordion. Since
277
- // an `#id` should be unique and an `id` is required for `aria-` attributes
278
- // `id` can be safely used.
279
- var button = section.querySelector('.' + this.sectionButtonClass)
280
-
281
- if (button) {
282
- var contentId = button.getAttribute('aria-controls')
283
- var contentState = button.getAttribute('aria-expanded')
284
-
285
- if (typeof contentId === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
286
- console.error(new Error('No aria controls present in accordion section heading.'))
287
- }
288
-
289
- if (typeof contentState === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
290
- console.error(new Error('No aria expanded present in accordion section heading.'))
291
- }
292
-
293
- // Only set the state when both `contentId` and `contentState` are taken from the DOM.
294
- if (contentId && contentState) {
295
- window.sessionStorage.setItem(contentId, contentState)
296
- }
297
- }
298
- }
299
- }
300
-
301
- // Read the state of the accordions from sessionStorage
302
- GemAccordion.prototype.setInitialState = function (section) {
303
- if (this.browserSupportsSessionStorage) {
304
- var button = section.querySelector('.' + this.sectionButtonClass)
305
-
306
- if (button) {
307
- var contentId = button.getAttribute('aria-controls')
308
- var contentState = contentId ? window.sessionStorage.getItem(contentId) : null
309
-
310
- if (contentState !== null) {
311
- this.setExpanded(contentState === 'true', section)
312
- }
313
- }
314
- }
315
36
  }
316
37
 
317
38
  // Navigate to and open accordions with anchored content on page load if a hash is present
@@ -327,6 +48,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
327
48
  // Adding an event listener to all anchor link a tags in an accordion is risky but we circumvent this risk partially by only being a layer of accordion behaviour instead of any sort of change to link behaviour
328
49
  GemAccordion.prototype.addEventListenersForAnchors = function () {
329
50
  var links = this.$module.querySelectorAll('.' + this.sectionInnerContent + ' a[href*="#"]')
51
+
330
52
  nodeListForEach(links, function (link) {
331
53
  if (link.pathname === window.location.pathname) {
332
54
  link.addEventListener('click', this.openForAnchor.bind(this, link.hash.split('#')[1]))
@@ -337,9 +59,18 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
337
59
  // Find the parent accordion section for the given id and open it
338
60
  GemAccordion.prototype.openForAnchor = function (hash) {
339
61
  var target = document.getElementById(hash)
340
- var section = this.getContainingSection(target)
341
-
342
- this.setExpanded(true, section)
62
+ var $section = this.getContainingSection(target)
63
+ var $header = $section.querySelector('.' + this.sectionHeaderClass)
64
+ var $expanded = this.getContainingSection($section)
65
+ var $parent = $header.parentElement
66
+
67
+ // manuals-frontend features:
68
+ // Should the target anchor link be within the same page, open section - navigate normally
69
+ // Should the target anchor link be within a different, closed section, open this section
70
+ // Should the target anchor link be within a different page and different, closed section open this section
71
+ if ($expanded && (!$parent.classList.contains(this.sectionClassExpanded))) {
72
+ $header.click()
73
+ }
343
74
  }
344
75
 
345
76
  // Loop through the given id's ancestors until the parent section class is found
@@ -347,7 +78,6 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
347
78
  while (!target.classList.contains(this.sectionClass)) {
348
79
  target = target.parentElement
349
80
  }
350
-
351
81
  return target
352
82
  }
353
83
 
@@ -2,4 +2,4 @@
2
2
  // = require govuk/components/button/button.js
3
3
  window.GOVUK = window.GOVUK || {}
4
4
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.GovukButton = window.GOVUKFrontend
5
+ window.GOVUK.Modules.GovukButton = window.GOVUKFrontend.Button
@@ -2,4 +2,4 @@
2
2
  // = require govuk/components/character-count/character-count.js
3
3
  window.GOVUK = window.GOVUK || {}
4
4
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.GovukCharacterCount = window.GOVUKFrontend
5
+ window.GOVUK.Modules.GovukCharacterCount = window.GOVUKFrontend.CharacterCount
@@ -1,9 +1,8 @@
1
- /* eslint-env jquery */
2
1
  // = require govuk/vendor/polyfills/Element/prototype/closest.js
3
2
  // = require govuk/components/checkboxes/checkboxes.js
4
3
  window.GOVUK = window.GOVUK || {}
5
4
  window.GOVUK.Modules = window.GOVUK.Modules || {}
6
- window.GOVUK.Modules.GovukCheckboxes = window.GOVUKFrontend;
5
+ window.GOVUK.Modules.GovukCheckboxes = window.GOVUKFrontend.Checkboxes;
7
6
 
8
7
  (function (Modules) {
9
8
  function GemCheckboxes ($module) {
@@ -1,8 +1,7 @@
1
- /* eslint-env jquery */
2
1
  // = require govuk/components/details/details.js
3
2
  window.GOVUK = window.GOVUK || {}
4
3
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.GovukDetails = window.GOVUKFrontend;
4
+ window.GOVUK.Modules.GovukDetails = window.GOVUKFrontend.Details;
6
5
 
7
6
  (function (Modules) {
8
7
  function GemDetails ($module) {
@@ -15,8 +14,8 @@ window.GOVUK.Modules.GovukDetails = window.GOVUKFrontend;
15
14
 
16
15
  GemDetails.prototype.init = function () {
17
16
  if (this.customTrackLabel) { // If a custom label has been provided, we can simply call the tracking module
18
- var trackDetails = new window.GOVUK.Modules.GemTrackClick()
19
- trackDetails.start($(this.$summary))
17
+ var trackDetails = new window.GOVUK.Modules.GemTrackClick(this.$summary)
18
+ trackDetails.init()
20
19
  } else if (this.detailsClick) { // If no custom label is set, we use the open/close status as the label
21
20
  this.detailsClick.addEventListener('click', function (event) {
22
21
  this.trackDefault(this.$summary)
@@ -2,4 +2,4 @@
2
2
  // = require govuk/components/error-summary/error-summary.js
3
3
  window.GOVUK = window.GOVUK || {}
4
4
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.GovukErrorSummary = window.GOVUKFrontend
5
+ window.GOVUK.Modules.GovukErrorSummary = window.GOVUKFrontend.ErrorSummary
@@ -2,4 +2,4 @@
2
2
  // = require govuk/components/header/header.js
3
3
  window.GOVUK = window.GOVUK || {}
4
4
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.GovukHeader = window.GOVUKFrontend
5
+ window.GOVUK.Modules.GovukHeader = window.GOVUKFrontend.Header
@@ -2,4 +2,4 @@
2
2
  // = require govuk/components/radios/radios.js
3
3
  window.GOVUK = window.GOVUK || {}
4
4
  window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.GovukRadios = window.GOVUKFrontend
5
+ window.GOVUK.Modules.GovukRadios = window.GOVUKFrontend.Radios
@@ -0,0 +1,5 @@
1
+ // This component relies on JavaScript from GOV.UK Frontend
2
+ // = require govuk/components/skip-link/skip-link.js
3
+ window.GOVUK = window.GOVUK || {}
4
+ window.GOVUK.Modules = window.GOVUK.Modules || {}
5
+ window.GOVUK.Modules.GovukSkipLink = window.GOVUKFrontend.SkipLink