govuk_publishing_components 29.10.0 → 29.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c90f6280f1c3ce88606be0f030883575971e8fd8447cac1b353b2e1163221b63
4
- data.tar.gz: 79e9a7c4d8f262fd3dd65d504aabcbff63cf7228479a540f7fb187cf4383e8fa
3
+ metadata.gz: 4908ab95bb70e9f55096b46cae08b0ea6fff5f168da24aa427c810a39de96e4a
4
+ data.tar.gz: 99873d158278fbbf30eb341558a5424b9957054b0711486312bd4e18b9c45b35
5
5
  SHA512:
6
- metadata.gz: 036a6a9d2e713632f5f8ca68b997017cf728dbf7f0dfa46709762b185ee32d576526bcad7ebbb453a0a8feb9e809c95dd5e86bf20d91d35293b2009fd972f0b3
7
- data.tar.gz: 876823d94cae4f3fbbcc4a8e5c178a35e0d9c90b8ea5f0d29b8e9ec737097d9764608f3dbfea13f7d8ae8aa252c07f33fba46e53638cc249b1f20c86e0c99cc6
6
+ metadata.gz: 7c6a51b33e3f4fccb750bdc8ab05171bb7d3e877f5ee8e9f0a601be977baa390162cfbab07a94facf2905d7eadd5f504640e25e86260d5b756e82959a8532522
7
+ data.tar.gz: 5531061592b4e1db78a34d8ecf15f613f05140585df1d5edb76224e82b317a62be16fb7ae4345d75c075297f164b3eb1569c794a7337a09d7345fee4061e0daf
@@ -1,3 +1,4 @@
1
+ // = require govuk/vendor/polyfills/Element/prototype/closest.js
1
2
  window.GOVUK = window.GOVUK || {}
2
3
  window.GOVUK.Modules = window.GOVUK.Modules || {};
3
4
 
@@ -10,38 +11,47 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
10
11
  }
11
12
 
12
13
  GtmClickTracking.prototype.init = function () {
13
- var trackClicksOn = [this.module]
14
- if (!this.module.getAttribute(this.trackingTrigger)) {
15
- trackClicksOn = this.module.querySelectorAll('[' + this.trackingTrigger + ']')
16
- }
17
-
18
- for (var i = 0; i < trackClicksOn.length; i++) {
19
- trackClicksOn[i].addEventListener('click', this.trackClick.bind(this))
20
- }
14
+ this.module.addEventListener('click', this.trackClick.bind(this), true) // useCapture must be true
21
15
  }
22
16
 
23
17
  GtmClickTracking.prototype.trackClick = function (event) {
24
18
  if (window.dataLayer) {
25
- var target = event.currentTarget
26
- var data = {
27
- event: 'analytics',
28
- event_name: target.getAttribute('data-gtm-event-name'),
29
- // get entire URL apart from domain
30
- link_url: window.location.href.substring(window.location.origin.length),
31
- ui: JSON.parse(target.getAttribute('data-gtm-attributes'))
32
- }
33
- var ariaExpanded = this.checkExpandedState(target)
34
- if (ariaExpanded) {
35
- data.ui.state = ariaExpanded === 'false' ? 'opened' : 'closed'
19
+ var target = this.findTrackingAttributes(event.target)
20
+ if (target) {
21
+ var data = {
22
+ event: 'analytics',
23
+ event_name: target.getAttribute('data-gtm-event-name'),
24
+ // get entire URL apart from domain
25
+ link_url: window.location.href.substring(window.location.origin.length),
26
+ ui: JSON.parse(target.getAttribute('data-gtm-attributes')) || {}
27
+ }
28
+ var ariaExpanded = this.checkExpandedState(target)
29
+ if (ariaExpanded) {
30
+ data.ui.state = ariaExpanded === 'false' ? 'opened' : 'closed'
31
+ data.ui.text = data.ui.text || target.innerText
32
+ }
33
+ window.dataLayer.push(data)
36
34
  }
37
- window.dataLayer.push(data)
38
35
  }
39
36
  }
40
37
 
38
+ GtmClickTracking.prototype.findTrackingAttributes = function (clicked) {
39
+ if (clicked.hasAttribute('[' + this.trackingTrigger + ']')) {
40
+ return clicked
41
+ } else {
42
+ return clicked.closest('[' + this.trackingTrigger + ']')
43
+ }
44
+ }
45
+
46
+ // check either element is expandable or contains expandable element
41
47
  GtmClickTracking.prototype.checkExpandedState = function (clicked) {
42
- var expanded = clicked.querySelector('[aria-expanded]')
43
- if (expanded) {
44
- return expanded.getAttribute('aria-expanded')
48
+ var isExpandable = clicked.getAttribute('aria-expanded')
49
+ var containsExpandable = clicked.querySelector('[aria-expanded]')
50
+
51
+ if (isExpandable) {
52
+ return isExpandable
53
+ } else if (containsExpandable) {
54
+ return containsExpandable.getAttribute('aria-expanded')
45
55
  }
46
56
  }
47
57
 
@@ -45,6 +45,21 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
45
45
  if (this.$module.getAttribute('data-track-sections') === 'true') {
46
46
  this.addEventListenerSections()
47
47
  }
48
+
49
+ // look for data attributes to put onto the 'show/hide all' link
50
+ var showAllAttributes = this.$module.getAttribute('data-show-all-attributes')
51
+ if (showAllAttributes) {
52
+ try {
53
+ var showAll = this.$module.querySelector('.' + this.showAllControls)
54
+ var values = JSON.parse(showAllAttributes)
55
+ var keys = Object.keys(values)
56
+ for (var i = 0; i < keys.length; i++) {
57
+ showAll.setAttribute('data-' + keys[i], values[keys[i]])
58
+ }
59
+ } catch (e) {
60
+ console.error('Could not read accordion data attributes error: ' + e.message, window.location)
61
+ }
62
+ }
48
63
  }
49
64
 
50
65
  // Navigate to and open accordions with anchored content on page load if a hash is present
@@ -10,6 +10,7 @@
10
10
  @import "components/print/govspeak-html-publication";
11
11
  @import "components/print/govspeak";
12
12
  @import "components/print/layout-super-navigation-header";
13
+ @import "components/print/organisation-logo";
13
14
  @import "components/print/step-by-step-nav-header";
14
15
  @import "components/print/step-by-step-nav";
15
16
  @import "components/print/textarea";
@@ -1,3 +1,7 @@
1
+ .gem-c-organisation-logo {
2
+ width: 25%;
3
+ }
4
+
1
5
  .gem-c-organisation-logo__image {
2
6
  max-width: 100%;
3
7
  }
@@ -27,6 +27,9 @@
27
27
  data_attributes[:track_show_all_clicks] = track_show_all_clicks
28
28
  data_attributes[:track_sections] = track_sections
29
29
 
30
+ data_attributes_show_all ||= nil
31
+ data_attributes[:show_all_attributes] = data_attributes_show_all if data_attributes_show_all
32
+
30
33
  translations.each do |key, translation|
31
34
  locales[key] = shared_helper.t_locale(translation)
32
35
  data_attributes[key] = t(translation)
@@ -47,8 +50,8 @@
47
50
  <%= tag.div(class: accordion_classes, id: id, data: data_attributes) do %>
48
51
  <% items.each_with_index do |item, i| %>
49
52
  <%
50
- # The GOVUK Frontend JavaScript for this component
51
- # uses a loop starting at 1 for accessing heading ID values,
53
+ # The GOVUK Frontend JavaScript for this component
54
+ # uses a loop starting at 1 for accessing heading ID values,
52
55
  # hence the increment below
53
56
  index = i + 1
54
57
 
@@ -65,11 +68,10 @@
65
68
  content_tag(
66
69
  shared_helper.get_heading_level,
67
70
  content_tag(
68
- 'span',
69
- item[:heading][:text],
71
+ 'span',
72
+ item[:heading][:text],
70
73
  class: "govuk-accordion__section-button",
71
74
  id: "#{id}-heading-#{index}"
72
-
73
75
  ),
74
76
  class: "govuk-accordion__section-heading",
75
77
  id: item[:heading][:id],
@@ -17,7 +17,7 @@
17
17
 
18
18
  <%= render "govuk_publishing_components/components/textarea", { id: id, character_count: true }.merge(textarea.symbolize_keys) %>
19
19
 
20
- <div id="<%= id %>-info" class="govuk-hint govuk-character-count__message" aria-live="polite">
20
+ <div id="<%= id %>-info" class="govuk-hint govuk-character-count__message">
21
21
  <%= t("components.character_count.body", number: maxlength || maxwords, type: maxwords ? t("components.character_count.type.words") : t("components.character_count.type.characters")) %>
22
22
  </div>
23
23
  <% end %>
@@ -29,7 +29,6 @@
29
29
  aria_described_by << describedby if describedby
30
30
  aria_described_by = aria_described_by.join(" ")
31
31
  end
32
-
33
32
  %>
34
33
 
35
34
  <%= content_tag :div, class: form_group_css_classes do %>
@@ -62,9 +62,7 @@
62
62
  if type == "number"
63
63
  type = "text"
64
64
  inputmode = "numeric"
65
- pattern = "[0-9]*"
66
65
  end
67
-
68
66
  %>
69
67
 
70
68
  <%= content_tag :div, class: form_group_css_classes do %>
@@ -189,10 +189,17 @@ examples:
189
189
 
190
190
  Each item can also have a `data_attributes` hash. These `data_attributes` are placed on the `button` that triggers the opening and closing - useful for differentiating between each section of the accordion.
191
191
 
192
+ Data attributes can also be added to the 'Show/hide all' link using the `data_attributes_show_all` option, primarily where custom tracking is required. These attributes are read from the accordion markup and then added to the link by JavaScript (which is how the link is created).
192
193
  data:
193
194
  data_attributes:
194
195
  gtm: gtm-accordion
195
196
  ga: ga-accordion
197
+ data_attributes_show_all:
198
+ module: example
199
+ track-action: click
200
+ ui:
201
+ type: test
202
+ text: something
196
203
  items:
197
204
  - heading:
198
205
  text: Writing well for the web
@@ -277,13 +284,13 @@ examples:
277
284
  html: <p class="govuk-body">This is the content for How people read.</p>
278
285
  with_the_anchor_link_navigation:
279
286
  description: |
280
- Some apps require custom `id`s per accordion section heading. Custom `id`s allow you to link section headings, sometimes across multiple pages.
281
-
287
+ Some apps require custom `id`s per accordion section heading. Custom `id`s allow you to link section headings, sometimes across multiple pages.
288
+
282
289
  For example on [guidance pages for Content Designers, referred to as "manuals",](https://www.gov.uk/guidance/how-to-publish-on-gov-uk/creating-and-updating-pages#associations) each manual includes multiple sets of accordions and will reference between specific sections to easily access content.
283
290
 
284
- Using the same rules, custom `id`s automatically open accordions when users click within another accordion that links to either
291
+ Using the same rules, custom `id`s automatically open accordions when users click within another accordion that links to either
285
292
 
286
- * the `id` of an accordion section heading
293
+ * the `id` of an accordion section heading
287
294
  * an `id` within the content of an accordion (this will also automatically navigate to and open accordions on page load)
288
295
 
289
296
  This feature will only be used if the `anchor_navigation` flag is passed as `true`. This mitigates performance risk from event listeners on a large number of links.
@@ -294,13 +301,13 @@ examples:
294
301
  items:
295
302
  - heading:
296
303
  text: Writing well for the web
297
- id: writing-well-for-the-web
304
+ id: writing-well-for-the-web-1
298
305
  content:
299
- html: <p class="govuk-body">This is content for accordion 1 of 2</p><p class="govuk-body">This content contains a <a href="#anchor-nav-test" class="govuk-link">link</a></p>
306
+ html: <p class="govuk-body">This is content for accordion 1 of 2</p><p class="govuk-body">This content contains a <a href="#anchor-nav-test-1" class="govuk-link">link</a></p>
300
307
  - heading:
301
308
  text: Writing well for specialists
302
309
  content:
303
- html: <p class="govuk-body" id="anchor-nav-test">This is content for accordion 2 of 2</p>
310
+ html: <p class="govuk-body" id="anchor-nav-test-1">This is content for accordion 2 of 2</p>
304
311
  - heading:
305
312
  text: Know your audience
306
313
  content:
@@ -312,31 +319,31 @@ examples:
312
319
  with_track_show_all_clicks:
313
320
  description: |
314
321
  To switch on Google Analytics for the "Show all sections" button on click, pass `track_show_all_clicks: true` the values passed on open will be
315
- `Event Action: accordionOpened` `Event Category: pageElementInteraction` `Event Label: Show all sections`
322
+ `Event Action: accordionOpened` `Event Category: pageElementInteraction` `Event Label: Show all sections`
316
323
  data:
317
324
  track_show_all_clicks: true
318
325
  items:
319
326
  - heading:
320
327
  text: Writing well for the web
321
- id: writing-well-for-the-web
328
+ id: writing-well-for-the-web-2
322
329
  content:
323
- html: <p class="govuk-body">This is content for accordion 1 of 2</p><p class="govuk-body">This content contains a <a href="#anchor-nav-test" class="govuk-link">link</a></p>
330
+ html: <p class="govuk-body">This is content for accordion 1 of 2</p>
324
331
  - heading:
325
332
  text: Writing well for specialists
326
333
  content:
327
- html: <p class="govuk-body" id="anchor-nav-test">This is content for accordion 2 of 2</p>
334
+ html: <p class="govuk-body">This is content for accordion 2 of 2</p>
328
335
  with_track_sections:
329
336
  description: |
330
337
  To switch on Google Analytics for each section, on click, pass `track_sections: true` the values passed on open will be
331
338
  `Event Action: accordionOpened` / `accordionClosed` `Event Category: pageElementInteraction` and the `Event Label` being the heading text.
332
-
339
+
333
340
  (`track_show_all_clicks: true` can be added to track the "Show all sections" button as well, if required)
334
341
  data:
335
342
  track_sections: true
336
343
  items:
337
344
  - heading:
338
345
  text: Writing well for the web
339
- id: writing-well-for-the-web
346
+ id: writing-well-for-the-web-3
340
347
  content:
341
348
  html: <p class="govuk-body">This is content for accordion 1 of 2</p><p class="govuk-body">This content contains a <a href="#anchor-nav-test" class="govuk-link">link</a></p>
342
349
  - heading:
@@ -2,7 +2,7 @@ module GovukPublishingComponents
2
2
  module Presenters
3
3
  class PublicLayoutHelper
4
4
  FOOTER_NAVIGATION_COLUMNS = [2, 1].freeze
5
- FOOTER_TRACK_ACTIONS = %w[topicsLink governmentActivityLink].freeze
5
+ FOOTER_TRACK_ACTIONS = %w[topicsLink governmentactivityLink].freeze
6
6
  FOOTER_META = {
7
7
  items: [
8
8
  {
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "29.10.0".freeze
2
+ VERSION = "29.11.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 29.10.0
4
+ version: 29.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2022-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config