govuk_publishing_components 35.2.0 → 35.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/component_guide/application.js +1 -0
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-core.js +26 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +7 -5
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js +5 -0
- data/app/assets/javascripts/govuk_publishing_components/components/intervention.js +69 -0
- data/app/assets/javascripts/govuk_publishing_components/lib/cookie-functions.js +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_brand-colours.scss +9 -0
- data/app/views/govuk_publishing_components/components/_accordion.html.erb +25 -1
- data/app/views/govuk_publishing_components/components/_contextual_sidebar.html.erb +6 -3
- data/app/views/govuk_publishing_components/components/_intervention.html.erb +15 -7
- data/app/views/govuk_publishing_components/components/_related_navigation.html.erb +3 -4
- data/app/views/govuk_publishing_components/components/_step_by_step_nav.html.erb +23 -3
- data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb +7 -1
- data/app/views/govuk_publishing_components/components/docs/intervention.yml +11 -6
- data/app/views/govuk_publishing_components/components/related_navigation/_section.html.erb +11 -5
- data/lib/govuk_publishing_components/presenters/intervention_helper.rb +16 -5
- data/lib/govuk_publishing_components/presenters/related_navigation_helper.rb +9 -1
- data/lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb +0 -16
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7d5e0e3ab0fa8c2a8ab33e0a41c142dbc9c967f53095dae21edcbef938ba2c3
|
4
|
+
data.tar.gz: 52e3130b7b3d04d05456dfb0efa86cad9f2a70a3cd06447da44a70d31a7c06d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fdfcedf36b4a26d5b834d49fb1a7d4ec64de5e0c808022e6904f1de99f4294c96e125ac9c28096d04ac47ce43796b73cdb0fb288dc2242d3d39682e524d5b64
|
7
|
+
data.tar.gz: c0fe259f8445f2a0f0b7e8cc72334f2fca3880dcb810bd7e2a4b09eababda3633841b49db194864828a9cca44e266c3f0742f574c1ce32b1f6a88f3bec8749b1
|
@@ -2,4 +2,5 @@
|
|
2
2
|
//= require_tree .
|
3
3
|
//= require ../govuk_publishing_components/dependencies
|
4
4
|
//= require ../govuk_publishing_components/components/accordion
|
5
|
+
//= require ../govuk_publishing_components/components/intervention
|
5
6
|
//= require ../govuk_publishing_components/components/tabs
|
@@ -230,7 +230,7 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
|
|
230
230
|
// Only index links that are not search results
|
231
231
|
if (!link.getAttribute('data-ga4-ecommerce-path')) {
|
232
232
|
totalLinks++
|
233
|
-
link.setAttribute('data-ga4-index', '{"index_link":
|
233
|
+
link.setAttribute('data-ga4-index', '{"index_link": ' + totalLinks + '}')
|
234
234
|
}
|
235
235
|
}
|
236
236
|
|
@@ -273,6 +273,31 @@ window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {};
|
|
273
273
|
index_link: parseInt(index[2])
|
274
274
|
}
|
275
275
|
}
|
276
|
+
},
|
277
|
+
|
278
|
+
addAttributesToElements: function (selector, dataAttributes) {
|
279
|
+
var targetElements = document.querySelectorAll(selector)
|
280
|
+
|
281
|
+
for (var i = 0; i < targetElements.length; i++) {
|
282
|
+
var element = targetElements[i]
|
283
|
+
|
284
|
+
for (var j = 0; j < dataAttributes.length; j++) {
|
285
|
+
var key = dataAttributes[j].key
|
286
|
+
var value = dataAttributes[j].value
|
287
|
+
|
288
|
+
// value must check for undefined only as it would return false on an empty string, the number 0, etc.
|
289
|
+
if (key && value !== undefined) {
|
290
|
+
var existingAttributeValue = element.getAttribute(key)
|
291
|
+
|
292
|
+
if (key === 'data-module' && existingAttributeValue) {
|
293
|
+
// Combines values to prevent replacing any existing data-module values.
|
294
|
+
element.setAttribute(key, existingAttributeValue + ' ' + value)
|
295
|
+
} else {
|
296
|
+
element.setAttribute(key, value)
|
297
|
+
}
|
298
|
+
}
|
299
|
+
}
|
300
|
+
}
|
276
301
|
}
|
277
302
|
},
|
278
303
|
|
@@ -108,20 +108,22 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
108
108
|
}
|
109
109
|
|
110
110
|
Ga4LinkTracker.prototype.setIndex = function (indexData, target) {
|
111
|
-
var index
|
111
|
+
var index = window.GOVUK.analyticsGa4.core.trackFunctions.createIndexObject(indexData)
|
112
112
|
|
113
113
|
if (target.getAttribute('data-ga4-index')) {
|
114
114
|
try {
|
115
|
-
|
115
|
+
var indexLink = JSON.parse(target.getAttribute('data-ga4-index'))
|
116
|
+
|
117
|
+
// Check whether the index object already exists on a parent element, as is the case with tracking accordion links.
|
118
|
+
// If true, combine data-ga4-index with the index object. Otherwise, just return indexLink
|
119
|
+
index = index ? window.GOVUK.extendObject(index, indexLink) : indexLink
|
116
120
|
} catch (e) {
|
117
121
|
console.error('Unable to parse index as JSON: ' + e.message, window.location)
|
118
122
|
return
|
119
123
|
}
|
120
|
-
} else {
|
121
|
-
index = indexData || undefined
|
122
124
|
}
|
123
125
|
|
124
|
-
return
|
126
|
+
return index
|
125
127
|
}
|
126
128
|
|
127
129
|
Modules.Ga4LinkTracker = Ga4LinkTracker
|
@@ -8,6 +8,11 @@ var initFunction = function () {
|
|
8
8
|
window.GOVUK.analyticsGa4.vars.internalDomains = []
|
9
9
|
window.GOVUK.analyticsGa4.vars.internalDomains.push(window.GOVUK.analyticsGa4.core.trackFunctions.getHostname())
|
10
10
|
window.GOVUK.analyticsGa4.core.trackFunctions.appendDomainsWithoutWWW(window.GOVUK.analyticsGa4.vars.internalDomains)
|
11
|
+
var attachmentLinkData = [
|
12
|
+
{ key: 'data-module', value: 'ga4-link-tracker' },
|
13
|
+
{ key: 'data-ga4-track-links-only', value: '' },
|
14
|
+
{ key: 'data-ga4-link', value: JSON.stringify({ event_name: 'navigation', type: 'html attachment' }) }]
|
15
|
+
window.GOVUK.analyticsGa4.core.trackFunctions.addAttributesToElements('[data-ga4-attachment-link]', attachmentLinkData)
|
11
16
|
window.GOVUK.analyticsGa4.core.load()
|
12
17
|
|
13
18
|
var analyticsModules = window.GOVUK.analyticsGa4.analyticsModules
|
@@ -0,0 +1,69 @@
|
|
1
|
+
window.GOVUK = window.GOVUK || {}
|
2
|
+
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
3
|
+
|
4
|
+
(function (Modules) {
|
5
|
+
function Intervention ($module) {
|
6
|
+
this.$module = $module
|
7
|
+
this.$closeLink = this.$module.querySelector('.js-dismiss-link')
|
8
|
+
this.$campaignName = this.$module.getAttribute('data-intervention-name')
|
9
|
+
this.$campaignCookie = window.GOVUK.cookie('intervention_campaign') || ''
|
10
|
+
}
|
11
|
+
|
12
|
+
Intervention.prototype.init = function () {
|
13
|
+
this.$cookieHasCampaign = this.cookieHasCampaign()
|
14
|
+
|
15
|
+
if (this.$closeLink) {
|
16
|
+
this.$module.close = this.handleClose.bind(this)
|
17
|
+
this.$closeLink.addEventListener('click', this.$module.close)
|
18
|
+
}
|
19
|
+
|
20
|
+
if (this.$cookieHasCampaign) {
|
21
|
+
this.hideBanner()
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
Intervention.prototype.handleClose = function (event) {
|
26
|
+
event.preventDefault()
|
27
|
+
|
28
|
+
if (this.$cookieHasCampaign) {
|
29
|
+
this.setCookies()
|
30
|
+
}
|
31
|
+
this.hideBanner()
|
32
|
+
}
|
33
|
+
|
34
|
+
Intervention.prototype.cookieHasCampaign = function () {
|
35
|
+
if (this.$campaignCookie) {
|
36
|
+
return this.cookieValues().includes(this.$campaignName)
|
37
|
+
}
|
38
|
+
return false
|
39
|
+
}
|
40
|
+
|
41
|
+
Intervention.prototype.cookieValues = function () {
|
42
|
+
if (this.$campaignCookie !== null && this.$campaignCookie.length > 0) {
|
43
|
+
return this.$campaignCookie.split(',')
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
Intervention.prototype.appendCookieValues = function () {
|
48
|
+
return this.$campaignCookie + ',' + this.$campaignName
|
49
|
+
}
|
50
|
+
|
51
|
+
Intervention.prototype.setCookies = function () {
|
52
|
+
if (this.$campaignCookie) {
|
53
|
+
window.GOVUK.setCookie('intervention_campaign', this.appendCookieValues(), { days: 30 })
|
54
|
+
} else {
|
55
|
+
window.GOVUK.setCookie('intervention_campaign', this.$campaignName, { days: 30 })
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
Intervention.prototype.hideBanner = function () {
|
60
|
+
if (!this.$cookieHasCampaign) {
|
61
|
+
this.setCookies()
|
62
|
+
}
|
63
|
+
|
64
|
+
this.$module.hidden = true
|
65
|
+
this.$module.style.display = 'none'
|
66
|
+
}
|
67
|
+
|
68
|
+
Modules.Intervention = Intervention
|
69
|
+
})(window.GOVUK.Modules)
|
@@ -17,6 +17,7 @@
|
|
17
17
|
cookie_preferences_set: 'essential',
|
18
18
|
cookies_preferences_set: 'essential',
|
19
19
|
'_email-alert-frontend_session': 'essential',
|
20
|
+
intervention_campaign: 'essential',
|
20
21
|
licensing_session: 'essential',
|
21
22
|
govuk_contact_referrer: 'essential',
|
22
23
|
multivariatetest_cohort_coronavirus_extremely_vulnerable_rate_limit: 'essential',
|
data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_brand-colours.scss
CHANGED
@@ -87,3 +87,12 @@
|
|
87
87
|
border-color: govuk-colour("black");
|
88
88
|
}
|
89
89
|
}
|
90
|
+
|
91
|
+
// new colour for DSIT for use until govuk-frontend#3523 has been released
|
92
|
+
|
93
|
+
.brand--department-for-science-innovation-and-technology {
|
94
|
+
&.brand__border-color,
|
95
|
+
.brand__border-color {
|
96
|
+
border-color: #045f71;
|
97
|
+
}
|
98
|
+
}
|
@@ -37,6 +37,7 @@
|
|
37
37
|
index = i + 1
|
38
38
|
|
39
39
|
item[:data_attributes] ||= nil
|
40
|
+
ga4_link_data_attributes ||= nil
|
40
41
|
|
41
42
|
if ga4_tracking
|
42
43
|
item[:data_attributes] ||= {}
|
@@ -49,6 +50,23 @@
|
|
49
50
|
index_section_count: items.length,
|
50
51
|
},
|
51
52
|
}.to_json
|
53
|
+
|
54
|
+
# These attributes have been created separately from the item[:data_attributes]
|
55
|
+
# object in order to keep them from colliding with GA4 event tracking and UA
|
56
|
+
# tracking attributes
|
57
|
+
ga4_link_data_attributes = {}
|
58
|
+
ga4_link_data_attributes[:module] = "ga4-link-tracker"
|
59
|
+
ga4_link_data_attributes[:ga4_tracks_links_only] = ""
|
60
|
+
ga4_link_data_attributes[:ga4_set_indexes] = ""
|
61
|
+
ga4_link_data_attributes[:ga4_link] = {
|
62
|
+
event_name: "navigation",
|
63
|
+
type: "accordion",
|
64
|
+
section: item[:heading][:text],
|
65
|
+
index: {
|
66
|
+
index_section: index,
|
67
|
+
index_section_count: (items.length),
|
68
|
+
}
|
69
|
+
}.to_json
|
52
70
|
end
|
53
71
|
|
54
72
|
section_classes = %w(govuk-accordion__section)
|
@@ -74,7 +92,13 @@
|
|
74
92
|
%>
|
75
93
|
<%= tag.div(item[:summary][:text], id: "#{id}-summary-#{index}", class: summary_classes) if item[:summary].present? %>
|
76
94
|
<% end %>
|
77
|
-
<%= tag.div(
|
95
|
+
<%= tag.div(
|
96
|
+
item[:content][:html],
|
97
|
+
id: "#{id}-content-#{index}",
|
98
|
+
class: "govuk-accordion__section-content",
|
99
|
+
'aria-labelledby': "#{id}-heading-#{index}",
|
100
|
+
data: ga4_link_data_attributes
|
101
|
+
) %>
|
78
102
|
<% end %>
|
79
103
|
<% end %>
|
80
104
|
<% end %>
|
@@ -5,6 +5,9 @@
|
|
5
5
|
request.query_parameters[:ga4_tracking] = ga4_tracking
|
6
6
|
navigation = GovukPublishingComponents::Presenters::ContextualNavigation.new(content_item, request)
|
7
7
|
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
|
8
|
+
show_ukraine_cta = navigation.show_ukraine_cta?
|
9
|
+
ga4_tracking_counts = OpenStruct.new(index_section_count: 0)
|
10
|
+
ga4_tracking_counts.index_section_count = 1 if show_ukraine_cta
|
8
11
|
%>
|
9
12
|
|
10
13
|
<div class="gem-c-contextual-sidebar">
|
@@ -18,7 +21,7 @@
|
|
18
21
|
<%= render 'govuk_publishing_components/components/step_by_step_nav', navigation.step_nav_helper.sidebar %>
|
19
22
|
<% else %>
|
20
23
|
<%# Rendering related navigation sidebar because no step by step list %>
|
21
|
-
<%= render 'govuk_publishing_components/components/related_navigation', content_item: content_item, context: :sidebar, ga4_tracking: ga4_tracking %>
|
24
|
+
<%= render 'govuk_publishing_components/components/related_navigation', content_item: content_item, context: :sidebar, ga4_tracking: ga4_tracking, ga4_tracking_counts: ga4_tracking_counts %>
|
22
25
|
<% end %>
|
23
26
|
|
24
27
|
<% if navigation.content_tagged_to_other_step_by_steps? %>
|
@@ -31,7 +34,7 @@
|
|
31
34
|
} %>
|
32
35
|
<% end %>
|
33
36
|
|
34
|
-
<% if
|
35
|
-
<%= render 'govuk_publishing_components/components/contextual_sidebar/ukraine_cta', content_item: content_item, ga4_tracking: ga4_tracking %>
|
37
|
+
<% if show_ukraine_cta %>
|
38
|
+
<%= render 'govuk_publishing_components/components/contextual_sidebar/ukraine_cta', content_item: content_item, ga4_tracking: ga4_tracking, ga4_tracking_counts: ga4_tracking_counts %>
|
36
39
|
<% end %>
|
37
40
|
</div>
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<%
|
2
2
|
add_gem_component_stylesheet("intervention")
|
3
3
|
|
4
|
+
name ||= ""
|
4
5
|
dismiss_text ||= false
|
5
6
|
suggestion_link_text ||= false
|
6
7
|
suggestion_link_url ||= false
|
@@ -10,16 +11,23 @@
|
|
10
11
|
|
11
12
|
data_attributes ||= {}
|
12
13
|
suggestion_data_attributes ||= {}
|
13
|
-
|
14
|
+
data_attributes[:module] = "intervention"
|
15
|
+
data_attributes["intervention-name"] = name
|
14
16
|
|
15
17
|
aria_attributes ||= {}
|
16
18
|
aria_attributes[:label] = 'Intervention'
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
options = {
|
21
|
+
name: name,
|
22
|
+
dismiss_text: dismiss_text,
|
23
|
+
params: request.params,
|
24
|
+
query_string: request.query_string,
|
25
|
+
suggestion_text: suggestion_text,
|
26
|
+
suggestion_link_text: suggestion_link_text,
|
27
|
+
suggestion_link_url: suggestion_link_url,
|
28
|
+
}
|
21
29
|
|
22
|
-
intervention_helper = GovukPublishingComponents::Presenters::InterventionHelper.new(
|
30
|
+
intervention_helper = GovukPublishingComponents::Presenters::InterventionHelper.new(options)
|
23
31
|
dismiss_href = intervention_helper.dismiss_link
|
24
32
|
|
25
33
|
suggestion_tag_options = {
|
@@ -44,7 +52,7 @@
|
|
44
52
|
}
|
45
53
|
section_options.merge!({ hidden: true }) if hide
|
46
54
|
%>
|
47
|
-
<% if
|
55
|
+
<% if intervention_helper.show? %>
|
48
56
|
<%= tag.section **section_options do %>
|
49
57
|
<p class="govuk-body">
|
50
58
|
<%= tag.span suggestion_text, class: "gem-c-intervention__textwrapper" if suggestion_text %>
|
@@ -55,7 +63,7 @@
|
|
55
63
|
|
56
64
|
<% if dismiss_text %>
|
57
65
|
<p class="govuk-body">
|
58
|
-
<%= tag.a class: "govuk-link", href: dismiss_href
|
66
|
+
<%= tag.a class: "govuk-link js-dismiss-link", href: dismiss_href do %>
|
59
67
|
<svg class="gem-c-intervention__dismiss-icon"
|
60
68
|
width="19" height="19" viewBox="0 0 19 19"
|
61
69
|
aria-hidden="true"
|
@@ -5,12 +5,11 @@
|
|
5
5
|
data = {}
|
6
6
|
data[:module] = "gem-track-click"
|
7
7
|
data[:module] << " ga4-link-tracker" if ga4_tracking
|
8
|
-
|
8
|
+
ga4_tracking_counts ||= OpenStruct.new(index_section_count: 0)
|
9
|
+
ga4_tracking_counts.index_section_count += related_nav_helper.index_section_count
|
9
10
|
|
10
|
-
<%
|
11
11
|
add_gem_component_stylesheet("related-navigation")
|
12
12
|
%>
|
13
|
-
|
14
13
|
<% if related_nav_helper.related_navigation? %>
|
15
14
|
<% random = SecureRandom.hex(4) %>
|
16
15
|
<%= tag.div(class: "gem-c-related-navigation", data: data) do %>
|
@@ -30,7 +29,6 @@
|
|
30
29
|
<% end %>
|
31
30
|
|
32
31
|
<% section_index = 0 %>
|
33
|
-
|
34
32
|
<% related_nav_helper.related_navigation.each do |section_title, links| %>
|
35
33
|
<% next unless links.any? %>
|
36
34
|
|
@@ -42,6 +40,7 @@
|
|
42
40
|
section_title: section_title,
|
43
41
|
links: links,
|
44
42
|
section_index: section_index,
|
43
|
+
section_count: ga4_tracking_counts.index_section_count,
|
45
44
|
random: random,
|
46
45
|
ga4_tracking: ga4_tracking %>
|
47
46
|
<% end %>
|
@@ -22,7 +22,7 @@
|
|
22
22
|
%>
|
23
23
|
<% if steps %>
|
24
24
|
<div
|
25
|
-
data-module="gemstepnav<% if ga4_tracking %> ga4-event-tracker
|
25
|
+
data-module="gemstepnav<% if ga4_tracking %> ga4-event-tracker<% end %>"
|
26
26
|
<%= "data-ga4-expandable" if ga4_tracking %>
|
27
27
|
class="gem-c-step-nav js-hidden <% if small %>govuk-!-display-none-print<% end %> <% unless small %>gem-c-step-nav--large<% end %>"
|
28
28
|
<%= "data-remember" if remember_last_step %>
|
@@ -73,7 +73,27 @@
|
|
73
73
|
<% end %>
|
74
74
|
</div>
|
75
75
|
|
76
|
-
|
76
|
+
<%
|
77
|
+
ga4_link_data = {}
|
78
|
+
|
79
|
+
if ga4_tracking
|
80
|
+
ga4_link_data = {
|
81
|
+
"module": "ga4-link-tracker",
|
82
|
+
"ga4-track-links-only": "",
|
83
|
+
"ga4-set-indexes": "",
|
84
|
+
"ga4-link": {
|
85
|
+
"event_name": "navigation",
|
86
|
+
"type": "step by step",
|
87
|
+
"index": {
|
88
|
+
"index_section": step_index + 1
|
89
|
+
},
|
90
|
+
"section": step[:title]
|
91
|
+
}.to_json
|
92
|
+
}
|
93
|
+
end
|
94
|
+
%>
|
95
|
+
|
96
|
+
<%= tag.div(class: "gem-c-step-nav__panel js-panel", id: "step-panel-#{id}-#{step_index + 1}", data: ga4_link_data) do %>
|
77
97
|
<%
|
78
98
|
in_substep = false
|
79
99
|
options[:step_nav_content_id] = step_nav_content_id
|
@@ -91,7 +111,7 @@
|
|
91
111
|
end
|
92
112
|
%>
|
93
113
|
<% end %>
|
94
|
-
|
114
|
+
<% end %>
|
95
115
|
|
96
116
|
</li>
|
97
117
|
<% end %>
|
data/app/views/govuk_publishing_components/components/contextual_sidebar/_ukraine_cta.html.erb
CHANGED
@@ -8,13 +8,19 @@
|
|
8
8
|
<%= tag.div class: "gem-c-contextual-sidebar__cta gem-c-contextual-sidebar__cta--ukraine", data: { module: data_module } do %>
|
9
9
|
<%= tag.h2 title, class: "gem-c-contextual-sidebar__heading govuk-heading-s" %>
|
10
10
|
<%= tag.ul class: "gem-c-contextual-sidebar__list" do %>
|
11
|
+
<% index_total = t("components.related_navigation.ukraine.links").length %>
|
11
12
|
<% t("components.related_navigation.ukraine.links").each_with_index do |link, index| %>
|
12
13
|
<%= tag.li class: "gem-c-contextual-sidebar__text govuk-body" do %>
|
13
14
|
<%
|
14
15
|
ga4_attributes = {
|
15
16
|
event_name: "navigation",
|
16
17
|
type: "related content",
|
17
|
-
index:
|
18
|
+
index: {
|
19
|
+
index_section: "#{ga4_tracking_counts.index_section_count}",
|
20
|
+
index_link: "#{index + 1}",
|
21
|
+
index_section_count: "#{ga4_tracking_counts.index_section_count}",
|
22
|
+
},
|
23
|
+
index_total: "#{index_total}",
|
18
24
|
section: title,
|
19
25
|
} if ga4_tracking
|
20
26
|
%>
|
@@ -6,7 +6,10 @@ body: |
|
|
6
6
|
that would be useful to them. This component would be used to add this personalised content and would
|
7
7
|
indicate to the user that this is not normally part of the page, but has been added for them specifically.
|
8
8
|
|
9
|
-
The dismiss link
|
9
|
+
The dismiss link works without Javascript by pointing to the current URL with the "hide-intervention"
|
10
|
+
query string parameter set to "true". It's progressively enhanced and sets a cookie to remember that
|
11
|
+
the user has dismissed the banner before. The cookie requires a "name" parameter, the value of which
|
12
|
+
is stored in the cookie to distinguish which campaign banner the user has dismissed.
|
10
13
|
|
11
14
|
accessibility_criteria: |
|
12
15
|
The intervention component must:
|
@@ -30,20 +33,20 @@ examples:
|
|
30
33
|
suggestion_link_url: /travel-abroad
|
31
34
|
|
32
35
|
with_dismiss_link:
|
36
|
+
description: |
|
37
|
+
Name is required in order to set a cookie. The name value should be distinct to the campaign for the banner,
|
38
|
+
so that other banners using this component are not hidden by accident.
|
33
39
|
data:
|
34
40
|
suggestion_text: You should renew your permit every 6 months.
|
35
41
|
dismiss_text: Hide this suggestion
|
36
|
-
|
37
|
-
with_suggestion_link_only:
|
38
|
-
data:
|
39
|
-
suggestion_link_text: You can now apply for a permit online.
|
40
|
-
suggestion_link_url: /permit
|
42
|
+
name: campaign-name
|
41
43
|
|
42
44
|
with_hide:
|
43
45
|
description: |
|
44
46
|
This example is for when we want to hide by default and display to the user based on some logic,
|
45
47
|
either in the backend or with Javascript.
|
46
48
|
data:
|
49
|
+
suggestion_text: You should renew your permit every 6 months.
|
47
50
|
suggestion_link_text: You may be invited to fill in a questionnaire
|
48
51
|
suggestion_link_url: /questionnaire
|
49
52
|
hide: true
|
@@ -55,6 +58,7 @@ examples:
|
|
55
58
|
Link text should tell the user that the link opens in a new tab.
|
56
59
|
Note: "(opens in a new tab)" is added to link text if the phrase isn't included.
|
57
60
|
data:
|
61
|
+
suggestion_text: You should renew your permit every 6 months.
|
58
62
|
suggestion_link_text: You can now apply for a permit online
|
59
63
|
suggestion_link_url: www.google.com/permit
|
60
64
|
new_tab: true
|
@@ -76,6 +80,7 @@ examples:
|
|
76
80
|
track-dimension-index: 29
|
77
81
|
track-label: clicked suggestion
|
78
82
|
dismiss_text: Hide this suggestion
|
83
|
+
name: another-campaign-name
|
79
84
|
dismiss_data_attributes:
|
80
85
|
track-category: interventionBanner
|
81
86
|
track-action: interventionDismissed
|
@@ -24,17 +24,23 @@
|
|
24
24
|
<% end %>
|
25
25
|
|
26
26
|
<ul class="gem-c-related-navigation__link-list">
|
27
|
-
<%
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
<%
|
28
|
+
constructed_link_array = []
|
29
|
+
section_link_limit = related_nav_helper.calculate_section_link_limit(links)
|
30
|
+
index_total = links.length
|
31
|
+
%>
|
31
32
|
<% links.each.with_index(1) do |link, index| %>
|
32
33
|
<%
|
33
34
|
link_class = "govuk-link #{related_nav_helper.section_css_class("govuk-link gem-c-related-navigation__section-link", section_title, link: link, link_is_inline: (index >= section_link_limit))}"
|
34
35
|
ga4_attributes = {
|
35
36
|
event_name: "navigation",
|
36
37
|
type: "related content",
|
37
|
-
index:
|
38
|
+
index: {
|
39
|
+
index_section: "#{section_index}",
|
40
|
+
index_link: "#{index}",
|
41
|
+
index_section_count: "#{section_count}",
|
42
|
+
},
|
43
|
+
index_total: "#{index_total}",
|
38
44
|
section: ga4_heading_text,
|
39
45
|
} if ga4_tracking
|
40
46
|
link_element = link_to(
|
@@ -1,11 +1,15 @@
|
|
1
1
|
module GovukPublishingComponents
|
2
2
|
module Presenters
|
3
3
|
class InterventionHelper
|
4
|
-
def initialize(
|
4
|
+
def initialize(options = {})
|
5
|
+
@name = options[:name]
|
6
|
+
@dismiss_text = options[:dismiss_text]
|
5
7
|
@accessible_text_suffix = I18n.t("components.intervention.accessible_link_text_suffix")
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
8
|
+
@params = options[:params]
|
9
|
+
@query_string = options[:query_string]
|
10
|
+
@suggestion_text = options[:suggestion_text]
|
11
|
+
@suggestion_link_text = options[:suggestion_link_text]
|
12
|
+
@suggestion_link_url = options[:suggestion_link_url]
|
9
13
|
end
|
10
14
|
|
11
15
|
def accessible_text
|
@@ -29,9 +33,16 @@ module GovukPublishingComponents
|
|
29
33
|
rel
|
30
34
|
end
|
31
35
|
|
36
|
+
def show?
|
37
|
+
return false if params["hide-intervention"] == "true"
|
38
|
+
return false if @dismiss_text && @name.blank?
|
39
|
+
|
40
|
+
@suggestion_text || (@suggestion_link_text && @suggestion_link_url)
|
41
|
+
end
|
42
|
+
|
32
43
|
private
|
33
44
|
|
34
|
-
attr_reader :accessible_text_suffix, :query_string, :suggestion_link_text, :suggestion_link_url
|
45
|
+
attr_reader :accessible_text_suffix, :query_string, :params, :suggestion_text, :suggestion_link_text, :suggestion_link_url
|
35
46
|
end
|
36
47
|
end
|
37
48
|
end
|
@@ -16,12 +16,16 @@ module GovukPublishingComponents
|
|
16
16
|
"UK Mission to the European Union" => "uk-mission-to-the-eu",
|
17
17
|
}.freeze
|
18
18
|
|
19
|
+
attr_reader :related_navigation, :index_section_count
|
20
|
+
|
19
21
|
def initialize(options = {})
|
20
22
|
@content_item = options.fetch(:content_item) { raise ArgumentError, "missing argument: content_item" }
|
21
23
|
@context = options.fetch(:context, nil)
|
24
|
+
@related_navigation = related_navigation_contents
|
25
|
+
@index_section_count = section_count
|
22
26
|
end
|
23
27
|
|
24
|
-
def
|
28
|
+
def related_navigation_contents
|
25
29
|
case @context.try(:to_sym)
|
26
30
|
when :sidebar
|
27
31
|
{
|
@@ -53,6 +57,10 @@ module GovukPublishingComponents
|
|
53
57
|
end
|
54
58
|
end
|
55
59
|
|
60
|
+
def section_count
|
61
|
+
@related_navigation.select { |_, links| links.any? }.length
|
62
|
+
end
|
63
|
+
|
56
64
|
def construct_section_text(section, underscores_to_spaces)
|
57
65
|
unless section == "related_items"
|
58
66
|
defaults = [I18n.t("components.related_navigation.#{section}")]
|
@@ -46,7 +46,6 @@ module GovukPublishingComponents
|
|
46
46
|
:li,
|
47
47
|
class: "gem-c-step-nav__list-item js-list-item #{link_active(contents[:active])}",
|
48
48
|
) do
|
49
|
-
@options[:ga4_index_total] = element[:contents].length if @options[:ga4_tracking]
|
50
49
|
create_list_item_content(contents)
|
51
50
|
end,
|
52
51
|
)
|
@@ -65,26 +64,11 @@ module GovukPublishingComponents
|
|
65
64
|
concat create_context(link[:context])
|
66
65
|
end
|
67
66
|
|
68
|
-
ga4_link_data ||= nil
|
69
|
-
if @options[:ga4_tracking]
|
70
|
-
ga4_link_data = {
|
71
|
-
"event_name": "navigation",
|
72
|
-
"type": "step by step",
|
73
|
-
"index": {
|
74
|
-
"index_section": (@options[:step_index] + 1).to_s,
|
75
|
-
"index_link": @link_index.to_s,
|
76
|
-
},
|
77
|
-
"index_total": @options[:ga4_index_total].to_s,
|
78
|
-
"section": @options[:step_title],
|
79
|
-
}.to_json
|
80
|
-
end
|
81
|
-
|
82
67
|
link_to(
|
83
68
|
href,
|
84
69
|
rel: ("external" if href.start_with?("http")),
|
85
70
|
data: {
|
86
71
|
position: "#{@options[:step_index] + 1}.#{@link_index}",
|
87
|
-
ga4_link: ga4_link_data,
|
88
72
|
},
|
89
73
|
class: "gem-c-step-nav__link js-link",
|
90
74
|
) do
|
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: 35.
|
4
|
+
version: 35.3.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: 2023-
|
11
|
+
date: 2023-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_app_config
|
@@ -484,6 +484,7 @@ files:
|
|
484
484
|
- app/assets/javascripts/govuk_publishing_components/components/feedback.js
|
485
485
|
- app/assets/javascripts/govuk_publishing_components/components/govspeak.js
|
486
486
|
- app/assets/javascripts/govuk_publishing_components/components/image-card.js
|
487
|
+
- app/assets/javascripts/govuk_publishing_components/components/intervention.js
|
487
488
|
- app/assets/javascripts/govuk_publishing_components/components/layout-header.js
|
488
489
|
- app/assets/javascripts/govuk_publishing_components/components/layout-super-navigation-header.js
|
489
490
|
- app/assets/javascripts/govuk_publishing_components/components/metadata.js
|
@@ -1415,7 +1416,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1415
1416
|
- !ruby/object:Gem::Version
|
1416
1417
|
version: '0'
|
1417
1418
|
requirements: []
|
1418
|
-
rubygems_version: 3.4.
|
1419
|
+
rubygems_version: 3.4.12
|
1419
1420
|
signing_key:
|
1420
1421
|
specification_version: 4
|
1421
1422
|
summary: A gem to document components in GOV.UK frontend applications
|