govuk_publishing_components 29.1.0 → 29.2.0
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/govuk_publishing_components/analytics/analytics.js +1 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +11 -0
- data/app/assets/javascripts/govuk_publishing_components/components/accordion.js +45 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_accordion.scss +5 -0
- data/app/views/govuk_publishing_components/components/_accordion.html.erb +4 -0
- data/app/views/govuk_publishing_components/components/_cards.html.erb +6 -3
- data/app/views/govuk_publishing_components/components/docs/accordion.yml +34 -0
- data/lib/govuk_publishing_components/presenters/attachment.rb +1 -2
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +36 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 966bb67ed287fd8f755238732b57bacee7913faa29effa54f69a64c3f7dae03f
|
4
|
+
data.tar.gz: 84876bd7eec64af2b9b514f4da5b075dd220bcd2566903eff1c1130ddb05f039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e994cd04b7a498b550c83d276cb71fbdc4983180b3cdebe6bb92e04a5dc6adf5fa7f9b8043c451063f433d1e3d28517746374937158409631e6405d3d64a179
|
7
|
+
data.tar.gz: 91905f09481b56158cef17108e3a3d86c0de65ad8e05e6d1c3af29925ce06fee38b6e0cbaad21db7f20fe867644dd91c7daca1db1a1fcfbe74aa56dc36ddec12
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
var GOVUK = global.GOVUK || {}
|
5
5
|
// For usage and initialisation see:
|
6
|
-
// https://github.com/alphagov/
|
6
|
+
// https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics/analytics.md
|
7
7
|
|
8
8
|
var Analytics = function (config) {
|
9
9
|
this.pii = new GOVUK.Pii()
|
@@ -13,6 +13,8 @@
|
|
13
13
|
return document.querySelectorAll('[data-track-count="accordionSection"]').length
|
14
14
|
case isDocumentCollectionPage():
|
15
15
|
return document.querySelectorAll('.document-collection .group-title').length
|
16
|
+
case isNewBrowsePage():
|
17
|
+
return document.querySelectorAll('[data-track-count="cardList"]').length
|
16
18
|
case isMainstreamBrowsePage():
|
17
19
|
return countVisible(document.querySelectorAll('#subsection ul')) || document.querySelectorAll('#section ul').length || document.querySelectorAll('#root ul').length
|
18
20
|
case isTopicPage():
|
@@ -44,6 +46,8 @@
|
|
44
46
|
return document.querySelectorAll('a[data-track-category="navAccordionLinkClicked"]').length
|
45
47
|
case isDocumentCollectionPage():
|
46
48
|
return document.querySelectorAll('.document-collection .group-document-list li a').length
|
49
|
+
case isNewBrowsePage():
|
50
|
+
return document.querySelectorAll('[data-track-count="cardLink"]').length
|
47
51
|
case isMainstreamBrowsePage():
|
48
52
|
return countVisible(document.querySelectorAll('#subsection ul a')) || document.querySelectorAll('#section ul a').length || document.querySelectorAll('#root ul a').length
|
49
53
|
case isTopicPage():
|
@@ -67,6 +71,7 @@
|
|
67
71
|
var metaApplicationSelector = 'meta[name="govuk:rendering-application"]'
|
68
72
|
var metaFormatSelector = 'meta[name="govuk:format"]'
|
69
73
|
var metaNavigationTypeSelector = 'meta[name="govuk:navigation-page-type"]'
|
74
|
+
var metaSectionSelector = 'meta[name="govuk:section"]'
|
70
75
|
|
71
76
|
function getMetaAttribute (selector) {
|
72
77
|
var element = document.querySelector(selector)
|
@@ -93,6 +98,12 @@
|
|
93
98
|
getMetaAttribute(metaNavigationTypeSelector) === 'leaf'
|
94
99
|
}
|
95
100
|
|
101
|
+
function isNewBrowsePage () {
|
102
|
+
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
103
|
+
getMetaAttribute(metaSectionSelector) === 'new_browse_page' &&
|
104
|
+
getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
|
105
|
+
}
|
106
|
+
|
96
107
|
function isMainstreamBrowsePage () {
|
97
108
|
return getMetaAttribute(metaApplicationSelector) === 'collections' &&
|
98
109
|
getMetaAttribute(metaFormatSelector) === 'mainstream_browse_page'
|
@@ -13,6 +13,9 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
|
|
13
13
|
this.sectionClassExpanded = 'govuk-accordion__section--expanded'
|
14
14
|
this.sectionHeaderClass = 'govuk-accordion__section-header'
|
15
15
|
this.sectionInnerContent = 'govuk-accordion__section-content'
|
16
|
+
this.showAllControls = 'govuk-accordion__show-all'
|
17
|
+
this.sectionButton = 'govuk-accordion__section-button'
|
18
|
+
this.headingText = 'govuk-accordion__section-heading-text'
|
16
19
|
|
17
20
|
// Translated component content and language attribute pulled from data attributes
|
18
21
|
this.$module.actions = {}
|
@@ -27,12 +30,21 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
|
|
27
30
|
GemAccordion.prototype.init = function () {
|
28
31
|
// Indicate that JavaScript has worked
|
29
32
|
this.$module.classList.add('gem-c-accordion--active')
|
33
|
+
this.$module.querySelector('.' + this.showAllControls).classList.add('gem-c-accordion__show-all')
|
30
34
|
|
31
35
|
// Feature flag for anchor tag navigation used on manuals
|
32
36
|
if (this.$module.getAttribute('data-anchor-navigation') === 'true') {
|
33
37
|
this.openByAnchorOnLoad()
|
34
38
|
this.addEventListenersForAnchors()
|
35
39
|
}
|
40
|
+
// Feature flag for "Show all sections" GA click event tracking
|
41
|
+
if (this.$module.getAttribute('data-track-show-all-clicks') === 'true') {
|
42
|
+
this.addAccordionOpenAllTracking()
|
43
|
+
}
|
44
|
+
// Feature flag for each section GA click event tracking
|
45
|
+
if (this.$module.getAttribute('data-track-sections') === 'true') {
|
46
|
+
this.addEventListenerSections()
|
47
|
+
}
|
36
48
|
}
|
37
49
|
|
38
50
|
// Navigate to and open accordions with anchored content on page load if a hash is present
|
@@ -90,5 +102,38 @@ window.GOVUK.Modules.GovukAccordion = window.GOVUKFrontend.Accordion;
|
|
90
102
|
}
|
91
103
|
}
|
92
104
|
|
105
|
+
// To track the Accordion's "Show all sections" / "Hide all sections" button click events and pass them to the GA event tracking
|
106
|
+
GemAccordion.prototype.addAccordionOpenAllTracking = function () {
|
107
|
+
this.$module.querySelector('.' + this.showAllControls).addEventListener('click', function (event) {
|
108
|
+
var expanded = event.target.getAttribute('aria-expanded') === 'true'
|
109
|
+
var label = expanded ? 'Show all sections' : 'Hide all sections'
|
110
|
+
var action = expanded ? 'accordionOpened' : 'accordionClosed'
|
111
|
+
var options = { transport: 'beacon', label: label }
|
112
|
+
if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
|
113
|
+
window.GOVUK.analytics.trackEvent('pageElementInteraction', action, options)
|
114
|
+
}
|
115
|
+
})
|
116
|
+
}
|
117
|
+
|
118
|
+
GemAccordion.prototype.addEventListenerSections = function () {
|
119
|
+
var sections = this.$module.querySelectorAll('.' + this.sectionButton)
|
120
|
+
nodeListForEach(sections, function (section) {
|
121
|
+
section.addEventListener('click', this.addAccordionSectionTracking.bind(this, section))
|
122
|
+
}.bind(this))
|
123
|
+
}
|
124
|
+
|
125
|
+
// If the Accordion's sections are opened on click, then pass them to the GA event tracking
|
126
|
+
GemAccordion.prototype.addAccordionSectionTracking = function (section) {
|
127
|
+
var expanded = section.getAttribute('aria-expanded') === 'false'
|
128
|
+
var label = section.querySelector('.' + this.headingText).textContent
|
129
|
+
var action = expanded ? 'accordionOpened' : 'accordionClosed'
|
130
|
+
var options = { transport: 'beacon', label: label }
|
131
|
+
|
132
|
+
if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
|
133
|
+
window.GOVUK.analytics.trackEvent('pageElementInteraction', action, options)
|
134
|
+
console.log('pageElementInteraction', action, options)
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
93
138
|
Modules.GemAccordion = GemAccordion
|
94
139
|
})(window.GOVUK.Modules)
|
@@ -5,6 +5,8 @@
|
|
5
5
|
id ||= "default-id-#{SecureRandom.hex(4)}"
|
6
6
|
items ||= []
|
7
7
|
anchor_navigation ||= false
|
8
|
+
track_show_all_clicks ||= false
|
9
|
+
track_sections ||= false
|
8
10
|
|
9
11
|
accordion_classes = %w(gem-c-accordion govuk-accordion)
|
10
12
|
accordion_classes << (shared_helper.get_margin_bottom)
|
@@ -22,6 +24,8 @@
|
|
22
24
|
data_attributes ||= {}
|
23
25
|
data_attributes[:module] = 'govuk-accordion gem-accordion'
|
24
26
|
data_attributes[:anchor_navigation] = anchor_navigation
|
27
|
+
data_attributes[:track_show_all_clicks] = track_show_all_clicks
|
28
|
+
data_attributes[:track_sections] = track_sections
|
25
29
|
|
26
30
|
translations.each do |key, translation|
|
27
31
|
locales[key] = shared_helper.t_locale(translation)
|
@@ -18,8 +18,10 @@
|
|
18
18
|
<%= heading %>
|
19
19
|
<% end %>
|
20
20
|
<% end %>
|
21
|
-
|
22
|
-
|
21
|
+
<%# data-track-count is used for analytics purposes in
|
22
|
+
https://github.com/alphagov/govuk_publishing_components/blob/main/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js
|
23
|
+
%>
|
24
|
+
<%= content_tag('ul', class: ul_classes, "data-track-count": "cardList" ) do %>
|
23
25
|
<%
|
24
26
|
items.each do |item|
|
25
27
|
link = item[:link]
|
@@ -33,7 +35,8 @@
|
|
33
35
|
<%=
|
34
36
|
link_to link[:text], link[:path],
|
35
37
|
class: "govuk-link gem-c-cards__link",
|
36
|
-
data: link[:data_attributes]
|
38
|
+
data: link[:data_attributes],
|
39
|
+
"data-track-count": "cardLink"
|
37
40
|
%>
|
38
41
|
<% end %>
|
39
42
|
<% if item[:description] %>
|
@@ -309,3 +309,37 @@ examples:
|
|
309
309
|
text: How people read
|
310
310
|
content:
|
311
311
|
html: <p class="govuk-body">This is the content for How people read.</p>
|
312
|
+
with_track_show_all_clicks:
|
313
|
+
description: |
|
314
|
+
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`
|
316
|
+
data:
|
317
|
+
track_show_all_clicks: true
|
318
|
+
items:
|
319
|
+
- heading:
|
320
|
+
text: Writing well for the web
|
321
|
+
id: writing-well-for-the-web
|
322
|
+
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>
|
324
|
+
- heading:
|
325
|
+
text: Writing well for specialists
|
326
|
+
content:
|
327
|
+
html: <p class="govuk-body" id="anchor-nav-test">This is content for accordion 2 of 2</p>
|
328
|
+
with_track_sections:
|
329
|
+
description: |
|
330
|
+
To switch on Google Analytics for each section, on click, pass `track_sections: true` the values passed on open will be
|
331
|
+
`Event Action: accordionOpened` / `accordionClosed` `Event Category: pageElementInteraction` and the `Event Label` being the heading text.
|
332
|
+
|
333
|
+
(`track_show_all_clicks: true` can be added to track the "Show all sections" button as well, if required)
|
334
|
+
data:
|
335
|
+
track_sections: true
|
336
|
+
items:
|
337
|
+
- heading:
|
338
|
+
text: Writing well for the web
|
339
|
+
id: writing-well-for-the-web
|
340
|
+
content:
|
341
|
+
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
|
+
- heading:
|
343
|
+
text: Writing well for specialists
|
344
|
+
content:
|
345
|
+
html: <p class="govuk-body" id="anchor-nav-test">This is content for accordion 2 of 2</p>
|
@@ -5,8 +5,7 @@ module GovukPublishingComponents
|
|
5
5
|
# rather than direct email for users to request accessible formats. When the pilot
|
6
6
|
# scheme is rolled out further this can be removed.
|
7
7
|
# Currently the HMRC are participating in the pilot.
|
8
|
-
EMAILS_IN_ACCESSIBLE_FORMAT_REQUEST_PILOT = %w[govuk_publishing_components@example.com
|
9
|
-
different.format@hmrc.gov.uk].freeze
|
8
|
+
EMAILS_IN_ACCESSIBLE_FORMAT_REQUEST_PILOT = %w[govuk_publishing_components@example.com].freeze
|
10
9
|
|
11
10
|
delegate :opendocument?, :document?, :spreadsheet?, to: :content_type
|
12
11
|
|
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.
|
4
|
+
version: 29.2.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-
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govuk_app_config
|
@@ -112,30 +112,30 @@ dependencies:
|
|
112
112
|
name: capybara
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: faker
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
131
|
+
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
138
|
+
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: gds-api-adapters
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,30 +154,30 @@ dependencies:
|
|
154
154
|
name: govuk_schemas
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- - "
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- - "
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: govuk_test
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
173
|
+
version: '0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
180
|
+
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: i18n-coverage
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -196,16 +196,16 @@ dependencies:
|
|
196
196
|
name: percy-capybara
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- - "
|
199
|
+
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
201
|
+
version: '0'
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- - "
|
206
|
+
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
208
|
+
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: pry-byebug
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -226,14 +226,14 @@ dependencies:
|
|
226
226
|
requirements:
|
227
227
|
- - ">="
|
228
228
|
- !ruby/object:Gem::Version
|
229
|
-
version: '
|
229
|
+
version: '0'
|
230
230
|
type: :development
|
231
231
|
prerelease: false
|
232
232
|
version_requirements: !ruby/object:Gem::Requirement
|
233
233
|
requirements:
|
234
234
|
- - ">="
|
235
235
|
- !ruby/object:Gem::Version
|
236
|
-
version: '
|
236
|
+
version: '0'
|
237
237
|
- !ruby/object:Gem::Dependency
|
238
238
|
name: rake
|
239
239
|
requirement: !ruby/object:Gem::Requirement
|
@@ -252,16 +252,16 @@ dependencies:
|
|
252
252
|
name: rspec-rails
|
253
253
|
requirement: !ruby/object:Gem::Requirement
|
254
254
|
requirements:
|
255
|
-
- - "
|
255
|
+
- - ">="
|
256
256
|
- !ruby/object:Gem::Version
|
257
|
-
version: '
|
257
|
+
version: '0'
|
258
258
|
type: :development
|
259
259
|
prerelease: false
|
260
260
|
version_requirements: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
|
-
- - "
|
262
|
+
- - ">="
|
263
263
|
- !ruby/object:Gem::Version
|
264
|
-
version: '
|
264
|
+
version: '0'
|
265
265
|
- !ruby/object:Gem::Dependency
|
266
266
|
name: rubocop-govuk
|
267
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -280,44 +280,44 @@ dependencies:
|
|
280
280
|
name: sassc-rails
|
281
281
|
requirement: !ruby/object:Gem::Requirement
|
282
282
|
requirements:
|
283
|
-
- - "
|
283
|
+
- - ">="
|
284
284
|
- !ruby/object:Gem::Version
|
285
|
-
version: '
|
285
|
+
version: '0'
|
286
286
|
type: :development
|
287
287
|
prerelease: false
|
288
288
|
version_requirements: !ruby/object:Gem::Requirement
|
289
289
|
requirements:
|
290
|
-
- - "
|
290
|
+
- - ">="
|
291
291
|
- !ruby/object:Gem::Version
|
292
|
-
version: '
|
292
|
+
version: '0'
|
293
293
|
- !ruby/object:Gem::Dependency
|
294
294
|
name: uglifier
|
295
295
|
requirement: !ruby/object:Gem::Requirement
|
296
296
|
requirements:
|
297
297
|
- - ">="
|
298
298
|
- !ruby/object:Gem::Version
|
299
|
-
version:
|
299
|
+
version: '0'
|
300
300
|
type: :development
|
301
301
|
prerelease: false
|
302
302
|
version_requirements: !ruby/object:Gem::Requirement
|
303
303
|
requirements:
|
304
304
|
- - ">="
|
305
305
|
- !ruby/object:Gem::Version
|
306
|
-
version:
|
306
|
+
version: '0'
|
307
307
|
- !ruby/object:Gem::Dependency
|
308
308
|
name: webmock
|
309
309
|
requirement: !ruby/object:Gem::Requirement
|
310
310
|
requirements:
|
311
|
-
- - "
|
311
|
+
- - ">="
|
312
312
|
- !ruby/object:Gem::Version
|
313
|
-
version:
|
313
|
+
version: '0'
|
314
314
|
type: :development
|
315
315
|
prerelease: false
|
316
316
|
version_requirements: !ruby/object:Gem::Requirement
|
317
317
|
requirements:
|
318
|
-
- - "
|
318
|
+
- - ">="
|
319
319
|
- !ruby/object:Gem::Version
|
320
|
-
version:
|
320
|
+
version: '0'
|
321
321
|
- !ruby/object:Gem::Dependency
|
322
322
|
name: yard
|
323
323
|
requirement: !ruby/object:Gem::Requirement
|