govuk_publishing_components 37.6.1 → 37.7.1

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: 057a27088f3e56f3de0b207bf272737059e084e11f7ad5d60c9c64f51b36f36c
4
- data.tar.gz: 2e7c53dbecff6dcb761c8b181be7c22a051d1e67738f96d6386cc24b08e4a850
3
+ metadata.gz: 6c466a7b84ca0509041a581929a94d5a1526f17673544ba08bb933ae70ba5ec0
4
+ data.tar.gz: 42c52ce52d1175d9e4056b447ce1ecdb2d370464f0e5dfc397a8ed5854082110
5
5
  SHA512:
6
- metadata.gz: 853e1a7952502815cc9cf864feedb258266b06f402c37d8622ce3e2a8550b160bfc676e60221b5e6a0332adca201bc7a8b651d3cee2ff451f9ade26c61a74304
7
- data.tar.gz: 54df263cbc3fe4b0a4bf2b7f8e3207e5d0292fb6dd79fddfe87cdcea0b844d0c5b4a73527de5ef7d747991e505af18b25228c8644d6c973a5431fb993707a3f7
6
+ metadata.gz: 07ea726dd1d183cf53247fa67897d38ed01d62885bf89a00b1af97b1682d283af3b5a0c709652e24168735008a990d8ed53cc7e3ef5c40c4721c323aeb544d18
7
+ data.tar.gz: dfc666345a441e87d80f1a47f49d987ef00961ae18f99b637a890ef587985edfcbce6fb6f27a89c36fbd04074461a6389f23da1c8a56d4183c3bb2ce7996ddea
@@ -40,11 +40,33 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
40
40
  return
41
41
  }
42
42
 
43
- // don't track this link if it's already being tracked by the another tracker (e.g. the link tracker or ecommerce tracker)
44
- if (element.closest('[data-ga4-link]') || element.closest('[data-ga4-ecommerce-path]')) {
43
+ // Don't track this link if it's already being tracked by the ecommerce tracker
44
+ if (element.closest('[data-ga4-ecommerce-path]')) {
45
45
  return
46
46
  }
47
47
 
48
+ // Code below ensures the tracker plays nicely with the other link tracker
49
+ var otherLinkTracker = element.closest('[data-ga4-link]')
50
+ if (otherLinkTracker) {
51
+ var limitToElementClass = otherLinkTracker.getAttribute('data-ga4-limit-to-element-class')
52
+
53
+ if (!limitToElementClass) {
54
+ // If this link is inside the other link tracker, and the other link tracker IS NOT limiting itself to specific classes,
55
+ // then stop this tracker from firing, as the other tracker is responsible for this link.
56
+ return
57
+ } else {
58
+ // If this link is inside the other link tracker, but the other link tracker IS limiting itself to specific classes,
59
+ // then track the link here only if it is not within the specified classes that the other tracker is looking for.
60
+ var classes = limitToElementClass.split(',')
61
+
62
+ for (var i = 0; i < classes.length; i++) {
63
+ if (element.closest('.' + classes[i].trim())) {
64
+ return
65
+ }
66
+ }
67
+ }
68
+ }
69
+
48
70
  var href = element.getAttribute('href')
49
71
 
50
72
  if (!href) {
@@ -93,6 +93,8 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
93
93
  this.$module = $module
94
94
  this.$searchToggle = this.$module.querySelector('#super-search-menu-toggle')
95
95
  this.$searchMenu = this.$module.querySelector('#super-search-menu')
96
+ this.$navToggle = this.$module.querySelector('#super-navigation-menu-toggle')
97
+ this.$navMenu = this.$module.querySelector('#super-navigation-menu')
96
98
 
97
99
  // The menu toggler buttons need three attributes for this to work:
98
100
  // - `aria-controls` contains the id of the menu to be toggled
@@ -126,7 +128,68 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
126
128
  toggle($target, $targetMenu)
127
129
  }
128
130
 
131
+ SuperNavigationMegaMenu.prototype.handleKeyDown = function (event) {
132
+ var KEY_TAB = 9
133
+ var KEY_ESC = 27
134
+ var $navMenuLinks = this.$navMenu.querySelectorAll('li a')
135
+ var $firstNavLink = $navMenuLinks[0]
136
+ var $lastNavLink = $navMenuLinks[$navMenuLinks.length - 1]
137
+ var $searchMenuLinks = this.$searchMenu.querySelectorAll('li a')
138
+ var $lastSearchLink = $searchMenuLinks[$searchMenuLinks.length - 1]
139
+
140
+ if (event.keyCode === KEY_TAB) {
141
+ if (!this.$navMenu.hasAttribute('hidden')) {
142
+ switch (document.activeElement) {
143
+ case this.$navToggle:
144
+ if (!event.shiftKey) {
145
+ event.preventDefault()
146
+ $firstNavLink.focus()
147
+ }
148
+ break
149
+ case $lastNavLink:
150
+ if (!event.shiftKey) {
151
+ event.preventDefault()
152
+ this.$searchToggle.focus()
153
+ hide(this.$navToggle, this.$navMenu)
154
+ }
155
+ break
156
+ case $firstNavLink:
157
+ if (event.shiftKey) {
158
+ event.preventDefault()
159
+ this.$navToggle.focus()
160
+ }
161
+ break
162
+ case this.$searchToggle:
163
+ if (event.shiftKey) {
164
+ event.preventDefault()
165
+ $lastNavLink.focus()
166
+ }
167
+ break
168
+ default:
169
+ break
170
+ }
171
+ } else if (!this.$searchMenu.hasAttribute('hidden')) {
172
+ if (document.activeElement === $lastSearchLink) {
173
+ if (!event.shiftKey) {
174
+ hide(this.$searchToggle, this.$searchMenu)
175
+ }
176
+ }
177
+ }
178
+ } else if (event.keyCode === KEY_ESC) {
179
+ if (!this.$navMenu.hasAttribute('hidden')) {
180
+ hide(this.$navToggle, this.$navMenu)
181
+ this.$navToggle.focus()
182
+ } else if (!this.$searchMenu.hasAttribute('hidden')) {
183
+ hide(this.$searchToggle, this.$searchMenu)
184
+ this.$searchToggle.focus()
185
+ }
186
+ }
187
+ }
188
+
129
189
  SuperNavigationMegaMenu.prototype.init = function () {
190
+ // Handle key events for tab and escape keys
191
+ this.$module.addEventListener('keydown', this.handleKeyDown.bind(this))
192
+
130
193
  for (var j = 0; j < this.$buttons.length; j++) {
131
194
  var $button = this.$buttons[j]
132
195
  $button.addEventListener('click', this.buttonHandler.bind(this), true)
@@ -3,6 +3,7 @@
3
3
  // This adds in javascript that initialises components and dependencies
4
4
  // that are provided by Slimmer in public frontend applications.
5
5
  // = require ./modules.js
6
+ // = require ./single-consent-functions.js
6
7
 
7
8
  document.addEventListener('DOMContentLoaded', function () {
8
9
  window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}
@@ -27,6 +27,10 @@
27
27
  event.keyCode = keyCode
28
28
  }
29
29
 
30
+ if (params.shiftKey) {
31
+ event.shiftKey = true
32
+ }
33
+
30
34
  element.dispatchEvent(event)
31
35
  }
32
36
  }(window))
@@ -10,9 +10,20 @@
10
10
  classes << "disable-youtube" if disable_youtube_expansions
11
11
  classes << "gem-c-govspeak--inverse" if inverse
12
12
 
13
+ disable_ga4 ||= false
14
+
13
15
  data_modules = "govspeak"
16
+ data_modules << " ga4-link-tracker" unless disable_ga4
14
17
  data_attributes = { module: data_modules }
15
18
 
19
+ unless disable_ga4
20
+ data_attributes.merge!({
21
+ ga4_track_links_only: "",
22
+ ga4_limit_to_element_class: "call-to-action, info-notice, help-notice, advisory",
23
+ ga4_link: { "event_name": "navigation", "type": "callout" }.to_json,
24
+ })
25
+ end
26
+
16
27
  %>
17
28
 
18
29
  <%= tag.div(class: "gem-c-govspeak govuk-govspeak " + classes.join(" "), data: data_attributes) do %>
@@ -162,7 +162,6 @@
162
162
 
163
163
  <%
164
164
  link = t("components.layout_super_navigation_header.navigation_link")
165
- unique_id = SecureRandom.hex(4)
166
165
  show_menu_text = show_navigation_menu_text
167
166
  hide_menu_text = hide_navigation_menu_text
168
167
  tracking_label = link[:label].downcase.gsub(/\s+/, "")
@@ -192,7 +191,7 @@
192
191
 
193
192
  <%= content_tag(:button, {
194
193
  aria: {
195
- controls: "super-navigation-menu-#{unique_id}",
194
+ controls: "super-navigation-menu",
196
195
  expanded: false,
197
196
  label: show_menu_text,
198
197
  },
@@ -213,7 +212,7 @@
213
212
  }
214
213
  },
215
214
  hidden: true,
216
- id: "super-navigation-menu-#{unique_id}-toggle",
215
+ id: "super-navigation-menu-toggle",
217
216
  type: "button",
218
217
  }) do %>
219
218
  <%= tag.span link[:label], class: top_toggle_button_inner_classes %>
@@ -282,7 +281,7 @@
282
281
  </div>
283
282
 
284
283
  <%= content_tag(:div, {
285
- id: "super-navigation-menu-#{unique_id}",
284
+ id: "super-navigation-menu",
286
285
  hidden: "",
287
286
  class: dropdown_menu_classes,
288
287
  }) do %>
@@ -914,3 +914,12 @@ examples:
914
914
  <p>Deforested area. Credit: Blue Ventures-Garth Cripps</p>
915
915
  </figcaption>
916
916
  </figure>
917
+ without_ga4_tracking:
918
+ description: |
919
+ Disables GA4 tracking on the component. Tracking is enabled by default. This adds a data module and data-attributes with JSON data. See the [ga4-link-tracker documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-ga4/ga4-link-tracker.md) for more information.
920
+ data:
921
+ block: |
922
+ <p>
923
+ <a href='https://www.gov.uk'>Hello World</a>
924
+ </p>
925
+ disable_ga4: true
@@ -7,6 +7,8 @@ accessibility_criteria: |
7
7
  The component must:
8
8
 
9
9
  * have a text contrast ratio higher than 4.5:1 against the background colour to meet WCAG AA
10
+ * follow the expected tabbing border
11
+ * allow menus to be closed when the escape key is pressed
10
12
 
11
13
  Images in the super navigation header must:
12
14
 
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "37.6.1".freeze
2
+ VERSION = "37.7.1".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: 37.6.1
4
+ version: 37.7.1
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: 2024-03-11 00:00:00.000000000 Z
11
+ date: 2024-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -528,13 +528,13 @@ files:
528
528
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js
529
529
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js
530
530
  - app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js
531
- - app/assets/javascripts/govuk_publishing_components/lib/single-consent-functions.js
532
531
  - app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js
533
532
  - app/assets/javascripts/govuk_publishing_components/lib/toggle.js
534
533
  - app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
535
534
  - app/assets/javascripts/govuk_publishing_components/load-analytics.js
536
535
  - app/assets/javascripts/govuk_publishing_components/modules.js
537
536
  - app/assets/javascripts/govuk_publishing_components/rum-loader.js
537
+ - app/assets/javascripts/govuk_publishing_components/single-consent-functions.js
538
538
  - app/assets/javascripts/govuk_publishing_components/vendor/html5shiv-printshiv.js
539
539
  - app/assets/javascripts/govuk_publishing_components/vendor/json2.js
540
540
  - app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-measurer.js