govuk_publishing_components 29.15.3 → 30.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{gtm-click-tracking.js → ga4-event-tracker.js} +20 -7
  3. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js +153 -0
  4. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{gtm-page-views.js → ga4-page-views.js} +23 -7
  5. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/{gtm-schemas.js → ga4-schemas.js} +3 -2
  6. data/app/assets/javascripts/govuk_publishing_components/analytics-ga4.js +6 -4
  7. data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -0
  8. data/app/assets/stylesheets/govuk_publishing_components/_all_components_print.scss +1 -0
  9. data/app/assets/stylesheets/govuk_publishing_components/components/_emergency-banner.scss +76 -0
  10. data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_typography.scss +0 -8
  11. data/app/assets/stylesheets/govuk_publishing_components/components/print/_emergency-banner.scss +3 -0
  12. data/app/models/govuk_publishing_components/audit_applications.rb +1 -1
  13. data/app/views/govuk_publishing_components/component_guide/example.html.erb +5 -1
  14. data/app/views/govuk_publishing_components/component_guide/show.html.erb +4 -1
  15. data/app/views/govuk_publishing_components/components/_accordion.html.erb +1 -1
  16. data/app/views/govuk_publishing_components/components/_emergency_banner.html.erb +51 -0
  17. data/app/views/govuk_publishing_components/components/_print_link.html.erb +1 -1
  18. data/app/views/govuk_publishing_components/components/docs/accordion.yml +24 -11
  19. data/app/views/govuk_publishing_components/components/docs/emergency_banner.yml +45 -0
  20. data/app/views/govuk_publishing_components/components/docs/print_link.yml +5 -0
  21. data/config/locales/hr.yml +0 -1
  22. data/lib/govuk_publishing_components/presenters/emergency_banner_helper.rb +17 -0
  23. data/lib/govuk_publishing_components/version.rb +1 -1
  24. data/lib/govuk_publishing_components.rb +1 -0
  25. metadata +12 -7
  26. data/app/assets/javascripts/govuk_publishing_components/lib/primary-links.js +0 -74
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1093c2ff6d40fae820a8b90e7a349d7e8dd78b10fca660453365343d7968749c
4
- data.tar.gz: 3607d6e31004a9697a60a6c7075124b085b2c7a592c6f159e9540fa9ed7c0ad6
3
+ metadata.gz: 4aee02160c93679a75c8418c7b1f0da2ed3908a6016f4437f06dfa0091b61096
4
+ data.tar.gz: 629859a537593a4f5547cbfa45e866bde739b616ef0598f2428ea07bc0f0af26
5
5
  SHA512:
6
- metadata.gz: 126afbff6dcbcab4a12c6551ab3546c2727841a9454df9a2eafae820bf8dcb483ad578b041e3250f085b3ba34534eabbb80727715f706391fdc2530d975da97a
7
- data.tar.gz: ea8bdcc6c1f05fc3f469de5fe182ff304ea58e228ad9caf8c89ecf8f66cc8ad8c279a5ff4d5556f09fbed75f88cd5cbd5cc46c21afc2dd1249befcbe16af8dd6
6
+ metadata.gz: 043a2bed5b586217a53aea43f53b9a43219b6f8947aaa90776d00a86ebb1f78c410131085401a2b0802a450426d85be2e22f986447e9e99c4d2afee76f95cbbb
7
+ data.tar.gz: a52358d241fd9539a21fd7cb47c4d54fd2e402e0441758ec7348eb9b14c64444cfeaca9c54e03c34e8051c10bcac4c7c0f00999898f3586b5007f320ba9a5d86
@@ -5,16 +5,16 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
5
5
  (function (Modules) {
6
6
  'use strict'
7
7
 
8
- function GtmClickTracking (module) {
8
+ function GA4EventTracker (module) {
9
9
  this.module = module
10
10
  this.trackingTrigger = 'data-ga4' // elements with this attribute get tracked
11
11
  }
12
12
 
13
- GtmClickTracking.prototype.init = function () {
13
+ GA4EventTracker.prototype.init = function () {
14
14
  this.module.addEventListener('click', this.trackClick.bind(this), true) // useCapture must be true
15
15
  }
16
16
 
17
- GtmClickTracking.prototype.trackClick = function (event) {
17
+ GA4EventTracker.prototype.trackClick = function (event) {
18
18
  if (window.dataLayer) {
19
19
  var target = this.findTrackingAttributes(event.target)
20
20
  if (target) {
@@ -33,7 +33,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
33
33
  // get attributes from the data attribute to send to GA
34
34
  // only allow it if it already exists in the schema
35
35
  for (var property in data) {
36
- if (schema.event_data[property]) {
36
+ if (property in schema.event_data) {
37
37
  schema.event_data[property] = data[property]
38
38
  }
39
39
  }
@@ -58,12 +58,25 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
58
58
  var openAttribute = detailsElement.getAttribute('open')
59
59
  schema.event_data.action = (openAttribute == null) ? 'opened' : 'closed'
60
60
  }
61
+
62
+ /* If a tab was clicked, grab the href of the clicked tab (usually an anchor # link) */
63
+ var tabElement = event.target.closest('.gem-c-tabs')
64
+ if (tabElement) {
65
+ var aTag = event.target.closest('a')
66
+ if (aTag) {
67
+ var href = aTag.getAttribute('href')
68
+ if (href) {
69
+ schema.event_data.url = href
70
+ }
71
+ }
72
+ }
73
+
61
74
  window.dataLayer.push(schema)
62
75
  }
63
76
  }
64
77
  }
65
78
 
66
- GtmClickTracking.prototype.findTrackingAttributes = function (clicked) {
79
+ GA4EventTracker.prototype.findTrackingAttributes = function (clicked) {
67
80
  if (clicked.hasAttribute('[' + this.trackingTrigger + ']')) {
68
81
  return clicked
69
82
  } else {
@@ -72,7 +85,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
72
85
  }
73
86
 
74
87
  // check if an attribute exists or contains the attribute
75
- GtmClickTracking.prototype.getClosestAttribute = function (clicked, attribute) {
88
+ GA4EventTracker.prototype.getClosestAttribute = function (clicked, attribute) {
76
89
  var isAttributeOnElement = clicked.getAttribute(attribute)
77
90
  var containsAttribute = clicked.querySelector('[' + attribute + ']')
78
91
 
@@ -83,5 +96,5 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
83
96
  }
84
97
  }
85
98
 
86
- Modules.GtmClickTracking = GtmClickTracking
99
+ Modules.GA4EventTracker = GA4EventTracker
87
100
  })(window.GOVUK.Modules)
@@ -0,0 +1,153 @@
1
+ // = require govuk/vendor/polyfills/Element/prototype/closest.js
2
+
3
+ ;(function (global) {
4
+ 'use strict'
5
+
6
+ var GOVUK = global.GOVUK || {}
7
+ GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}
8
+
9
+ GOVUK.analyticsGA4.linkTracker = {
10
+ trackLinkClicks: function () {
11
+ if (window.dataLayer) {
12
+ this.internalLinksDomain = 'www.gov.uk/'
13
+ this.internalLinksDomainWithoutWww = 'gov.uk/'
14
+ this.handleClick = this.handleClick.bind(this)
15
+ this.handleMousedown = this.handleMousedown.bind(this)
16
+ document.querySelector('body').addEventListener('click', this.handleClick)
17
+ document.querySelector('body').addEventListener('contextmenu', this.handleClick)
18
+ document.querySelector('body').addEventListener('mousedown', this.handleMousedown)
19
+ }
20
+ },
21
+
22
+ stopTracking: function () {
23
+ document.querySelector('body').removeEventListener('click', this.handleClick)
24
+ document.querySelector('body').removeEventListener('contextmenu', this.handleClick)
25
+ document.querySelector('body').removeEventListener('mousedown', this.handleMousedown)
26
+ },
27
+
28
+ handleClick: function (event) {
29
+ var element = event.target
30
+
31
+ if (element.tagName !== 'A') {
32
+ element = element.closest('a')
33
+ }
34
+
35
+ if (!element) {
36
+ return
37
+ }
38
+
39
+ var clickData = {}
40
+ var href = element.getAttribute('href')
41
+
42
+ if (!href) {
43
+ return
44
+ }
45
+
46
+ if (this.isMailToLink(href)) {
47
+ clickData.type = 'email'
48
+ clickData.external = 'true'
49
+ } else if (this.isDownloadLink(href)) {
50
+ clickData.type = 'download'
51
+ clickData.external = 'false'
52
+ } else if (this.isExternalLink(href)) {
53
+ clickData.type = 'generic link'
54
+ clickData.external = 'true'
55
+ }
56
+
57
+ if (Object.keys(clickData).length > 0) {
58
+ clickData.event_name = 'navigation'
59
+ clickData.text = element.textContent.trim()
60
+ clickData.url = href
61
+ clickData.link_method = this.getClickType(event)
62
+
63
+ var schema = new window.GOVUK.analyticsGA4.Schemas().eventSchema()
64
+ schema.event = 'analytics'
65
+
66
+ // get attributes from the clickData object to send to GA
67
+ // only allow it if it already exists in the schema
68
+ for (var property in clickData) {
69
+ if (property in schema.event_data) {
70
+ schema.event_data[property] = clickData[property]
71
+ }
72
+ }
73
+
74
+ window.dataLayer.push(schema)
75
+ }
76
+ },
77
+
78
+ getClickType: function (event) {
79
+ switch (event.type) {
80
+ case 'click':
81
+ if (event.ctrlKey) {
82
+ return 'ctrl click'
83
+ } else if (event.metaKey) {
84
+ return 'command/win click'
85
+ } else {
86
+ return 'primary click'
87
+ }
88
+ case 'mousedown':
89
+ return 'middle click'
90
+ case 'contextmenu':
91
+ return 'secondary click'
92
+ }
93
+ },
94
+
95
+ handleMousedown: function (event) {
96
+ // 1 = middle mouse button
97
+ if (event.button === 1) {
98
+ this.handleClick(event)
99
+ }
100
+ },
101
+
102
+ isMailToLink: function (href) {
103
+ return href.substring(0, 7) === 'mailto:'
104
+ },
105
+
106
+ isDownloadLink: function (href) {
107
+ var assetsDomain = 'assets.publishing.service.gov.uk/'
108
+ var uploadsPath = '/government/uploads/'
109
+
110
+ if (this.hrefPointsToDomain(href, assetsDomain)) {
111
+ return true
112
+ }
113
+
114
+ var isInternalLink = this.hrefPointsToDomain(href, this.internalLinksDomain) || this.hrefPointsToDomain(href, this.internalLinksDomainWithoutWww)
115
+ if (isInternalLink && href.indexOf(uploadsPath) !== -1) {
116
+ return true
117
+ }
118
+
119
+ // Checks relative links to the uploadsPath
120
+ if (this.stringStartsWith(href, uploadsPath)) {
121
+ return true
122
+ }
123
+ },
124
+
125
+ isExternalLink: function (href) {
126
+ var isInternalLink = this.hrefPointsToDomain(href, this.internalLinksDomain) || this.hrefPointsToDomain(href, this.internalLinksDomainWithoutWww)
127
+ if (!isInternalLink && !this.hrefIsRelative(href)) {
128
+ return true
129
+ }
130
+ },
131
+
132
+ hrefPointsToDomain: function (href, domain) {
133
+ var httpDomain = 'http://' + domain
134
+ var httpsDomain = 'https://' + domain
135
+ var schemaRelativeDomain = '//' + domain
136
+ return this.stringStartsWith(href, domain) ||
137
+ this.stringStartsWith(href, httpDomain) ||
138
+ this.stringStartsWith(href, httpsDomain) ||
139
+ this.stringStartsWith(href, schemaRelativeDomain)
140
+ },
141
+
142
+ stringStartsWith: function (string, stringToFind) {
143
+ return string.substring(0, stringToFind.length) === stringToFind
144
+ },
145
+
146
+ hrefIsRelative: function (href) {
147
+ // Checks that a link is relative, but is not a protocol relative url
148
+ return href[0] === '/' && href[1] !== '/'
149
+ }
150
+ }
151
+
152
+ global.GOVUK = GOVUK
153
+ })(window)
@@ -2,9 +2,11 @@
2
2
  'use strict'
3
3
 
4
4
  var GOVUK = global.GOVUK || {}
5
+ GOVUK.analyticsGA4 = GOVUK.analyticsGA4 || {}
5
6
 
6
- GOVUK.Gtm = {
7
+ GOVUK.analyticsGA4.pageViewTracker = {
7
8
  PIIRemover: new GOVUK.analyticsGA4.PIIRemover(), // imported in analytics-ga4.js
9
+ nullValue: null,
8
10
 
9
11
  sendPageView: function () {
10
12
  if (window.dataLayer) {
@@ -32,9 +34,9 @@
32
34
  language: this.getLanguage(),
33
35
  history: this.getHistory(),
34
36
  withdrawn: this.getWithDrawn(),
35
- first_published_at: this.getMetaContent('first-published-at'),
36
- updated_at: this.getMetaContent('updated-at'),
37
- public_updated_at: this.getMetaContent('public-updated-at'),
37
+ first_published_at: this.stripTimeFrom(this.getMetaContent('first-published-at')),
38
+ updated_at: this.stripTimeFrom(this.getMetaContent('updated-at')),
39
+ public_updated_at: this.stripTimeFrom(this.getMetaContent('public-updated-at')),
38
40
  publishing_government: this.getMetaContent('publishing-government'),
39
41
  political_status: this.getMetaContent('political-status'),
40
42
  primary_publishing_organisation: this.getMetaContent('primary-publishing-organisation'),
@@ -73,13 +75,17 @@
73
75
  if (tag) {
74
76
  return tag.getAttribute('content')
75
77
  } else {
76
- return 'n/a'
78
+ return this.nullValue
77
79
  }
78
80
  },
79
81
 
80
82
  getLanguage: function () {
81
- var html = document.querySelector('html')
82
- return html.getAttribute('lang') || 'n/a'
83
+ var content = document.getElementById('content')
84
+ if (content) {
85
+ return content.getAttribute('lang') || this.nullValue
86
+ } else {
87
+ return this.nullValue
88
+ }
83
89
  },
84
90
 
85
91
  getHistory: function () {
@@ -90,6 +96,16 @@
90
96
  getWithDrawn: function () {
91
97
  var withdrawn = this.getMetaContent('withdrawn')
92
98
  return (withdrawn === 'withdrawn') ? 'true' : 'false'
99
+ },
100
+
101
+ // return only the date from given timestamps of the form
102
+ // 2022-03-28T19:11:00.000+00:00
103
+ stripTimeFrom: function (value) {
104
+ if (value !== null) {
105
+ return value.split('T')[0]
106
+ } else {
107
+ return this.nullValue
108
+ }
93
109
  }
94
110
  }
95
111
 
@@ -4,7 +4,7 @@
4
4
  var GOVUK = global.GOVUK || {}
5
5
 
6
6
  var Schemas = function () {
7
- this.null = 'n/a'
7
+ this.null = null
8
8
  }
9
9
 
10
10
  Schemas.prototype.eventSchema = function () {
@@ -20,7 +20,8 @@
20
20
  index_total: this.null,
21
21
  section: this.null,
22
22
  action: this.null,
23
- external: this.null
23
+ external: this.null,
24
+ link_method: this.null
24
25
  }
25
26
  }
26
27
  }
@@ -1,7 +1,9 @@
1
1
  // The following modules are imported in a specific order
2
- //= require ./analytics-ga4/gtm-schemas
2
+ //= require ./analytics-ga4/ga4-schemas
3
3
  //= require ./analytics-ga4/pii-remover
4
- //= require ./analytics-ga4/gtm-page-views
5
- //= require ./analytics-ga4/gtm-click-tracking
4
+ //= require ./analytics-ga4/ga4-page-views
5
+ //= require ./analytics-ga4/ga4-link-tracker
6
+ //= require ./analytics-ga4/ga4-event-tracker
6
7
 
7
- window.GOVUK.Gtm.sendPageView() // this will need integrating with cookie consent before production
8
+ window.GOVUK.analyticsGA4.pageViewTracker.sendPageView() // this will need integrating with cookie consent before production
9
+ window.GOVUK.analyticsGA4.linkTracker.trackLinkClicks()
@@ -31,6 +31,7 @@ $govuk-new-link-styles: true;
31
31
  @import "components/details";
32
32
  @import "components/devolved-nations";
33
33
  @import "components/document-list";
34
+ @import "components/emergency-banner";
34
35
  @import "components/error-alert";
35
36
  @import "components/error-message";
36
37
  @import "components/error-summary";
@@ -7,6 +7,7 @@
7
7
  @import "components/print/button";
8
8
  @import "components/print/cards";
9
9
  @import "components/print/contents-list";
10
+ @import "components/print/emergency-banner";
10
11
  @import "components/print/govspeak-html-publication";
11
12
  @import "components/print/govspeak";
12
13
  @import "components/print/layout-super-navigation-header";
@@ -0,0 +1,76 @@
1
+ .gem-c-emergency-banner {
2
+ @include govuk-font(19);
3
+ background-color: govuk-colour("mid-grey");
4
+ color: govuk-colour("white");
5
+ margin-top: 2px;
6
+ padding: govuk-spacing(3) 0;
7
+
8
+ @include govuk-media-query($from: tablet) {
9
+ padding: govuk-spacing(6) 0;
10
+ }
11
+ }
12
+
13
+ .gem-c-emergency-banner--homepage {
14
+ border-bottom: govuk-spacing(1) solid govuk-colour("white");
15
+ border-top: govuk-spacing(1) solid govuk-colour("white");
16
+ margin-bottom: govuk-spacing(-2);
17
+ margin-top: 0;
18
+ position: relative;
19
+ z-index: 10;
20
+ }
21
+
22
+ .gem-c-emergency-banner__heading {
23
+ @include govuk-font(24, $weight: bold);
24
+ margin: 0;
25
+ }
26
+
27
+ .gem-c-emergency-banner__heading--homepage {
28
+ @include govuk-font(48, $weight: bold);
29
+
30
+ @include govuk-media-query($from: tablet) {
31
+ margin-bottom: govuk-spacing(4);
32
+ }
33
+ }
34
+
35
+ .gem-c-emergency-banner__description {
36
+ @include govuk-font(19);
37
+ color: govuk-colour("white");
38
+ margin-top: 0;
39
+ margin-bottom: govuk-spacing(4);
40
+
41
+ &:last-child {
42
+ margin-bottom: 0;
43
+ }
44
+ }
45
+
46
+ .gem-c-emergency-banner__description--homepage {
47
+ margin: govuk-spacing(4) 0;
48
+ }
49
+
50
+ .gem-c-emergency-banner__link {
51
+ @include govuk-font(19);
52
+ }
53
+
54
+ .gem-c-emergency-banner__link:link,
55
+ .gem-c-emergency-banner__link:visited {
56
+ color: govuk-colour("white");
57
+ }
58
+
59
+ .gem-c-emergency-banner__link:focus {
60
+ @include govuk-focused-text;
61
+ }
62
+
63
+ .gem-c-emergency-banner--notable-death {
64
+ background-color: govuk-colour("black");
65
+ }
66
+
67
+ .gem-c-emergency-banner--national-emergency {
68
+ // Not using govuk-colour("red") aka #d4351c as that's a slightly different red.
69
+ background-color: #b10e1e;
70
+ }
71
+
72
+ .gem-c-emergency-banner--local-emergency {
73
+ // Not using govuk-colour("turquoise") for background colour as
74
+ // the contrast was too low with white text
75
+ background-color: #00847d;
76
+ }
@@ -108,11 +108,3 @@
108
108
  @include govuk-link-style-inverse;
109
109
  }
110
110
  }
111
-
112
- // This helper class is for use by the primary links js module
113
- // We have this custom helper here with a single rule over using the design system helper class govuk-!-display-none
114
- // because jasmine tests don't like the "!" in the distributed helper class
115
-
116
- .primary-links--display-none {
117
- display: none;
118
- }
@@ -0,0 +1,3 @@
1
+ .gem-c-emergency-banner {
2
+ display: none;
3
+ }
@@ -150,7 +150,7 @@ module GovukPublishingComponents
150
150
  end
151
151
 
152
152
  def clean_file_path(file)
153
- file[/(?<=#{Regexp.escape(@path.to_s)}\/)[\/a-zA-Z_-]+.[a-zA-Z.]+/]
153
+ file[/(?<=#{Regexp.escape(@path.to_s)}\/)[\/a-zA-Z_-]+.[a-zA-Z+.]+/]
154
154
  end
155
155
 
156
156
  def clean_file_name(name)
@@ -7,6 +7,10 @@
7
7
 
8
8
  <%= render 'govuk_publishing_components/components/title', title: @component_example.name, context: "#{@component_doc.name} example", margin_top: 0 %>
9
9
 
10
+ <% code_example = capture do %>
11
+ <%= render partial: "govuk_publishing_components/component_guide/component_doc/call", locals: { component_doc: @component_doc, example: @component_example } %>
12
+ <% end %>
13
+
10
14
  <div class="component-show">
11
15
  <div class="component-doc">
12
16
  <div class="component-markdown">
@@ -19,6 +23,6 @@
19
23
  <%= render partial: "govuk_publishing_components/component_guide/component_doc/preview", locals: { component_doc: @component_doc, example: @component_example } %>
20
24
 
21
25
  <h2 class="component-doc-h2">How to call this example</h2>
22
- <%= render partial: "govuk_publishing_components/component_guide/component_doc/call", locals: { component_doc: @component_doc, example: @component_example } %>
26
+ <%= code_example %>
23
27
  </div>
24
28
  </div>
@@ -74,8 +74,11 @@
74
74
  <div class="component-markdown">
75
75
  <%= raw(example.html_description) %>
76
76
  </div>
77
+ <% code_example = capture do %>
78
+ <%= render "govuk_publishing_components/component_guide/component_doc/call", component_doc: @component_doc, example: example %>
79
+ <% end %>
77
80
  <%= render "govuk_publishing_components/component_guide/component_doc/preview", component_doc: @component_doc, example: example %>
78
- <%= render "govuk_publishing_components/component_guide/component_doc/call", component_doc: @component_doc, example: example %>
81
+ <%= code_example %>
79
82
  </div>
80
83
  <% end %>
81
84
  </div>
@@ -22,7 +22,7 @@
22
22
  locales = {}
23
23
 
24
24
  data_attributes ||= {}
25
- data_attributes[:module] = 'govuk-accordion gem-accordion'
25
+ ((data_attributes[:module] ||= "") << " " << "govuk-accordion gem-accordion").strip!
26
26
  data_attributes[:anchor_navigation] = anchor_navigation
27
27
  data_attributes[:track_show_all_clicks] = track_show_all_clicks
28
28
  data_attributes[:track_sections] = track_sections
@@ -0,0 +1,51 @@
1
+ <%
2
+ heading ||= ""
3
+ short_description ||= nil
4
+ link ||= nil
5
+ link_text ||= "More information"
6
+ campaign_class ||= nil
7
+ homepage ||= false
8
+
9
+ emergency_banner_helper = GovukPublishingComponents::Presenters::EmergencyBannerHelper.new()
10
+
11
+ if !campaign_class
12
+ raise ArgumentError, "Need to specify an emergency_type"
13
+ end
14
+
15
+ if !emergency_banner_helper.is_a_valid_emergency_type?(campaign_class)
16
+ raise ArgumentError, "Emergency type #{campaign_class} is not in list of valid emergency types (#{emergency_banner_helper.emergency_types.join(', ')})"
17
+ end
18
+
19
+ banner_classes = %w[gem-c-emergency-banner]
20
+ banner_classes << "gem-c-emergency-banner--#{campaign_class}"
21
+ banner_classes << "gem-c-emergency-banner--homepage" if homepage
22
+
23
+ heading_classes = %w[gem-c-emergency-banner__heading]
24
+ heading_classes << "gem-c-emergency-banner__heading--homepage" if homepage
25
+
26
+ description_classes = %w[gem-c-emergency-banner__description]
27
+ description_classes << "gem-c-emergency-banner__description--homepage" if homepage
28
+
29
+ %>
30
+
31
+ <%= content_tag('div', class: banner_classes, "aria-label": "emergency banner", "role": "region", "data-nosnippet": true ) do %>
32
+ <div class="govuk-width-container">
33
+ <div class="govuk-grid-row">
34
+ <div class="govuk-grid-column-two-thirds">
35
+ <%= content_tag('h2', class: heading_classes) do %>
36
+ <%= heading %>
37
+ <% end %>
38
+ <% if short_description %>
39
+ <%= content_tag('p', class: description_classes) do %>
40
+ <%= short_description %>
41
+ <% end %>
42
+ <% end %>
43
+ <% if link %>
44
+ <a href="<%= link %>" class="gem-c-emergency-banner__link">
45
+ <%= link_text %>
46
+ </a>
47
+ <% end %>
48
+ </div>
49
+ </div>
50
+ </div>
51
+ <% end %>
@@ -6,7 +6,7 @@
6
6
  margin_top ||= 3
7
7
  margin_bottom ||= 3
8
8
 
9
- data_attributes[:module] = require_js ? "print-link" : "button"
9
+ ((data_attributes[:module] ||= "") << " " << (require_js ? "print-link" : "button")).strip!
10
10
 
11
11
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new({
12
12
  margin_top: margin_top,
@@ -185,18 +185,17 @@ examples:
185
185
  description: |
186
186
  Adds custom data attributes to each section of the accordion. Accepts a hash, so multiple attributes can be added.
187
187
 
188
- The `data_attributes` hash is for the outermost element in the accordion.
188
+ The `data_attributes` option applies attributes to the outermost element in the accordion. Each item can also have a `data_attributes` hash, which are placed on the `button` that triggers the opening and closing - useful for differentiating between each section of the accordion.
189
189
 
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.
190
+ Data attributes can 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). More details on how this can be used with the GA4 event tracking can be found in the 'Advanced' section of the [event tracking documentation](https://github.com/alphagov/govuk_publishing_components/blob/main/docs/analytics-gtm/ga4-event-tracker.md).
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). If `track_options` within `data_attributes_show_all` is set, then it is possible to pass a custom dimension when 'Show/Hide all' is clicked.
192
+ If `track_options` within `data_attributes_show_all` is set, then it is possible to pass a custom dimension when 'Show/Hide all' is clicked.
193
193
  data:
194
194
  data_attributes:
195
- gtm: gtm-accordion
196
- ga: ga-accordion
195
+ custom_data_attr: custom-data-attr-accordion
197
196
  data_attributes_show_all:
198
- gtm-event-name: example
199
- gtm-attributes: "{ 'ui': { 'type': 'type value', 'section': 'section value' } }"
197
+ custom_data_attr-event-name: example
198
+ custom_data_attr-attributes: "{ 'ui': { 'type': 'type value', 'section': 'section value' } }"
200
199
  tracking-options: "{ 'dimension114': 1 }"
201
200
  items:
202
201
  - heading:
@@ -204,25 +203,39 @@ examples:
204
203
  content:
205
204
  html: <p class="govuk-body">This is the content for Writing well for the web.</p>
206
205
  data_attributes:
207
- gtm: gtm-accordion-item-1
206
+ custom_data_attr: custom-data-attr-accordion-item-1
208
207
  - heading:
209
208
  text: Writing well for specialists
210
209
  content:
211
210
  html: <p class="govuk-body">This is the content for Writing well for specialists.</p>
212
211
  data_attributes:
213
- gtm: gtm-accordion-item-2
212
+ custom_data_attr: custom-data-attr-accordion-item-2
214
213
  - heading:
215
214
  text: Know your audience
216
215
  content:
217
216
  html: <p class="govuk-body">This is the content for Know your audience.</p>
218
217
  data_attributes:
219
- gtm: gtm-accordion-item-3
218
+ custom_data_attr: custom-data-attr-accordion-item-3
220
219
  - heading:
221
220
  text: How people read
222
221
  content:
223
222
  html: <p class="govuk-body">This is the content for How people read.</p>
224
223
  data_attributes:
225
- gtm: gtm-accordion-item-4
224
+ custom_data_attr: custom-data-attr-accordion-item-4
225
+ with_custom_data_module:
226
+ description: The component includes its own `data-module` but others can be passed in addition if required, for example to apply tracking to an element. This will be included along with the components own `data-module`.
227
+ data:
228
+ data_attributes:
229
+ module: gem-track-click
230
+ items:
231
+ - heading:
232
+ text: Writing well for the web
233
+ content:
234
+ html: <p class="govuk-body">This is the content for Writing well for the web.</p>
235
+ - heading:
236
+ text: Writing well for specialists
237
+ content:
238
+ html: <p class="govuk-body">This is the content for Writing well for specialists.</p>
226
239
  different_heading_level:
227
240
  description: This will alter the level of the heading, not the appearance of the heading.
228
241
  data:
@@ -0,0 +1,45 @@
1
+ name: Emergency banner
2
+ description: A site-wide banner used in the event of an emergency
3
+ body: |
4
+ There are three types of events that would lead GOV.UK to add an emergency banner to the top of each page on the web site; a notable death, a national emergency or a local emergency.
5
+
6
+ See the [opsmanual](https://docs.publishing.service.gov.uk/manual/emergency-publishing.html#adding-emergency-publishing-banners) for information about what the Emergency Banner is and when it should be deployed.
7
+
8
+ shared_accessibility_criteria:
9
+ - link
10
+
11
+ examples:
12
+ default:
13
+ description: |
14
+ Death of a notable person
15
+ data:
16
+ campaign_class: "notable-death"
17
+ heading: "His Royal Highness Henry VIII"
18
+ short_description: "1491 to 1547"
19
+ link_text: "Override Link Text"
20
+ link: "https://www.gov.uk/"
21
+ national_emergency:
22
+ description: |
23
+ National emergency (level 1 or category 2)
24
+ data:
25
+ campaign_class: "national-emergency"
26
+ heading: "National emergency"
27
+ short_description: "This is a level 1 incident"
28
+ link: "https://www.gov.uk/"
29
+ local_emergency:
30
+ description: |
31
+ Localised large-scale emergency (level 2 or category 1)
32
+ data:
33
+ campaign_class: "local-emergency"
34
+ heading: "Local emergency"
35
+ short_description: "This is a level 2 incident"
36
+ link: "https://www.gov.uk/"
37
+ notable_death_homepage:
38
+ description: |
39
+ When presenting any type of emergency banner on homepage the styling is slightly different.
40
+ data:
41
+ campaign_class: "notable-death"
42
+ heading: "His Royal Highness Henry VIII"
43
+ short_description: "1491 to 1547"
44
+ link: "https://www.gov.uk/"
45
+ homepage: true
@@ -26,6 +26,11 @@ examples:
26
26
  track-category: "printButton"
27
27
  track-action: "clicked"
28
28
  track-label: "Print this page"
29
+ with_custom_data_module:
30
+ description: The component includes its own `data-module` but others can be passed in addition if required, for example to apply tracking to an element. This will be included along with the components own `data-module`.
31
+ data:
32
+ data_attributes:
33
+ module: "gem-track-click"
29
34
  with_custom_margins:
30
35
  description: The component accepts a number for margin bottom from `0` to `9` (`0px` to `60px`) using the [GOV.UK Frontend spacing scale](https://design-system.service.gov.uk/styles/spacing/#the-responsive-spacing-scale). It defaults to having margin level `3` on top and bottom.
31
36
  data:
@@ -16,7 +16,6 @@ hr:
16
16
  order_a_copy: Naručite kopiju
17
17
  page:
18
18
  few:
19
- many:
20
19
  one: 1 stranica
21
20
  other: "%{count} stranice"
22
21
  reference: 'Referenca: %{reference}'
@@ -0,0 +1,17 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class EmergencyBannerHelper
4
+ EMERGENCY_TYPES = %w[notable-death national-emergency local-emergency].freeze
5
+
6
+ def initialize; end
7
+
8
+ def emergency_types
9
+ EMERGENCY_TYPES
10
+ end
11
+
12
+ def is_a_valid_emergency_type?(type)
13
+ EMERGENCY_TYPES.include?(type)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "29.15.3".freeze
2
+ VERSION = "30.2.0".freeze
3
3
  end
@@ -12,6 +12,7 @@ require "govuk_publishing_components/presenters/breadcrumb_selector"
12
12
  require "govuk_publishing_components/presenters/button_helper"
13
13
  require "govuk_publishing_components/presenters/contextual_navigation"
14
14
  require "govuk_publishing_components/presenters/devolved_nations_helper"
15
+ require "govuk_publishing_components/presenters/emergency_banner_helper"
15
16
  require "govuk_publishing_components/presenters/related_navigation_helper"
16
17
  require "govuk_publishing_components/presenters/step_by_step_nav_helper"
17
18
  require "govuk_publishing_components/presenters/page_with_step_by_step_navigation"
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.15.3
4
+ version: 30.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-07-27 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -436,9 +436,10 @@ files:
436
436
  - app/assets/javascripts/component_guide/vendor/matches-polyfill.min.js
437
437
  - app/assets/javascripts/govuk_publishing_components/all_components.js
438
438
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4.js
439
- - app/assets/javascripts/govuk_publishing_components/analytics-ga4/gtm-click-tracking.js
440
- - app/assets/javascripts/govuk_publishing_components/analytics-ga4/gtm-page-views.js
441
- - app/assets/javascripts/govuk_publishing_components/analytics-ga4/gtm-schemas.js
439
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-event-tracker.js
440
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-link-tracker.js
441
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js
442
+ - app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-schemas.js
442
443
  - app/assets/javascripts/govuk_publishing_components/analytics-ga4/pii-remover.js
443
444
  - app/assets/javascripts/govuk_publishing_components/analytics.js
444
445
  - app/assets/javascripts/govuk_publishing_components/analytics/analytics.js
@@ -495,7 +496,6 @@ files:
495
496
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js
496
497
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js
497
498
  - app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js
498
- - app/assets/javascripts/govuk_publishing_components/lib/primary-links.js
499
499
  - app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js
500
500
  - app/assets/javascripts/govuk_publishing_components/lib/toggle.js
501
501
  - app/assets/javascripts/govuk_publishing_components/lib/trigger-event.js
@@ -535,6 +535,7 @@ files:
535
535
  - app/assets/stylesheets/govuk_publishing_components/components/_details.scss
536
536
  - app/assets/stylesheets/govuk_publishing_components/components/_devolved-nations.scss
537
537
  - app/assets/stylesheets/govuk_publishing_components/components/_document-list.scss
538
+ - app/assets/stylesheets/govuk_publishing_components/components/_emergency-banner.scss
538
539
  - app/assets/stylesheets/govuk_publishing_components/components/_error-alert.scss
539
540
  - app/assets/stylesheets/govuk_publishing_components/components/_error-message.scss
540
541
  - app/assets/stylesheets/govuk_publishing_components/components/_error-summary.scss
@@ -623,6 +624,7 @@ files:
623
624
  - app/assets/stylesheets/govuk_publishing_components/components/print/_button.scss
624
625
  - app/assets/stylesheets/govuk_publishing_components/components/print/_cards.scss
625
626
  - app/assets/stylesheets/govuk_publishing_components/components/print/_contents-list.scss
627
+ - app/assets/stylesheets/govuk_publishing_components/components/print/_emergency-banner.scss
626
628
  - app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak-html-publication.scss
627
629
  - app/assets/stylesheets/govuk_publishing_components/components/print/_govspeak.scss
628
630
  - app/assets/stylesheets/govuk_publishing_components/components/print/_layout-super-navigation-header.scss
@@ -679,6 +681,7 @@ files:
679
681
  - app/views/govuk_publishing_components/components/_details.html.erb
680
682
  - app/views/govuk_publishing_components/components/_devolved_nations.html.erb
681
683
  - app/views/govuk_publishing_components/components/_document_list.html.erb
684
+ - app/views/govuk_publishing_components/components/_emergency_banner.html.erb
682
685
  - app/views/govuk_publishing_components/components/_error_alert.html.erb
683
686
  - app/views/govuk_publishing_components/components/_error_message.html.erb
684
687
  - app/views/govuk_publishing_components/components/_error_summary.html.erb
@@ -761,6 +764,7 @@ files:
761
764
  - app/views/govuk_publishing_components/components/docs/details.yml
762
765
  - app/views/govuk_publishing_components/components/docs/devolved_nations.yml
763
766
  - app/views/govuk_publishing_components/components/docs/document_list.yml
767
+ - app/views/govuk_publishing_components/components/docs/emergency_banner.yml
764
768
  - app/views/govuk_publishing_components/components/docs/error_alert.yml
765
769
  - app/views/govuk_publishing_components/components/docs/error_message.yml
766
770
  - app/views/govuk_publishing_components/components/docs/error_summary.yml
@@ -923,6 +927,7 @@ files:
923
927
  - lib/govuk_publishing_components/presenters/contextual_navigation.rb
924
928
  - lib/govuk_publishing_components/presenters/curated_taxonomy_sidebar_links.rb
925
929
  - lib/govuk_publishing_components/presenters/devolved_nations_helper.rb
930
+ - lib/govuk_publishing_components/presenters/emergency_banner_helper.rb
926
931
  - lib/govuk_publishing_components/presenters/heading_helper.rb
927
932
  - lib/govuk_publishing_components/presenters/image_card_helper.rb
928
933
  - lib/govuk_publishing_components/presenters/intervention_helper.rb
@@ -1932,7 +1937,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1932
1937
  - !ruby/object:Gem::Version
1933
1938
  version: '0'
1934
1939
  requirements: []
1935
- rubygems_version: 3.3.18
1940
+ rubygems_version: 3.3.20
1936
1941
  signing_key:
1937
1942
  specification_version: 4
1938
1943
  summary: A gem to document components in GOV.UK frontend applications
@@ -1,74 +0,0 @@
1
- // migrated from govuk_frontend_toolkit
2
- ;(function (global) {
3
- 'use strict'
4
-
5
- var GOVUK = global.GOVUK || {}
6
-
7
- // Only show the first {n} items in a list, documentation is in the README.md
8
- var PrimaryList = function (el, selector) {
9
- this.el = el
10
- this.extraLinks = this.el.querySelectorAll('li:not(' + selector + ')')
11
- // only hide more than one extra link
12
- if (this.extraLinks.length > 1) {
13
- this.addToggleLink()
14
- this.hideExtraLinks()
15
- }
16
- }
17
-
18
- PrimaryList.prototype = {
19
- toggleText: function () {
20
- if (this.extraLinks.length > 1) {
21
- return '+' + this.extraLinks.length + ' others'
22
- } else {
23
- return '+' + this.extraLinks.length + ' other'
24
- }
25
- },
26
- addToggleLink: function () {
27
- this.toggleLink = document.createElement('a')
28
- this.toggleLink.href = '#'
29
- this.toggleLink.setAttribute('aria-expanded', 'false')
30
- this.toggleLink.innerText = this.toggleText()
31
-
32
- this.el.parentNode.insertBefore(this.toggleLink, this.el.nextSibling)
33
- this.toggleLink.addEventListener('click', this.toggleLinks.bind(this))
34
- },
35
- toggleLinks: function (e) {
36
- e.preventDefault()
37
- this.toggleLink.remove()
38
- this.showExtraLinks()
39
- },
40
- hideExtraLinks: function () {
41
- for (var i = 0; i < this.extraLinks.length; i++) {
42
- this.extraLinks[i].className = 'primary-links--display-none'
43
- }
44
- },
45
- showExtraLinks: function () {
46
- for (var i = 0; i < this.extraLinks.length; i++) {
47
- this.extraLinks[i].className = ''
48
- }
49
- }
50
- }
51
-
52
- GOVUK.PrimaryList = PrimaryList
53
-
54
- GOVUK.primaryLinks = {
55
- init: function (selector) {
56
- var allListItems = document.querySelectorAll(selector)
57
- var AllLists = []
58
-
59
- for (var i = 0; i < allListItems.length; i++) {
60
- var parent = allListItems[i].parentNode
61
-
62
- if (AllLists.indexOf(parent) < 0) {
63
- AllLists.push(parent)
64
- }
65
- }
66
-
67
- AllLists.forEach(function (el, i) {
68
- new GOVUK.PrimaryList(el, selector) // eslint-disable-line no-new
69
- })
70
- }
71
- }
72
-
73
- global.GOVUK = GOVUK
74
- })(window)