govuk_publishing_components 23.13.0 → 24.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/govuk_publishing_components/take-action-amber.svg +4 -0
  3. data/app/assets/images/govuk_publishing_components/take-action-green.svg +4 -0
  4. data/app/assets/images/govuk_publishing_components/take-action-red.svg +4 -0
  5. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +286 -4
  6. data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +0 -4
  7. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +44 -39
  8. data/app/assets/javascripts/govuk_publishing_components/vendor/polyfills/common.js +8 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +0 -1
  10. data/app/assets/stylesheets/govuk_publishing_components/component_support.scss +0 -2
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +302 -14
  12. data/app/assets/stylesheets/govuk_publishing_components/components/_contextual-sidebar.scss +34 -17
  13. data/app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss +14 -8
  14. data/app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss +4 -4
  15. data/app/assets/stylesheets/govuk_publishing_components/components/_feedback.scss +35 -44
  16. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +112 -47
  17. data/app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss +8 -8
  18. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +0 -5
  19. data/app/assets/stylesheets/govuk_publishing_components/components/print/_accordion.scss +16 -9
  20. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav.scss +2 -2
  21. data/app/models/govuk_publishing_components/component_doc.rb +1 -1
  22. data/app/views/govuk_publishing_components/audit/show.html.erb +26 -26
  23. data/app/views/govuk_publishing_components/components/_accordion.html.erb +13 -20
  24. data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +2 -8
  25. data/app/views/govuk_publishing_components/components/_document_list.html.erb +12 -2
  26. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +9 -4
  27. data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +2 -2
  28. data/app/views/govuk_publishing_components/components/contextual_sidebar/_brexit_cta.html.erb +21 -0
  29. data/app/views/govuk_publishing_components/components/docs/accordion.yml +8 -3
  30. data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +65 -1
  31. data/app/views/govuk_publishing_components/components/docs/document_list.yml +50 -7
  32. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +3 -3
  33. data/app/views/govuk_publishing_components/components/docs/layout_header.yml +11 -0
  34. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
  35. data/app/views/govuk_publishing_components/components/layout_header/_navigation_items.html.erb +9 -4
  36. data/config/initializers/assets.rb +3 -1
  37. data/config/locales/cy.yml +6 -1
  38. data/config/locales/en.yml +8 -3
  39. data/lib/govuk_publishing_components/presenters/contextual_navigation.rb +183 -2
  40. data/lib/govuk_publishing_components/version.rb +1 -1
  41. data/node_modules/govuk-frontend/govuk/all.js +58 -1
  42. data/node_modules/govuk-frontend/govuk/components/_all.scss +2 -0
  43. data/node_modules/govuk-frontend/govuk/components/accordion/fixtures.json +25 -10
  44. data/node_modules/govuk-frontend/govuk/components/back-link/fixtures.json +12 -6
  45. data/node_modules/govuk-frontend/govuk/components/back-link/macro-options.json +4 -4
  46. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/fixtures.json +34 -13
  47. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/macro-options.json +1 -0
  48. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/template.njk +2 -2
  49. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +2 -0
  50. data/node_modules/govuk-frontend/govuk/components/button/fixtures.json +74 -31
  51. data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +1 -0
  52. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +1 -1
  53. data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +85 -15
  54. data/node_modules/govuk-frontend/govuk/components/character-count/macro-options.json +1 -1
  55. data/node_modules/govuk-frontend/govuk/components/checkboxes/fixtures.json +145 -52
  56. data/node_modules/govuk-frontend/govuk/components/checkboxes/macro-options.json +2 -2
  57. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_cookie-banner.scss +2 -0
  58. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_index.scss +51 -0
  59. data/node_modules/govuk-frontend/govuk/components/cookie-banner/fixtures.json +425 -0
  60. data/node_modules/govuk-frontend/govuk/components/cookie-banner/macro-options.json +132 -0
  61. data/node_modules/govuk-frontend/govuk/components/cookie-banner/macro.njk +3 -0
  62. data/node_modules/govuk-frontend/govuk/components/cookie-banner/template.njk +63 -0
  63. data/node_modules/govuk-frontend/govuk/components/date-input/fixtures.json +84 -34
  64. data/node_modules/govuk-frontend/govuk/components/date-input/macro-options.json +1 -1
  65. data/node_modules/govuk-frontend/govuk/components/date-input/template.njk +1 -1
  66. data/node_modules/govuk-frontend/govuk/components/details/fixtures.json +35 -15
  67. data/node_modules/govuk-frontend/govuk/components/error-message/fixtures.json +21 -10
  68. data/node_modules/govuk-frontend/govuk/components/error-message/macro-options.json +1 -0
  69. data/node_modules/govuk-frontend/govuk/components/error-summary/_index.scss +2 -12
  70. data/node_modules/govuk-frontend/govuk/components/error-summary/fixtures.json +86 -25
  71. data/node_modules/govuk-frontend/govuk/components/fieldset/fixtures.json +20 -10
  72. data/node_modules/govuk-frontend/govuk/components/file-upload/fixtures.json +60 -13
  73. data/node_modules/govuk-frontend/govuk/components/footer/fixtures.json +37 -18
  74. data/node_modules/govuk-frontend/govuk/components/footer/macro-options.json +8 -5
  75. data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +36 -18
  76. data/node_modules/govuk-frontend/govuk/components/header/macro-options.json +2 -2
  77. data/node_modules/govuk-frontend/govuk/components/header/template.njk +4 -4
  78. data/node_modules/govuk-frontend/govuk/components/hint/fixtures.json +17 -8
  79. data/node_modules/govuk-frontend/govuk/components/input/fixtures.json +130 -40
  80. data/node_modules/govuk-frontend/govuk/components/input/macro-options.json +1 -1
  81. data/node_modules/govuk-frontend/govuk/components/inset-text/fixtures.json +17 -8
  82. data/node_modules/govuk-frontend/govuk/components/label/fixtures.json +20 -11
  83. data/node_modules/govuk-frontend/govuk/components/label/macro-options.json +1 -1
  84. data/node_modules/govuk-frontend/govuk/components/notification-banner/README.md +15 -0
  85. data/node_modules/govuk-frontend/govuk/components/notification-banner/_index.scss +89 -0
  86. data/node_modules/govuk-frontend/govuk/components/notification-banner/_notification-banner.scss +2 -0
  87. data/node_modules/govuk-frontend/govuk/components/notification-banner/fixtures.json +212 -0
  88. data/node_modules/govuk-frontend/govuk/components/notification-banner/macro-options.json +68 -0
  89. data/node_modules/govuk-frontend/govuk/components/notification-banner/macro.njk +3 -0
  90. data/node_modules/govuk-frontend/govuk/components/notification-banner/notification-banner.js +61 -0
  91. data/node_modules/govuk-frontend/govuk/components/notification-banner/template.njk +47 -0
  92. data/node_modules/govuk-frontend/govuk/components/panel/fixtures.json +30 -13
  93. data/node_modules/govuk-frontend/govuk/components/phase-banner/fixtures.json +20 -9
  94. data/node_modules/govuk-frontend/govuk/components/radios/fixtures.json +167 -50
  95. data/node_modules/govuk-frontend/govuk/components/select/fixtures.json +97 -18
  96. data/node_modules/govuk-frontend/govuk/components/select/macro-options.json +1 -1
  97. data/node_modules/govuk-frontend/govuk/components/skip-link/fixtures.json +21 -9
  98. data/node_modules/govuk-frontend/govuk/components/summary-list/fixtures.json +118 -25
  99. data/node_modules/govuk-frontend/govuk/components/table/_index.scss +21 -0
  100. data/node_modules/govuk-frontend/govuk/components/table/fixtures.json +92 -22
  101. data/node_modules/govuk-frontend/govuk/components/table/macro-options.json +2 -2
  102. data/node_modules/govuk-frontend/govuk/components/tabs/fixtures.json +75 -18
  103. data/node_modules/govuk-frontend/govuk/components/tabs/macro-options.json +1 -1
  104. data/node_modules/govuk-frontend/govuk/components/tag/fixtures.json +28 -14
  105. data/node_modules/govuk-frontend/govuk/components/textarea/fixtures.json +68 -17
  106. data/node_modules/govuk-frontend/govuk/components/warning-text/fixtures.json +19 -14
  107. data/node_modules/govuk-frontend/govuk/helpers/_links.scss +94 -0
  108. data/node_modules/govuk-frontend/govuk/objects/_all.scss +1 -0
  109. data/node_modules/govuk-frontend/govuk/objects/_button-group.scss +94 -0
  110. data/node_modules/govuk-frontend/govuk/settings/_colours-applied.scss +9 -0
  111. data/node_modules/govuk-frontend/govuk/settings/_typography-font.scss +3 -0
  112. data/node_modules/govuk-frontend/package.json +1 -1
  113. metadata +21 -18
  114. data/app/assets/images/govuk_publishing_components/chevron-banner/chevron-banner-small-focus.svg +0 -4
  115. data/app/assets/images/govuk_publishing_components/chevron-banner/chevron-banner-small.svg +0 -4
  116. data/app/assets/javascripts/govuk_publishing_components/components/header.js +0 -8
  117. data/app/assets/javascripts/govuk_publishing_components/lib/auto-track-event.js +0 -31
  118. data/app/assets/stylesheets/govuk_publishing_components/components/_chevron-banner.scss +0 -138
  119. data/app/assets/stylesheets/govuk_publishing_components/components/_list.scss +0 -1
  120. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_variables.scss +0 -27
  121. data/app/assets/stylesheets/govuk_publishing_components/components/mixins/_back-arrow.scss +0 -13
  122. data/app/assets/stylesheets/govuk_publishing_components/components/mixins/_clearfix.scss +0 -8
  123. data/app/views/govuk_publishing_components/components/_chevron_banner.html.erb +0 -19
  124. data/app/views/govuk_publishing_components/components/_subscription-links.html.erb +0 -85
  125. data/app/views/govuk_publishing_components/components/_translation-nav.html.erb +0 -33
  126. data/app/views/govuk_publishing_components/components/contextual_sidebar/_brexit_related_links.html.erb +0 -6
  127. data/app/views/govuk_publishing_components/components/docs/chevron_banner.yml +0 -33
  128. data/app/views/govuk_publishing_components/components/docs/subscription-links.yml +0 -103
  129. data/app/views/govuk_publishing_components/components/docs/translation-nav.yml +0 -139
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d8c74adc692bb0b7466ea5eba32bd121b8bf4470b7cb78c71732f5de5143e35
4
- data.tar.gz: c2ac6affcff44c35c9c47652945181cc59906db32e575ca25b937a120af59d0c
3
+ metadata.gz: 93a8bde02a39806e02cc9007a6b503aa3e65af3f1e7768b29f1d82c2c0ae66c4
4
+ data.tar.gz: b1e3bf6f8b98f5a4dcf2847fdca19aeed81b140491d43c230a5ea7074961d91b
5
5
  SHA512:
6
- metadata.gz: d615bae60cc517e98114ebf4185fc9686d45b0860e3bf38988827a77e1338b84c2e3e13cc1b04a1841c99157d5bba8f4f751ab6046c6ff4eee7d87b9640952bf
7
- data.tar.gz: 1ab8e32b4933e8de6642a5e30d48071d5590bfff81d72c6068d3b7093bf905b3025a6762f2c664171fc6e6b0e547ce1e10cf7e5fd439571e832080cd2f5eacd0
6
+ metadata.gz: 64cffb98c5dc002910a32ee736f21500ca921d5c3e5d165f66f87688d4e2a589da8e4aa69deba06b953924cf152aaac39e2f19752e80f7d7184285c9ce43bf8e
7
+ data.tar.gz: d1defc316e8d5e7171d903fa874ef1d8c93d416f1ce28e4c860aaed644b088e9621e24b2fb5a955768234a0d8d642193283509819348693b39c121e584aeeb5f
@@ -0,0 +1,4 @@
1
+ <svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <circle cx="17.5" cy="17.5" r="17.5" fill="#FF5800"/>
3
+ <path d="M28.5 10L13.6739 24L6.5 17.2258" stroke="white" stroke-width="3"/>
4
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <circle cx="17.5" cy="17.5" r="17.5" fill="#0EBA72"/>
3
+ <path d="M28.5 10L13.6739 24L6.5 17.2258" stroke="white" stroke-width="3"/>
4
+ </svg>
@@ -0,0 +1,4 @@
1
+ <svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <circle cx="17.5" cy="17.5" r="17.5" fill="#FF003B"/>
3
+ <path d="M28.5 10.5L13.6739 24.5L6.5 17.7258" stroke="white" stroke-width="3"/>
4
+ </svg>
@@ -1,5 +1,287 @@
1
- // This component relies on JavaScript from GOV.UK Frontend
2
- // = require govuk/components/accordion/accordion.js
1
+ /* global nodeListForEach */
2
+ // = require ../vendor/polyfills/closest.js
3
+ // = require ../vendor/polyfills/indexOf.js
4
+ // = require ../vendor/polyfills/common.js
5
+
3
6
  window.GOVUK = window.GOVUK || {}
4
- window.GOVUK.Modules = window.GOVUK.Modules || {}
5
- window.GOVUK.Modules.Accordion = window.GOVUKFrontend
7
+ window.GOVUK.Modules = window.GOVUK.Modules || {};
8
+
9
+ (function (Modules) {
10
+ function GemAccordion () { }
11
+
12
+ GemAccordion.prototype.start = function ($module) {
13
+ this.$module = $module[0]
14
+ this.moduleId = this.$module.getAttribute('id')
15
+ this.sections = this.$module.querySelectorAll('.gem-c-accordion__section')
16
+ this.openAllButton = ''
17
+ this.browserSupportsSessionStorage = helper.checkForSessionStorage()
18
+ this.controlsClass = 'gem-c-accordion__controls'
19
+ this.openAllClass = 'gem-c-accordion__open-all'
20
+ this.openAllTextClass = 'gem-c-accordion__open-all-text'
21
+ this.sectionHeaderClass = 'gem-c-accordion__section-header'
22
+ this.sectionHeadingClass = 'gem-c-accordion__section-heading'
23
+ this.sectionSummaryClass = 'gem-c-accordion__section-summary'
24
+ this.sectionButtonClass = 'gem-c-accordion__section-button'
25
+ this.sectionExpandedClass = 'gem-c-accordion__section--expanded'
26
+ this.sectionInnerContent = 'gem-c-accordion__section-content'
27
+ this.toggleLinkClass = 'js-toggle-link'
28
+ this.sectionShowHideIconClass = 'gem-c-accordion__toggle-link'
29
+ this.sectionShowHideTextClass = 'gem-c-accordion__toggle-text'
30
+ this.upChevonIconClass = 'gem-c-accordion-nav__chevron'
31
+ this.downChevonIconClass = 'gem-c-accordion-nav__chevron--down'
32
+
33
+ // Indicate that js has worked
34
+ this.$module.classList.add('gem-c-accordion--active')
35
+
36
+ this.initControls()
37
+ this.initSectionHeaders()
38
+
39
+ // See if "Show all sections" button text should be updated
40
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen()
41
+ this.updateOpenAllButton(areAllSectionsOpen)
42
+ }
43
+
44
+ // Initialise controls and set attributes
45
+ GemAccordion.prototype.initControls = function () {
46
+ // Create "Show all" button and set attributes
47
+ this.openAllButton = document.createElement('button')
48
+ this.openAllButton.setAttribute('class', this.openAllClass)
49
+ this.openAllButton.setAttribute('aria-expanded', 'false')
50
+
51
+ // Create icon, add to element
52
+ var icon = document.createElement('span')
53
+ icon.classList.add(this.upChevonIconClass)
54
+ this.openAllButton.appendChild(icon)
55
+
56
+ // Create control wrapper and add controls to it
57
+ var accordionControls = document.createElement('div')
58
+ accordionControls.setAttribute('class', this.controlsClass)
59
+ accordionControls.appendChild(this.openAllButton)
60
+ this.$module.insertBefore(accordionControls, this.$module.firstChild)
61
+
62
+ // Build addtional wrapper for open all toggle text, place icon after wrapped text.
63
+ var wrapperOpenAllText = document.createElement('span')
64
+ wrapperOpenAllText.classList.add(this.openAllTextClass)
65
+ this.openAllButton.insertBefore(wrapperOpenAllText, this.openAllButton.childNodes[0] || null)
66
+
67
+ // Handle events for the controls
68
+ this.openAllButton.addEventListener('click', this.onOpenOrCloseAllToggle.bind(this))
69
+ }
70
+
71
+ // Initialise section headers
72
+ GemAccordion.prototype.initSectionHeaders = function () {
73
+ // Loop through section headers
74
+ nodeListForEach(this.sections, function (section, i) {
75
+ // Set header attributes
76
+ var header = section.querySelector('.' + this.sectionHeaderClass)
77
+ this.initHeaderAttributes(header, i)
78
+ this.setExpanded(this.isExpanded(section), section)
79
+
80
+ // Handle events
81
+ header.addEventListener('click', this.onSectionToggle.bind(this, section))
82
+
83
+ // See if there is any state stored in sessionStorage and set the sections to
84
+ // open or closed.
85
+ this.setInitialState(section)
86
+ }.bind(this))
87
+ }
88
+
89
+ // Set individual header attributes
90
+ GemAccordion.prototype.initHeaderAttributes = function (headerWrapper, index) {
91
+ var span = headerWrapper.querySelector('.' + this.sectionButtonClass)
92
+ var heading = headerWrapper.querySelector('.' + this.sectionHeadingClass)
93
+ var summary = headerWrapper.querySelector('.' + this.sectionSummaryClass)
94
+
95
+ // Copy existing span element to an actual button element, for improved accessibility.
96
+ var button = document.createElement('button')
97
+ button.setAttribute('id', this.moduleId + '-heading-' + (index + 1))
98
+ button.setAttribute('aria-controls', this.moduleId + '-content-' + (index + 1))
99
+
100
+ // Create show / hide arrow icons with text.
101
+ var showIcons = document.createElement('span')
102
+ showIcons.classList.add(this.sectionShowHideIconClass, this.toggleLinkClass)
103
+
104
+ // Add pause after heading for assistive technology.
105
+ var srPause = document.createElement('span')
106
+ srPause.classList.add('govuk-visually-hidden')
107
+ srPause.innerHTML = ', '
108
+
109
+ // Build addtional copy for assistive technology
110
+ var srAddtionalCopy = document.createElement('span')
111
+ srAddtionalCopy.classList.add('govuk-visually-hidden')
112
+ srAddtionalCopy.innerHTML = ' this section'
113
+
114
+ // Build addtional wrapper for toggle text, place icon after wrapped text.
115
+ var wrapperShowHideIcon = document.createElement('span')
116
+ var icon = document.createElement('span')
117
+ icon.classList.add(this.upChevonIconClass)
118
+ showIcons.appendChild(icon)
119
+ wrapperShowHideIcon.classList.add(this.sectionShowHideTextClass)
120
+ showIcons.insertBefore(wrapperShowHideIcon, showIcons.childNodes[0] || null)
121
+
122
+ // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from span to button
123
+ for (var i = 0; i < span.attributes.length; i++) {
124
+ var attr = span.attributes.item(i)
125
+ button.setAttribute(attr.nodeName, attr.nodeValue)
126
+ }
127
+
128
+ // span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
129
+ button.innerHTML = span.innerHTML
130
+ heading.removeChild(span)
131
+ heading.appendChild(button)
132
+ button.appendChild(srPause)
133
+
134
+ // If summary content exists add to DOM in correct order
135
+ if (typeof (summary) !== 'undefined' && summary !== null) {
136
+ button.setAttribute('aria-describedby', this.moduleId + '-summary-' + (index + 1))
137
+ button.appendChild(summary)
138
+ }
139
+
140
+ button.appendChild(showIcons)
141
+ button.appendChild(srAddtionalCopy)
142
+ }
143
+
144
+ // When section toggled, set and store state
145
+ GemAccordion.prototype.onSectionToggle = function (section) {
146
+ var expanded = this.isExpanded(section)
147
+ this.setExpanded(!expanded, section)
148
+
149
+ // Store the state in sessionStorage when a change is triggered
150
+ this.storeState(section)
151
+ }
152
+
153
+ // When Open/Close All toggled, set and store state
154
+ GemAccordion.prototype.onOpenOrCloseAllToggle = function () {
155
+ var module = this
156
+ var sections = this.sections
157
+ var nowExpanded = !this.checkIfAllSectionsOpen()
158
+
159
+ nodeListForEach(sections, function (section) {
160
+ module.setExpanded(nowExpanded, section)
161
+ // Store the state in sessionStorage when a change is triggered
162
+ module.storeState(section)
163
+ })
164
+
165
+ module.updateOpenAllButton(nowExpanded)
166
+ }
167
+
168
+ // Set section attributes when opened/closed
169
+ GemAccordion.prototype.setExpanded = function (expanded, section) {
170
+ var icon = section.querySelector('.' + this.upChevonIconClass)
171
+ var showHideText = section.querySelector('.' + this.sectionShowHideTextClass)
172
+ var button = section.querySelector('.' + this.sectionButtonClass)
173
+ var newButtonText = expanded ? 'Hide' : 'Show'
174
+
175
+ showHideText.innerHTML = newButtonText
176
+ button.setAttribute('aria-expanded', expanded)
177
+ button.classList.add(this.toggleLinkClass)
178
+
179
+ // Swap icon, change class
180
+ if (expanded) {
181
+ section.classList.add(this.sectionExpandedClass)
182
+ icon.classList.remove(this.downChevonIconClass)
183
+ } else {
184
+ section.classList.remove(this.sectionExpandedClass)
185
+ icon.classList.add(this.downChevonIconClass)
186
+ }
187
+
188
+ // See if "Show all sections" button text should be updated
189
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen()
190
+ this.updateOpenAllButton(areAllSectionsOpen)
191
+ }
192
+
193
+ // Get state of section
194
+ GemAccordion.prototype.isExpanded = function (section) {
195
+ return section.classList.contains(this.sectionExpandedClass)
196
+ }
197
+
198
+ // Check if all sections are open
199
+ GemAccordion.prototype.checkIfAllSectionsOpen = function () {
200
+ // Get a count of all the Accordion sections
201
+ var sectionsCount = this.sections.length
202
+ // Get a count of all Accordion sections that are expanded
203
+ var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length
204
+ var areAllSectionsOpen = sectionsCount === expandedSectionCount
205
+
206
+ return areAllSectionsOpen
207
+ }
208
+
209
+ // Update "Show all sections" button
210
+ GemAccordion.prototype.updateOpenAllButton = function (expanded) {
211
+ var icon = this.openAllButton.querySelector('.' + this.upChevonIconClass)
212
+ var openAllCopy = this.openAllButton.querySelector('.' + this.openAllTextClass)
213
+ var newButtonText = expanded ? 'Hide all sections' : 'Show all sections'
214
+ this.openAllButton.setAttribute('aria-expanded', expanded)
215
+ openAllCopy.innerHTML = newButtonText
216
+
217
+ // Swap icon, toggle class
218
+ if (expanded) {
219
+ icon.classList.remove(this.downChevonIconClass)
220
+ } else {
221
+ icon.classList.add(this.downChevonIconClass)
222
+ }
223
+ }
224
+
225
+ var helper = {
226
+ checkForSessionStorage: function () {
227
+ var testString = 'this is the test string'
228
+ var result
229
+ try {
230
+ window.sessionStorage.setItem(testString, testString)
231
+ result = window.sessionStorage.getItem(testString) === testString.toString()
232
+ window.sessionStorage.removeItem(testString)
233
+ return result
234
+ } catch (exception) {
235
+ if ((typeof console === 'undefined' || typeof console.log === 'undefined')) {
236
+ console.log('Notice: sessionStorage not available.')
237
+ }
238
+ }
239
+ }
240
+ }
241
+
242
+ // Set the state of the accordions in sessionStorage
243
+ GemAccordion.prototype.storeState = function (section) {
244
+ if (this.browserSupportsSessionStorage) {
245
+ // We need a unique way of identifying each content in the GemAccordion. Since
246
+ // an `#id` should be unique and an `id` is required for `aria-` attributes
247
+ // `id` can be safely used.
248
+ var button = section.querySelector('.' + this.sectionButtonClass)
249
+
250
+ if (button) {
251
+ var contentId = button.getAttribute('aria-controls')
252
+ var contentState = button.getAttribute('aria-expanded')
253
+
254
+ if (typeof contentId === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
255
+ console.error(new Error('No aria controls present in accordion section heading.'))
256
+ }
257
+
258
+ if (typeof contentState === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
259
+ console.error(new Error('No aria expanded present in accordion section heading.'))
260
+ }
261
+
262
+ // Only set the state when both `contentId` and `contentState` are taken from the DOM.
263
+ if (contentId && contentState) {
264
+ window.sessionStorage.setItem(contentId, contentState)
265
+ }
266
+ }
267
+ }
268
+ }
269
+
270
+ // Read the state of the accordions from sessionStorage
271
+ GemAccordion.prototype.setInitialState = function (section) {
272
+ if (this.browserSupportsSessionStorage) {
273
+ var button = section.querySelector('.' + this.sectionButtonClass)
274
+
275
+ if (button) {
276
+ var contentId = button.getAttribute('aria-controls')
277
+ var contentState = contentId ? window.sessionStorage.getItem(contentId) : null
278
+
279
+ if (contentState !== null) {
280
+ this.setExpanded(contentState === 'true', section)
281
+ }
282
+ }
283
+ }
284
+ }
285
+
286
+ Modules.GemAccordion = GemAccordion
287
+ })(window.GOVUK.Modules)
@@ -85,10 +85,6 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
85
85
  this.$module.cookieBannerConfirmationMessage.style.display = 'block'
86
86
  }
87
87
 
88
- CookieBanner.prototype.listenForCrossOriginMessages = function () {
89
- window.addEventListener('message', this.receiveMessage.bind(this), false)
90
- }
91
-
92
88
  CookieBanner.prototype.isInCookiesPage = function () {
93
89
  return window.location.pathname === '/help/cookies'
94
90
  }
@@ -40,6 +40,15 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
40
40
  this.$module.sessionStoreLink = this.$module.sessionStoreLink + '_' + this.$module.uniqueId
41
41
  }
42
42
 
43
+ this.$module.upChevronSvg = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">' +
44
+ '<path class="gem-c-step-nav__chevron-stroke" d="M19.5 10C19.5 15.2467 15.2467 19.5 10 19.5C4.75329 19.5 0.499997 15.2467 0.499998 10C0.499999 4.7533 4.7533 0.500001 10 0.500002C15.2467 0.500003 19.5 4.7533 19.5 10Z" stroke="#1D70B8"/>' +
45
+ '<path class="gem-c-step-nav__chevron-stroke" d="M6.32617 12.3262L10 8.65234L13.6738 12.3262" stroke="#1D70B8" stroke-width="2"/>' +
46
+ '</svg>'
47
+ this.$module.downChevronSvg = '<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">' +
48
+ '<path class="gem-c-step-nav__chevron-stroke" d="M0.499997 10C0.499998 4.75329 4.75329 0.499999 10 0.499999C15.2467 0.5 19.5 4.75329 19.5 10C19.5 15.2467 15.2467 19.5 10 19.5C4.75329 19.5 0.499997 15.2467 0.499997 10Z" stroke="#1D70B8"/>' +
49
+ '<path class="gem-c-step-nav__chevron-stroke" d="M13.6738 8.67383L10 12.3477L6.32617 8.67383" stroke="#1D70B8" stroke-width="2"/>' +
50
+ '</svg>'
51
+
43
52
  var stepNavTracker = new this.StepNavTracker(this.$module.uniqueId, this.$module.totalSteps, this.$module.totalLinks)
44
53
 
45
54
  this.getTextForInsertedElements()
@@ -66,7 +75,10 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
66
75
  Gemstepnav.prototype.addShowHideAllButton = function () {
67
76
  var showall = document.createElement('div')
68
77
  showall.className = 'gem-c-step-nav__controls'
69
- showall.innerHTML = '<button aria-expanded="false" class="gem-c-step-nav__button gem-c-step-nav__button--controls js-step-controls-button">' + this.$module.actions.showAllText + '</button>'
78
+ showall.innerHTML = '<button aria-expanded="false" class="gem-c-step-nav__button gem-c-step-nav__button--controls js-step-controls-button">' +
79
+ '<span class="gem-c-step-nav__button-text gem-c-step-nav__button-text--all js-step-controls-button-text">' + this.$module.actions.showAllText + '</span>' +
80
+ '<span class="gem-c-step-nav__chevron js-step-controls-button-icon">' + this.$module.downChevronSvg + '</span>' +
81
+ '</button>'
70
82
 
71
83
  var steps = this.$module.querySelectorAll('.gem-c-step-nav__steps')[0]
72
84
  this.$module.insertBefore(showall, steps)
@@ -81,13 +93,20 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
81
93
  if (!thisel.querySelectorAll('.js-toggle-link').length) {
82
94
  var span = document.createElement('span')
83
95
  var showHideSpan = document.createElement('span')
96
+ var showHideSpanText = document.createElement('span')
97
+ var showHideSpanIcon = document.createElement('span')
84
98
  var commaSpan = document.createElement('span')
85
99
  var thisSectionSpan = document.createElement('span')
86
100
 
87
101
  showHideSpan.className = 'gem-c-step-nav__toggle-link js-toggle-link'
102
+ showHideSpanText.className = 'gem-c-step-nav__button-text js-toggle-link-text'
103
+ showHideSpanIcon.className = 'gem-c-step-nav__chevron js-toggle-link-icon'
88
104
  commaSpan.className = 'govuk-visually-hidden'
89
105
  thisSectionSpan.className = 'govuk-visually-hidden'
90
106
 
107
+ showHideSpan.appendChild(showHideSpanText)
108
+ showHideSpan.appendChild(showHideSpanIcon)
109
+
91
110
  commaSpan.innerHTML = ', '
92
111
  thisSectionSpan.innerHTML = ' this section'
93
112
 
@@ -114,7 +133,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
114
133
  var data = []
115
134
 
116
135
  for (var i = 0; i < this.$module.steps.length; i++) {
117
- var stepView = new this.StepView(this.$module.steps[i], this.$module.actions.showText, this.$module.actions.hideText)
136
+ var stepView = new this.StepView(this.$module.steps[i], this.$module)
118
137
  stepView.setIsShown(isShown)
119
138
 
120
139
  if (isShown) {
@@ -136,7 +155,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
136
155
  for (var i = 0; i < this.$module.steps.length; i++) {
137
156
  var thisel = this.$module.steps[i]
138
157
  var id = thisel.getAttribute('id')
139
- var stepView = new this.StepView(thisel, this.$module.actions.showText, this.$module.actions.hideText)
158
+ var stepView = new this.StepView(thisel, this.$module)
140
159
  var shouldBeShown = thisel.hasAttribute('data-show')
141
160
 
142
161
  // show the step if it has been remembered or if it has the 'data-show' attribute
@@ -165,7 +184,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
165
184
  '<button ' +
166
185
  'class="gem-c-step-nav__button gem-c-step-nav__button--title js-step-title-button" ' +
167
186
  'aria-expanded="false" aria-controls="' + contentId + '">' +
168
- '<span class="js-step-title-text">' + titleText + '</span>' +
187
+ '<span class="gem-c-step-nav__title-text js-step-title-text">' + titleText + '</span>' +
169
188
  '</button>' +
170
189
  '</span>'
171
190
  }
@@ -177,7 +196,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
177
196
 
178
197
  for (var i = 0; i < togglePanels.length; i++) {
179
198
  togglePanels[i].addEventListener('click', function (event) {
180
- var stepView = new that.StepView(this.parentNode, that.$module.actions.showText, that.$module.actions.hideText)
199
+ var stepView = new that.StepView(this.parentNode, that.$module)
181
200
  stepView.toggle()
182
201
 
183
202
  var stepIsOptional = this.parentNode.hasAttribute('data-optional')
@@ -321,34 +340,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
321
340
  var that = this
322
341
 
323
342
  this.$module.showOrHideAllButton.addEventListener('click', function (event) {
324
- var shouldshowAll
325
- var showHideTexts = that.$module.querySelectorAll('.js-toggle-link')
326
343
  var textContent = this.textContent || this.innerText
344
+ var shouldShowAll = textContent === that.$module.actions.showAllText
327
345
 
328
- if (textContent === that.$module.actions.showAllText) {
329
- that.$module.showOrHideAllButton.textContent = that.$module.actions.hideAllText
330
- for (var i = 0; i < showHideTexts.length; i++) {
331
- showHideTexts[i].innerHTML = that.$module.actions.hideText
332
- }
333
- shouldshowAll = true
334
-
335
- stepNavTracker.trackClick('pageElementInteraction', 'stepNavAllShown', {
336
- label: that.$module.actions.showAllText + ': ' + that.$module.stepNavSize
337
- })
338
- } else {
339
- that.$module.showOrHideAllButton.textContent = that.$module.actions.showAllText
340
- for (var j = 0; j < showHideTexts.length; j++) {
341
- showHideTexts[j].innerHTML = that.$module.actions.showText
342
- }
343
- shouldshowAll = false
344
-
345
- stepNavTracker.trackClick('pageElementInteraction', 'stepNavAllHidden', {
346
- label: that.$module.actions.hideAllText + ': ' + that.$module.stepNavSize
347
- })
348
- }
346
+ // Fire GA click tracking
347
+ stepNavTracker.trackClick('pageElementInteraction', (shouldShowAll ? 'stepNavAllShown' : 'stepNavAllHidden'), {
348
+ label: (shouldShowAll ? that.$module.actions.showAllText : that.$module.actions.hideAllText) + ': ' + that.$module.stepNavSize
349
+ })
349
350
 
350
- that.setAllStepsShownState(shouldshowAll)
351
- that.$module.showOrHideAllButton.setAttribute('aria-expanded', shouldshowAll)
351
+ that.setAllStepsShownState(shouldShowAll)
352
+ that.$module.showOrHideAllButton.setAttribute('aria-expanded', shouldShowAll)
352
353
  that.setShowHideAllText()
353
354
 
354
355
  return false
@@ -357,23 +358,25 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
357
358
 
358
359
  Gemstepnav.prototype.setShowHideAllText = function () {
359
360
  var shownSteps = this.$module.querySelectorAll('.step-is-shown').length
361
+
360
362
  // Find out if the number of is-opens == total number of steps
361
- if (shownSteps === this.$module.totalSteps) {
362
- this.$module.showOrHideAllButton.textContent = this.$module.actions.hideAllText
363
- } else {
364
- this.$module.showOrHideAllButton.textContent = this.$module.actions.showAllText
365
- }
363
+ var shownStepsIsTotalSteps = shownSteps === this.$module.totalSteps
364
+
365
+ this.$module.showOrHideAllButton.querySelector('.js-step-controls-button-text').innerHTML = shownStepsIsTotalSteps ? this.$module.actions.hideAllText : this.$module.actions.showAllText
366
+ this.$module.showOrHideAllButton.querySelector('.js-step-controls-button-icon').innerHTML = shownStepsIsTotalSteps ? this.$module.upChevronSvg : this.$module.downChevronSvg
366
367
  }
367
368
 
368
- Gemstepnav.prototype.StepView = function (stepElement, showText, hideText) {
369
+ Gemstepnav.prototype.StepView = function (stepElement, $module) {
369
370
  this.stepElement = stepElement
370
371
  this.stepContent = this.stepElement.querySelectorAll('.js-panel')[0]
371
372
  this.titleButton = this.stepElement.querySelectorAll('.js-step-title-button')[0]
372
373
  var textElement = this.stepElement.querySelectorAll('.js-step-title-text')[0]
373
374
  this.title = textElement.textContent || textElement.innerText
374
375
  this.title = this.title.replace(/^\s+|\s+$/g, '') // this is 'trim' but supporting IE8
375
- this.showText = showText
376
- this.hideText = hideText
376
+ this.showText = $module.actions.showText
377
+ this.hideText = $module.actions.hideText
378
+ this.upChevronSvg = $module.upChevronSvg
379
+ this.downChevronSvg = $module.downChevronSvg
377
380
 
378
381
  this.show = function () {
379
382
  this.setIsShown(true)
@@ -398,7 +401,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
398
401
 
399
402
  this.titleButton.setAttribute('aria-expanded', isShown)
400
403
  var showHideText = this.stepElement.querySelectorAll('.js-toggle-link')[0]
401
- showHideText.innerHTML = isShown ? this.hideText : this.showText
404
+
405
+ showHideText.querySelector('.js-toggle-link-text').innerHTML = isShown ? this.hideText : this.showText
406
+ showHideText.querySelector('.js-toggle-link-icon').innerHTML = isShown ? this.upChevronSvg : this.downChevronSvg
402
407
  }
403
408
 
404
409
  this.isShown = function () {