govuk_publishing_components 23.15.0 → 24.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics/scroll-tracker.js +28 -0
  3. data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +330 -4
  4. data/app/assets/javascripts/govuk_publishing_components/components/cookie-banner.js +26 -10
  5. data/app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js +23 -14
  6. data/app/assets/javascripts/govuk_publishing_components/vendor/polyfills/common.js +8 -0
  7. data/app/assets/stylesheets/component_guide/application.scss +0 -8
  8. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +0 -1
  9. data/app/assets/stylesheets/govuk_publishing_components/component_support.scss +0 -2
  10. data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +298 -14
  11. data/app/assets/stylesheets/govuk_publishing_components/components/_cookie-banner.scss +7 -87
  12. data/app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss +4 -4
  13. data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +21 -5
  14. data/app/assets/stylesheets/govuk_publishing_components/components/_step-by-step-nav.scss +105 -48
  15. data/app/assets/stylesheets/govuk_publishing_components/components/_success-alert.scss +8 -8
  16. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_contact.scss +0 -5
  17. data/app/assets/stylesheets/govuk_publishing_components/components/print/_accordion.scss +17 -9
  18. data/app/assets/stylesheets/govuk_publishing_components/components/print/_step-by-step-nav.scss +2 -2
  19. data/app/assets/stylesheets/govuk_publishing_components/govuk_frontend_support.scss +1 -11
  20. data/app/models/govuk_publishing_components/audit_applications.rb +1 -1
  21. data/app/views/govuk_publishing_components/audit/show.html.erb +211 -199
  22. data/app/views/govuk_publishing_components/components/_accordion.html.erb +15 -22
  23. data/app/views/govuk_publishing_components/components/_attachment.html.erb +3 -3
  24. data/app/views/govuk_publishing_components/components/_cookie_banner.html.erb +47 -36
  25. data/app/views/govuk_publishing_components/components/_document_list.html.erb +10 -1
  26. data/app/views/govuk_publishing_components/components/_layout_footer.html.erb +1 -1
  27. data/app/views/govuk_publishing_components/components/attachment/{_thumbnail_document.svg → _thumbnail_document.html.erb} +0 -0
  28. data/app/views/govuk_publishing_components/components/attachment/{_thumbnail_generic.svg → _thumbnail_generic.html.erb} +0 -0
  29. data/app/views/govuk_publishing_components/components/attachment/{_thumbnail_spreadsheet.svg → _thumbnail_spreadsheet.html.erb} +0 -0
  30. data/app/views/govuk_publishing_components/components/docs/accordion.yml +37 -3
  31. data/app/views/govuk_publishing_components/components/docs/contextual_sidebar.yml +5 -0
  32. data/app/views/govuk_publishing_components/components/docs/cookie_banner.yml +9 -0
  33. data/app/views/govuk_publishing_components/components/docs/document_list.yml +18 -0
  34. data/app/views/govuk_publishing_components/components/docs/govspeak.yml +3 -3
  35. data/app/views/govuk_publishing_components/components/layout_header/_header_logo.html.erb +1 -1
  36. data/config/initializers/assets.rb +0 -1
  37. data/lib/govuk_publishing_components/presenters/contextual_navigation.rb +61 -2
  38. data/lib/govuk_publishing_components/version.rb +1 -1
  39. data/node_modules/govuk-frontend/govuk/all.js +1 -1
  40. data/node_modules/govuk-frontend/govuk/components/_all.scss +1 -0
  41. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/fixtures.json +10 -10
  42. data/node_modules/govuk-frontend/govuk/components/breadcrumbs/template.njk +2 -2
  43. data/node_modules/govuk-frontend/govuk/components/button/_index.scss +2 -0
  44. data/node_modules/govuk-frontend/govuk/components/character-count/_index.scss +1 -0
  45. data/node_modules/govuk-frontend/govuk/components/character-count/character-count.js +1 -1
  46. data/node_modules/govuk-frontend/govuk/components/character-count/fixtures.json +13 -0
  47. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_cookie-banner.scss +2 -0
  48. data/node_modules/govuk-frontend/govuk/components/cookie-banner/_index.scss +51 -0
  49. data/node_modules/govuk-frontend/govuk/components/cookie-banner/fixtures.json +425 -0
  50. data/node_modules/govuk-frontend/govuk/components/cookie-banner/macro-options.json +132 -0
  51. data/node_modules/govuk-frontend/govuk/components/cookie-banner/macro.njk +3 -0
  52. data/node_modules/govuk-frontend/govuk/components/cookie-banner/template.njk +63 -0
  53. data/node_modules/govuk-frontend/govuk/components/details/fixtures.json +2 -2
  54. data/node_modules/govuk-frontend/govuk/components/header/fixtures.json +18 -18
  55. data/node_modules/govuk-frontend/govuk/components/header/template.njk +4 -4
  56. data/node_modules/govuk-frontend/govuk/components/table/_index.scss +21 -0
  57. data/node_modules/govuk-frontend/govuk/components/table/macro-options.json +2 -2
  58. data/node_modules/govuk-frontend/govuk/objects/_all.scss +1 -0
  59. data/node_modules/govuk-frontend/govuk/objects/_button-group.scss +94 -0
  60. data/node_modules/govuk-frontend/package.json +1 -1
  61. metadata +13 -20
  62. data/app/assets/images/govuk_publishing_components/chevron-banner/chevron-banner-small-focus.svg +0 -4
  63. data/app/assets/images/govuk_publishing_components/chevron-banner/chevron-banner-small.svg +0 -4
  64. data/app/assets/javascripts/govuk_publishing_components/components/header.js +0 -8
  65. data/app/assets/javascripts/govuk_publishing_components/lib/auto-track-event.js +0 -31
  66. data/app/assets/stylesheets/govuk_publishing_components/components/_chevron-banner.scss +0 -138
  67. data/app/assets/stylesheets/govuk_publishing_components/components/_list.scss +0 -1
  68. data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_variables.scss +0 -27
  69. data/app/assets/stylesheets/govuk_publishing_components/components/mixins/_back-arrow.scss +0 -13
  70. data/app/assets/stylesheets/govuk_publishing_components/components/mixins/_clearfix.scss +0 -8
  71. data/app/views/govuk_publishing_components/components/_chevron_banner.html.erb +0 -19
  72. data/app/views/govuk_publishing_components/components/_subscription-links.html.erb +0 -85
  73. data/app/views/govuk_publishing_components/components/_translation-nav.html.erb +0 -33
  74. data/app/views/govuk_publishing_components/components/docs/chevron_banner.yml +0 -33
  75. data/app/views/govuk_publishing_components/components/docs/subscription-links.yml +0 -103
  76. 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: dcb27613b799a95856f3a2125b6e5a95a0a6ef79dbb0b51b3c96abbcafbcc8ae
4
- data.tar.gz: ce5e6a4c647af7b0260ad3e3258d1edae02607a129d1de4153cb89b8fdc24eb2
3
+ metadata.gz: 27bbb3cbb2bca8d09be089a66cbbfa710fea05a35e275d9dbd92237b78206f49
4
+ data.tar.gz: 582f39e64a1af7c58a13c01adb9bb8a25e0c2042da02ce81688ce9ad2a74282f
5
5
  SHA512:
6
- metadata.gz: c581512609cf6841314030d6d2ad34a930208b84cd769561b80913579e788b6b964f2b1c4feec07087ee8f5075cbda98b31dda749fc21606315ba34d0b46200d
7
- data.tar.gz: 5b11f1c74f5045f23afc9e393b77892eb2089953dfc402157cd39efbcf72b876b491a6897c51d08d54e3575f7651b7e4ef63dec194bf50975532b3c1868fc35c
6
+ metadata.gz: d357fa3acf40c80ff22f1f619f0f412904d60d3d8cbab2279e166a77a02a58be06a15801360e5d3748877ebd6353cebfc402914eba08931b28489256ee7b3048
7
+ data.tar.gz: 82c84f467d4903b1f916af25bc73fd151857db158b5fe84ae3f442d6a7ef5725ca97db85a558132f0ef968f4ef80e67145f94a5c96b2d8e9887f6c3982e35db4
@@ -405,6 +405,34 @@
405
405
  ],
406
406
  '/eubusiness': [
407
407
  ['Heading', 'Additional help and support']
408
+ ],
409
+ '/coronavirus': [
410
+ ['Percent', 20],
411
+ ['Percent', 40],
412
+ ['Percent', 60],
413
+ ['Percent', 80],
414
+ ['Percent', 100]
415
+ ],
416
+ '/coronavirus/education-and-childcare': [
417
+ ['Percent', 20],
418
+ ['Percent', 40],
419
+ ['Percent', 60],
420
+ ['Percent', 80],
421
+ ['Percent', 100]
422
+ ],
423
+ '/coronavirus/worker-support': [
424
+ ['Percent', 20],
425
+ ['Percent', 40],
426
+ ['Percent', 60],
427
+ ['Percent', 80],
428
+ ['Percent', 100]
429
+ ],
430
+ '/coronavirus/business-support': [
431
+ ['Percent', 20],
432
+ ['Percent', 40],
433
+ ['Percent', 60],
434
+ ['Percent', 80],
435
+ ['Percent', 100]
408
436
  ]
409
437
  }
410
438
 
@@ -1,5 +1,331 @@
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.sectionClass = 'gem-c-accordion__section'
15
+ this.moduleId = this.$module.getAttribute('id')
16
+ this.sections = this.$module.querySelectorAll('.' + this.sectionClass)
17
+ this.openAllButton = ''
18
+ this.browserSupportsSessionStorage = helper.checkForSessionStorage()
19
+ this.controlsClass = 'gem-c-accordion__controls'
20
+ this.openAllClass = 'gem-c-accordion__open-all'
21
+ this.openAllTextClass = 'gem-c-accordion__open-all-text'
22
+ this.sectionHeaderClass = 'gem-c-accordion__section-header'
23
+ this.sectionHeadingClass = 'gem-c-accordion__section-heading'
24
+ this.sectionSummaryClass = 'gem-c-accordion__section-summary'
25
+ this.sectionButtonClass = 'gem-c-accordion__section-button'
26
+ this.sectionExpandedClass = 'gem-c-accordion__section--expanded'
27
+ this.sectionInnerContent = 'gem-c-accordion__section-content'
28
+ this.toggleLinkClass = 'js-toggle-link'
29
+ this.sectionShowHideIconClass = 'gem-c-accordion__toggle-link'
30
+ this.sectionShowHideTextClass = 'gem-c-accordion__toggle-text'
31
+ this.upChevonIconClass = 'gem-c-accordion-nav__chevron'
32
+ this.downChevonIconClass = 'gem-c-accordion-nav__chevron--down'
33
+
34
+ // Indicate that js has worked
35
+ this.$module.classList.add('gem-c-accordion--active')
36
+
37
+ this.initControls()
38
+ this.initSectionHeaders()
39
+
40
+ // Feature flag for anchor tag navigation used on manuals
41
+ if (this.$module.getAttribute('data-anchor-navigation')) {
42
+ this.openByAnchorOnLoad()
43
+ this.addEventListenersForAnchors()
44
+ }
45
+
46
+ // See if "Show all sections" button text should be updated
47
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen()
48
+ this.updateOpenAllButton(areAllSectionsOpen)
49
+ }
50
+
51
+ // Initialise controls and set attributes
52
+ GemAccordion.prototype.initControls = function () {
53
+ // Create "Show all" button and set attributes
54
+ this.openAllButton = document.createElement('button')
55
+ this.openAllButton.setAttribute('class', this.openAllClass)
56
+ this.openAllButton.setAttribute('aria-expanded', 'false')
57
+
58
+ // Create icon, add to element
59
+ var icon = document.createElement('span')
60
+ icon.classList.add(this.upChevonIconClass)
61
+ this.openAllButton.appendChild(icon)
62
+
63
+ // Create control wrapper and add controls to it
64
+ var accordionControls = document.createElement('div')
65
+ accordionControls.setAttribute('class', this.controlsClass)
66
+ accordionControls.appendChild(this.openAllButton)
67
+ this.$module.insertBefore(accordionControls, this.$module.firstChild)
68
+
69
+ // Build additional wrapper for open all toggle text, place icon after wrapped text.
70
+ var wrapperOpenAllText = document.createElement('span')
71
+ wrapperOpenAllText.classList.add(this.openAllTextClass)
72
+ this.openAllButton.insertBefore(wrapperOpenAllText, this.openAllButton.childNodes[0] || null)
73
+
74
+ // Handle events for the controls
75
+ this.openAllButton.addEventListener('click', this.onOpenOrCloseAllToggle.bind(this))
76
+ }
77
+
78
+ // Initialise section headers
79
+ GemAccordion.prototype.initSectionHeaders = function () {
80
+ // Loop through section headers
81
+ nodeListForEach(this.sections, function (section, i) {
82
+ // Set header attributes
83
+ var header = section.querySelector('.' + this.sectionHeaderClass)
84
+
85
+ this.initHeaderAttributes(header, i)
86
+ this.setExpanded(this.isExpanded(section), section)
87
+
88
+ // Handle events
89
+ header.addEventListener('click', this.onSectionToggle.bind(this, section))
90
+
91
+ // See if there is any state stored in sessionStorage and set the sections to
92
+ // open or closed.
93
+ this.setInitialState(section)
94
+ }.bind(this))
95
+ }
96
+
97
+ // Set individual header attributes
98
+ GemAccordion.prototype.initHeaderAttributes = function (headerWrapper, index) {
99
+ var span = headerWrapper.querySelector('.' + this.sectionButtonClass)
100
+ var heading = headerWrapper.querySelector('.' + this.sectionHeadingClass)
101
+ var summary = headerWrapper.querySelector('.' + this.sectionSummaryClass)
102
+
103
+ // Copy existing span element to an actual button element, for improved accessibility.
104
+ var button = document.createElement('button')
105
+ button.setAttribute('id', this.moduleId + '-heading-' + (index + 1))
106
+ button.setAttribute('aria-controls', this.moduleId + '-content-' + (index + 1))
107
+
108
+ // Create show / hide arrow icons with text.
109
+ var showIcons = document.createElement('span')
110
+ showIcons.classList.add(this.sectionShowHideIconClass, this.toggleLinkClass)
111
+
112
+ // Add pause after heading for assistive technology.
113
+ var srPause = document.createElement('span')
114
+ srPause.classList.add('govuk-visually-hidden')
115
+ srPause.innerHTML = ', '
116
+
117
+ // Build additional copy for assistive technology
118
+ var srAdditionalCopy = document.createElement('span')
119
+ srAdditionalCopy.classList.add('govuk-visually-hidden')
120
+ srAdditionalCopy.innerHTML = ' this section'
121
+
122
+ // Build additional wrapper for toggle text, place icon after wrapped text.
123
+ var wrapperShowHideIcon = document.createElement('span')
124
+ var icon = document.createElement('span')
125
+ icon.classList.add(this.upChevonIconClass)
126
+ showIcons.appendChild(icon)
127
+ wrapperShowHideIcon.classList.add(this.sectionShowHideTextClass)
128
+ showIcons.insertBefore(wrapperShowHideIcon, showIcons.childNodes[0] || null)
129
+
130
+ // Copy all attributes (https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes) from span to button
131
+ for (var i = 0; i < span.attributes.length; i++) {
132
+ var attr = span.attributes.item(i)
133
+ button.setAttribute(attr.nodeName, attr.nodeValue)
134
+ }
135
+
136
+ // span could contain HTML elements (see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content)
137
+ button.innerHTML = span.innerHTML
138
+ heading.removeChild(span)
139
+ heading.appendChild(button)
140
+ button.appendChild(srPause)
141
+
142
+ // If summary content exists add to DOM in correct order
143
+ if (typeof (summary) !== 'undefined' && summary !== null) {
144
+ button.setAttribute('aria-describedby', this.moduleId + '-summary-' + (index + 1))
145
+ button.appendChild(summary)
146
+ }
147
+
148
+ button.appendChild(showIcons)
149
+ button.appendChild(srAdditionalCopy)
150
+ }
151
+
152
+ // When section toggled, set and store state
153
+ GemAccordion.prototype.onSectionToggle = function (section) {
154
+ var expanded = this.isExpanded(section)
155
+ this.setExpanded(!expanded, section)
156
+
157
+ // Store the state in sessionStorage when a change is triggered
158
+ this.storeState(section)
159
+ }
160
+
161
+ // When Open/Close All toggled, set and store state
162
+ GemAccordion.prototype.onOpenOrCloseAllToggle = function () {
163
+ var module = this
164
+ var sections = this.sections
165
+ var nowExpanded = !this.checkIfAllSectionsOpen()
166
+
167
+ nodeListForEach(sections, function (section) {
168
+ module.setExpanded(nowExpanded, section)
169
+ // Store the state in sessionStorage when a change is triggered
170
+ module.storeState(section)
171
+ })
172
+
173
+ module.updateOpenAllButton(nowExpanded)
174
+ }
175
+
176
+ // Set section attributes when opened/closed
177
+ GemAccordion.prototype.setExpanded = function (expanded, section) {
178
+ var icon = section.querySelector('.' + this.upChevonIconClass)
179
+ var showHideText = section.querySelector('.' + this.sectionShowHideTextClass)
180
+ var button = section.querySelector('.' + this.sectionButtonClass)
181
+ var newButtonText = expanded ? 'Hide' : 'Show'
182
+
183
+ showHideText.innerHTML = newButtonText
184
+ button.setAttribute('aria-expanded', expanded)
185
+ button.classList.add(this.toggleLinkClass)
186
+
187
+ // Swap icon, change class
188
+ if (expanded) {
189
+ section.classList.add(this.sectionExpandedClass)
190
+ icon.classList.remove(this.downChevonIconClass)
191
+ } else {
192
+ section.classList.remove(this.sectionExpandedClass)
193
+ icon.classList.add(this.downChevonIconClass)
194
+ }
195
+
196
+ // See if "Show all sections" button text should be updated
197
+ var areAllSectionsOpen = this.checkIfAllSectionsOpen()
198
+ this.updateOpenAllButton(areAllSectionsOpen)
199
+ }
200
+
201
+ // Get state of section
202
+ GemAccordion.prototype.isExpanded = function (section) {
203
+ return section.classList.contains(this.sectionExpandedClass)
204
+ }
205
+
206
+ // Check if all sections are open
207
+ GemAccordion.prototype.checkIfAllSectionsOpen = function () {
208
+ // Get a count of all the Accordion sections
209
+ var sectionsCount = this.sections.length
210
+ // Get a count of all Accordion sections that are expanded
211
+ var expandedSectionCount = this.$module.querySelectorAll('.' + this.sectionExpandedClass).length
212
+ var areAllSectionsOpen = sectionsCount === expandedSectionCount
213
+
214
+ return areAllSectionsOpen
215
+ }
216
+
217
+ // Update "Show all sections" button
218
+ GemAccordion.prototype.updateOpenAllButton = function (expanded) {
219
+ var icon = this.openAllButton.querySelector('.' + this.upChevonIconClass)
220
+ var openAllCopy = this.openAllButton.querySelector('.' + this.openAllTextClass)
221
+ var newButtonText = expanded ? 'Hide all sections' : 'Show all sections'
222
+ this.openAllButton.setAttribute('aria-expanded', expanded)
223
+ openAllCopy.innerHTML = newButtonText
224
+
225
+ // Swap icon, toggle class
226
+ if (expanded) {
227
+ icon.classList.remove(this.downChevonIconClass)
228
+ } else {
229
+ icon.classList.add(this.downChevonIconClass)
230
+ }
231
+ }
232
+
233
+ var helper = {
234
+ checkForSessionStorage: function () {
235
+ var testString = 'this is the test string'
236
+ var result
237
+ try {
238
+ window.sessionStorage.setItem(testString, testString)
239
+ result = window.sessionStorage.getItem(testString) === testString.toString()
240
+ window.sessionStorage.removeItem(testString)
241
+ return result
242
+ } catch (exception) {
243
+ if ((typeof console === 'undefined' || typeof console.log === 'undefined')) {
244
+ console.log('Notice: sessionStorage not available.')
245
+ }
246
+ }
247
+ }
248
+ }
249
+
250
+ // Set the state of the accordions in sessionStorage
251
+ GemAccordion.prototype.storeState = function (section) {
252
+ if (this.browserSupportsSessionStorage) {
253
+ // We need a unique way of identifying each content in the GemAccordion. Since
254
+ // an `#id` should be unique and an `id` is required for `aria-` attributes
255
+ // `id` can be safely used.
256
+ var button = section.querySelector('.' + this.sectionButtonClass)
257
+
258
+ if (button) {
259
+ var contentId = button.getAttribute('aria-controls')
260
+ var contentState = button.getAttribute('aria-expanded')
261
+
262
+ if (typeof contentId === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
263
+ console.error(new Error('No aria controls present in accordion section heading.'))
264
+ }
265
+
266
+ if (typeof contentState === 'undefined' && (typeof console === 'undefined' || typeof console.log === 'undefined')) {
267
+ console.error(new Error('No aria expanded present in accordion section heading.'))
268
+ }
269
+
270
+ // Only set the state when both `contentId` and `contentState` are taken from the DOM.
271
+ if (contentId && contentState) {
272
+ window.sessionStorage.setItem(contentId, contentState)
273
+ }
274
+ }
275
+ }
276
+ }
277
+
278
+ // Read the state of the accordions from sessionStorage
279
+ GemAccordion.prototype.setInitialState = function (section) {
280
+ if (this.browserSupportsSessionStorage) {
281
+ var button = section.querySelector('.' + this.sectionButtonClass)
282
+
283
+ if (button) {
284
+ var contentId = button.getAttribute('aria-controls')
285
+ var contentState = contentId ? window.sessionStorage.getItem(contentId) : null
286
+
287
+ if (contentState !== null) {
288
+ this.setExpanded(contentState === 'true', section)
289
+ }
290
+ }
291
+ }
292
+ }
293
+
294
+ // Navigate to and open accordions with anchored content on page load if a hash is present
295
+ GemAccordion.prototype.openByAnchorOnLoad = function () {
296
+ if (window.location.hash && this.$module.querySelector(window.location.hash)) {
297
+ this.openForAnchor(window.location.hash)
298
+ }
299
+ }
300
+
301
+ // Add event listeners for links to open accordion sections when navigated to using said anchor links on the page
302
+ // 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
303
+ GemAccordion.prototype.addEventListenersForAnchors = function () {
304
+ var links = this.$module.querySelectorAll('.' + this.sectionInnerContent + ' a[href*="#"]')
305
+
306
+ links.forEach(function (link) {
307
+ if (link.pathname === window.location.pathname) {
308
+ link.addEventListener('click', this.openForAnchor.bind(this, link.hash))
309
+ }
310
+ }.bind(this))
311
+ }
312
+
313
+ // Find the parent accordion section for the given id and open it
314
+ GemAccordion.prototype.openForAnchor = function (hash) {
315
+ var target = document.querySelector(hash)
316
+ var section = this.getContainingSection(target)
317
+
318
+ this.setExpanded(true, section)
319
+ }
320
+
321
+ // Loop through the given ids ancestors until the parent section class is found
322
+ GemAccordion.prototype.getContainingSection = function (target) {
323
+ while (!target.classList.contains(this.sectionClass)) {
324
+ target = target.parentElement
325
+ }
326
+
327
+ return target
328
+ }
329
+
330
+ Modules.GemAccordion = GemAccordion
331
+ })(window.GOVUK.Modules)
@@ -9,10 +9,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
9
9
  this.$module.hideCookieMessage = this.hideCookieMessage.bind(this)
10
10
  this.$module.showConfirmationMessage = this.showConfirmationMessage.bind(this)
11
11
  this.$module.setCookieConsent = this.setCookieConsent.bind(this)
12
+ this.$module.rejectCookieConsent = this.rejectCookieConsent.bind(this)
12
13
 
13
14
  this.$module.cookieBanner = document.querySelector('.gem-c-cookie-banner')
14
15
  this.$module.cookieBannerConfirmationMessage = this.$module.querySelector('.gem-c-cookie-banner__confirmation')
15
-
16
+ this.$module.cookieBannerConfirmationMessageText = this.$module.querySelector('.gem-c-cookie-banner__confirmation-message')
16
17
  this.setupCookieMessage()
17
18
  }
18
19
 
@@ -24,9 +25,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
24
25
  }
25
26
  }
26
27
 
27
- this.$acceptCookiesLink = this.$module.querySelector('button[data-accept-cookies]')
28
- if (this.$acceptCookiesLink) {
29
- this.$acceptCookiesLink.addEventListener('click', this.$module.setCookieConsent)
28
+ this.$acceptCookiesButton = this.$module.querySelector('button[data-accept-cookies]')
29
+ if (this.$acceptCookiesButton) {
30
+ this.$acceptCookiesButton.style.display = 'block'
31
+ this.$acceptCookiesButton.addEventListener('click', this.$module.setCookieConsent)
32
+ }
33
+
34
+ this.$rejectCookiesButton = this.$module.querySelector('button[data-reject-cookies]')
35
+ if (this.$rejectCookiesButton) {
36
+ this.$rejectCookiesButton.style.display = 'block'
37
+ this.$rejectCookiesButton.addEventListener('click', this.$module.rejectCookieConsent)
30
38
  }
31
39
 
32
40
  this.showCookieMessage()
@@ -56,6 +64,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
56
64
 
57
65
  CookieBanner.prototype.hideCookieMessage = function (event) {
58
66
  if (this.$module) {
67
+ this.$module.hidden = true
59
68
  this.$module.style.display = 'none'
60
69
  window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
61
70
  }
@@ -66,6 +75,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
66
75
  }
67
76
 
68
77
  CookieBanner.prototype.setCookieConsent = function () {
78
+ if (this.$acceptCookiesButton.getAttribute('data-cookie-types') === 'all') {
79
+ this.$module.cookieBannerConfirmationMessageText.insertAdjacentHTML('afterbegin', 'You have accepted additional cookies. ')
80
+ }
69
81
  window.GOVUK.approveAllCookieTypes()
70
82
  this.$module.showConfirmationMessage()
71
83
  this.$module.cookieBannerConfirmationMessage.focus()
@@ -78,15 +90,19 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
78
90
  }
79
91
  }
80
92
 
93
+ CookieBanner.prototype.rejectCookieConsent = function () {
94
+ this.$module.cookieBannerConfirmationMessageText.insertAdjacentHTML('afterbegin', 'You have rejected additional cookies. ')
95
+ this.$module.showConfirmationMessage()
96
+ this.$module.cookieBannerConfirmationMessage.focus()
97
+ window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
98
+ }
99
+
81
100
  CookieBanner.prototype.showConfirmationMessage = function () {
82
- this.$cookieBannerMainContent = document.querySelector('.gem-c-cookie-banner__wrapper')
101
+ this.$cookieBannerMainContent = document.querySelector('.js-banner-wrapper')
83
102
 
84
- this.$cookieBannerMainContent.style.display = 'none'
103
+ this.$cookieBannerMainContent.hidden = true
85
104
  this.$module.cookieBannerConfirmationMessage.style.display = 'block'
86
- }
87
-
88
- CookieBanner.prototype.listenForCrossOriginMessages = function () {
89
- window.addEventListener('message', this.receiveMessage.bind(this), false)
105
+ this.$module.cookieBannerConfirmationMessage.hidden = false
90
106
  }
91
107
 
92
108
  CookieBanner.prototype.isInCookiesPage = function () {