govuk_publishing_components 27.15.0 → 27.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e405833a40d51e34a480d411380a552a68d49a9c398fa89fa694716e0a22131f
4
- data.tar.gz: c6f710970b8ecae4c214851ee2e250b80673e38ec004bf161a1ca1042a44af3b
3
+ metadata.gz: 586ea5662dfd4f3951905b244afc78556dc687bf861a05e11e56ff7d2ee172eb
4
+ data.tar.gz: eab6ea6544883bc5fa511f29e589d996eabae18a6661f0772ac45356668f5396
5
5
  SHA512:
6
- metadata.gz: a24c9485202f161b46daff7ec6b081148c8e58d52f8fed9cab8ab6f2d90b016b1d06e81abf0ffd157b75c7331d7b5151b018bbe58f580c6d8bdf94f23ee0dcab
7
- data.tar.gz: b63635bfda7d6ccb8ee7e88d810f19e97343d6cb7a08075bba620764cfd609ad0b1043361e1a5b84b49c1787263119b521316b44435dd8c6566754e5635c7b0c
6
+ metadata.gz: f513e048959e7e81b753583f923772b590f5c4da1841e666f4131bc79e8dea9b8cd4571cba7bab859e0d1b4683a1b10ebaa17d56cd6d3ab3a4eff68090837a1c
7
+ data.tar.gz: 5f2d6aa1171a47b3074ba65b0dc5488b9269dc4f7781580df52d7d1c354559d19270bace849b39342c51e3e4ad9342a966354da39dabb6f52838de4c505f0f03
@@ -1,4 +1,4 @@
1
- /* global GOVUK, $ */
1
+ /* global GOVUK */
2
2
 
3
3
  (function () {
4
4
  'use strict'
@@ -7,11 +7,11 @@
7
7
 
8
8
  CustomDimensions.getAndExtendDefaultTrackingOptions = function (extraOptions) {
9
9
  var trackingOptions = this.customDimensions()
10
- return $.extend(trackingOptions, extraOptions)
10
+ return this.extend(trackingOptions, extraOptions)
11
11
  }
12
12
 
13
13
  CustomDimensions.customDimensions = function () {
14
- var dimensions = $.extend(
14
+ var dimensions = this.extend(
15
15
  {},
16
16
  customDimensionsFromBrowser(),
17
17
  customDimensionsFromMetaTags(),
@@ -19,9 +19,28 @@
19
19
  abTestCustomDimensions()
20
20
  )
21
21
 
22
- return $.each(dimensions, function (key, value) {
23
- dimensions[key] = new GOVUK.Analytics.PIISafe(String(value))
24
- })
22
+ for (var key in dimensions) {
23
+ dimensions[key] = new GOVUK.Analytics.PIISafe(String(dimensions[key]))
24
+ }
25
+ return dimensions
26
+ }
27
+
28
+ CustomDimensions.extend = function (out) {
29
+ out = out || {}
30
+
31
+ for (var i = 1; i < arguments.length; i++) {
32
+ if (!arguments[i]) {
33
+ continue
34
+ }
35
+
36
+ for (var key in arguments[i]) {
37
+ if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
38
+ out[key] = arguments[i][key]
39
+ }
40
+ }
41
+ }
42
+
43
+ return out
25
44
  }
26
45
 
27
46
  function customDimensionsFromBrowser () {
@@ -70,52 +89,59 @@
70
89
  'spelling-suggestion': { dimension: 81 }
71
90
  }
72
91
 
73
- var $metas = $('meta[name^="govuk:"]')
92
+ var metas = document.querySelectorAll("meta[name^='govuk']")
74
93
  var customDimensions = {}
75
94
  var tags = {}
76
95
 
77
- $metas.each(function () {
78
- var $meta = $(this)
79
- var key = $meta.attr('name').split('govuk:')[1]
80
-
81
- var dimension = dimensionMappings[key]
96
+ for (var i = 0; i < metas.length; i++) {
97
+ var meta = metas[i]
98
+ var metaKey = meta.getAttribute('name').split('govuk:')[1]
99
+ var dimension = dimensionMappings[metaKey]
82
100
  if (dimension) {
83
- tags[key] = $meta.attr('content')
101
+ tags[metaKey] = meta.getAttribute('content')
84
102
  }
85
- })
103
+ }
86
104
 
87
- $.each(dimensionMappings, function (key, dimension) {
88
- var value = tags[key] || dimension.defaultValue
105
+ for (var key in dimensionMappings) {
106
+ var value = tags[key] || dimensionMappings[key].defaultValue
89
107
  if (typeof value !== 'undefined') {
90
- customDimensions['dimension' + dimension.dimension] = value
108
+ customDimensions['dimension' + dimensionMappings[key].dimension] = value
91
109
  }
92
- })
110
+ }
93
111
 
94
112
  return customDimensions
95
113
  }
96
114
 
97
115
  function customDimensionsFromDom () {
116
+ var mainLang = document.getElementById('content')
117
+ if (mainLang) {
118
+ mainLang = mainLang.getAttribute('lang')
119
+ }
120
+ var globalBar = document.querySelector('[data-module="global-bar"]') || false
121
+ if (globalBar) {
122
+ globalBar = globalBar.style.display !== 'none'
123
+ }
98
124
  return {
99
125
  dimension26: GOVUK.PageContent.getNumberOfSections(),
100
126
  dimension27: GOVUK.PageContent.getNumberOfLinks(),
101
- dimension23: $('main[id="content"]').attr('lang') || 'unknown',
102
- dimension38: $('[data-module="global-bar"]').is(':visible') && 'Global Banner viewed'
127
+ dimension23: mainLang || 'unknown',
128
+ dimension38: globalBar && 'Global Banner viewed'
103
129
  }
104
130
  }
105
131
 
106
132
  function abTestCustomDimensions () {
107
- var $abMetas = $('meta[name^="govuk:ab-test"]')
133
+ var abMetas = document.querySelectorAll("meta[name^='govuk:ab-test']")
108
134
  var customDimensions = {}
109
135
 
110
- $abMetas.each(function () {
111
- var $meta = $(this)
112
- var dimension = parseInt($meta.data('analytics-dimension'))
113
- var testNameAndBucket = $meta.attr('content')
136
+ for (var i = 0; i < abMetas.length; i++) {
137
+ var meta = abMetas[i]
138
+ var dimension = parseInt(meta.getAttribute('data-analytics-dimension'))
139
+ var testNameAndBucket = meta.getAttribute('content')
114
140
 
115
141
  if (dimension) {
116
142
  customDimensions['dimension' + dimension] = testNameAndBucket
117
143
  }
118
- })
144
+ }
119
145
 
120
146
  return customDimensions
121
147
  }
@@ -1,5 +1,5 @@
1
1
  // https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce
2
- /* global GOVUK, $, ga */
2
+ /* global GOVUK, ga */
3
3
 
4
4
  (function () {
5
5
  'use strict'
@@ -12,25 +12,25 @@
12
12
  this.init = function (element) {
13
13
  // Limiting to 100 characters to avoid noise from extra longs search queries
14
14
  // and to stop the size of the payload going over 8k limit.
15
- var searchQuery = GOVUK.analytics.stripPII(element.attr('data-search-query')).substring(0, 100).toLowerCase()
16
- var ecommerceRows = element.find('[data-ecommerce-row]')
17
- var startPosition = parseInt(element.data('ecommerce-start-index'), 10)
18
- var listTitle = element.data('list-title') || DEFAULT_LIST_TITLE
19
- var variant = element.data('ecommerce-variant')
20
- var trackClickLabel = element.data('track-click-label') || DEFAULT_TRACK_CLICK_LABEL
21
-
22
- ecommerceRows.each(function (index, ecommerceRow) {
23
- var $ecommerceRow = $(ecommerceRow)
24
- var listSubheading = $ecommerceRow.data('ecommerce-subheading') || undefined
25
- var contentId = $ecommerceRow.attr('data-ecommerce-content-id')
26
- var path = $ecommerceRow.attr('data-ecommerce-path')
27
-
28
- var indexOverride = $ecommerceRow.attr('data-ecommerce-index')
29
- index = indexOverride ? parseInt(indexOverride, 10) - 1 : index
15
+ var searchQuery = GOVUK.analytics.stripPII(element.getAttribute('data-search-query')).substring(0, 100).toLowerCase()
16
+ var ecommerceRows = element.querySelectorAll('[data-ecommerce-row]')
17
+ var startPosition = parseInt(element.getAttribute('data-ecommerce-start-index'), 10)
18
+ var listTitle = element.getAttribute('data-list-title') || DEFAULT_LIST_TITLE
19
+ var variant = element.getAttribute('data-ecommerce-variant') || undefined
20
+ var trackClickLabel = element.getAttribute('data-track-click-label') || DEFAULT_TRACK_CLICK_LABEL
21
+
22
+ for (var i = 0; i < ecommerceRows.length; i++) {
23
+ var ecommerceRow = ecommerceRows[i]
24
+ var listSubheading = ecommerceRow.getAttribute('data-ecommerce-subheading') || undefined
25
+ var contentId = ecommerceRow.getAttribute('data-ecommerce-content-id') || undefined
26
+ var path = ecommerceRow.getAttribute('data-ecommerce-path')
27
+
28
+ var indexOverride = ecommerceRow.getAttribute('data-ecommerce-index')
29
+ var index = indexOverride ? parseInt(indexOverride, 10) - 1 : i
30
30
 
31
31
  addImpression(contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant)
32
- trackProductOnClick($ecommerceRow, contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant, trackClickLabel)
33
- })
32
+ trackProductOnClick(ecommerceRow, contentId, path, index + startPosition, searchQuery, listTitle, listSubheading, variant, trackClickLabel)
33
+ }
34
34
  }
35
35
 
36
36
  function constructData (contentId, path, position, listTitle, listSubheading, searchQuery, variant) {
@@ -67,7 +67,7 @@
67
67
  }
68
68
 
69
69
  function trackProductOnClick (row, contentId, path, position, searchQuery, listTitle, listSubheading, variant, trackClickLabel) {
70
- row.click(function () {
70
+ row.addEventListener('click', function () {
71
71
  if (contentId || path) {
72
72
  var clickData = constructData(contentId, path, position, listTitle, listSubheading, searchQuery, variant)
73
73
  ga('ec:addProduct', clickData)
@@ -82,18 +82,18 @@
82
82
  }
83
83
 
84
84
  Ecommerce.ecLoaded = false
85
- Ecommerce.start = function (element) {
85
+ Ecommerce.start = function (elements) {
86
86
  if (!window.ga) { return }
87
- element = element || $('[data-analytics-ecommerce]')
88
- if (element.length > 0) {
87
+ elements = elements || document.querySelectorAll('[data-analytics-ecommerce]')
88
+ if (elements.length > 0) {
89
89
  if (!Ecommerce.ecLoaded) {
90
90
  ga('require', 'ec')
91
91
  Ecommerce.ecLoaded = true
92
92
  }
93
- element.each(function (index) {
93
+ for (var i = 0; i < elements.length; i++) {
94
94
  var ecommerce = new Ecommerce()
95
- ecommerce.init($(this))
96
- })
95
+ ecommerce.init(elements[i])
96
+ }
97
97
  }
98
98
  }
99
99
 
@@ -1,13 +1,26 @@
1
1
  .gem-c-big-number {
2
2
  margin-bottom: govuk-spacing(3);
3
+ @include govuk-typography-common;
4
+ @include govuk-text-colour;
3
5
  }
4
6
 
5
7
  .gem-c-big-number__value {
6
- @include govuk-font($size: 80, $weight: bold);
8
+ font-size: 80px;
9
+ @include govuk-typography-weight-bold;
10
+ line-height: 1;
11
+
12
+ @if $govuk-typography-use-rem {
13
+ font-size: govuk-px-to-rem(80px);
14
+ }
7
15
  }
8
16
 
9
17
  .gem-c-big-number__label {
10
- @include govuk-font($size: 16, $weight: bold, $line-height: 2);
18
+ font-size: 16px;
19
+ @include govuk-typography-weight-bold;
20
+
21
+ @if $govuk-typography-use-rem {
22
+ font-size: govuk-px-to-rem(16px);
23
+ }
11
24
 
12
25
  // This pseudo element is to bypass an issue with NVDA where block level elements are dictated separately.
13
26
  // What's happening here is that the label and the number technically have an inline relationship but appear to have a block relationship thanks to this element
@@ -3,6 +3,7 @@
3
3
  suggestion_link_text ||= false
4
4
  suggestion_link_url ||= false
5
5
  suggestion_text ||= nil
6
+ new_tab ||= false
6
7
 
7
8
  data_attributes ||= {}
8
9
  data_attributes[:module] = 'intervention'
@@ -13,17 +14,33 @@
13
14
  aria_attributes[:label] = 'Intervention'
14
15
 
15
16
  local_assigns[:query_string] ||= request.query_string
17
+ local_assigns[:suggestion_link_text] = suggestion_link_text
18
+ local_assigns[:suggestion_link_url] = suggestion_link_url
16
19
 
17
20
  intervention_helper = GovukPublishingComponents::Presenters::InterventionHelper.new(local_assigns)
18
21
  dismiss_href = intervention_helper.dismiss_link
22
+
23
+ suggestion_tag_options = {
24
+ class: "govuk-link gem-c-intervention__suggestion-link",
25
+ href: suggestion_link_url,
26
+ data: suggestion_data_attributes,
27
+ }
28
+
29
+ if new_tab && (suggestion_link_text && suggestion_link_url)
30
+ target = "_blank"
31
+ rel = intervention_helper.security_attr
32
+
33
+ suggestion_tag_options.merge!({ target: target, rel: rel })
34
+
35
+ suggestion_link_text = intervention_helper.accessible_text
36
+ end
19
37
  %>
20
- <% if suggestion_text or (suggestion_link_text and suggestion_link_text) %>
38
+ <% if suggestion_text || (suggestion_link_text && suggestion_link_url) %>
21
39
  <%= tag.section class: "gem-c-intervention", role: "region", aria: aria_attributes, data: data_attributes do %>
22
40
  <p class="govuk-body">
23
41
  <%= tag.span suggestion_text, class: "gem-c-intervention__textwrapper" if suggestion_text %>
24
- <% if suggestion_link_text and suggestion_link_url %>
25
- <%= tag.a suggestion_link_text, class: "govuk-link gem-c-intervention__suggestion-link", href: suggestion_link_url, data: suggestion_data_attributes %>
26
-
42
+ <% if suggestion_link_text && suggestion_link_url %>
43
+ <%= tag.a suggestion_link_text, suggestion_tag_options %>
27
44
  <% end %>
28
45
  </p>
29
46
 
@@ -1,9 +1,12 @@
1
1
  <%
2
2
  description ||= nil
3
3
  title_id ||= "govuk-notification-banner-title-#{SecureRandom.hex(4)}"
4
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
5
+ classes = %w(gem-c-success-alert govuk-notification-banner govuk-notification-banner--success)
6
+ classes << shared_helper.get_margin_bottom if local_assigns[:margin_bottom]
4
7
  %>
5
8
 
6
- <%= tag.div class: "gem-c-success-alert govuk-notification-banner govuk-notification-banner--success",
9
+ <%= tag.div class: classes,
7
10
  role: "alert",
8
11
  tabindex: "-1",
9
12
  aria: {
@@ -38,6 +38,17 @@ examples:
38
38
  suggestion_link_text: "You can now apply for a permit online."
39
39
  suggestion_link_url: "/permit"
40
40
 
41
+ open_suggestion_link_in_new_tab:
42
+ description: |
43
+ When sending users to another online task, you don't want to completely hijack
44
+ their original flow on GOV.UK. Adding the option to open links in a new tab helps to address this.
45
+ Link text should tell the user that the link opens in a new tab.
46
+ Note: "(opens in a new tab)" is added to link text if the phrase isn't included.
47
+ data:
48
+ suggestion_link_text: "You can now apply for a permit online"
49
+ suggestion_link_url: "www.google.com/permit"
50
+ new_tab: true
51
+
41
52
  with_data_attributes:
42
53
  description: |
43
54
  This example shows the use of `suggestion_data_attributes` and
@@ -37,3 +37,9 @@ examples:
37
37
  orci. Proin semper porttitor ipsum, vel maximus justo rutrum vel.
38
38
  Morbi volutpat facilisis libero. Donec posuere eget odio non egestas.
39
39
  Nullam sed neque quis turpis.
40
+ with_custom_margin_bottom:
41
+ description: |
42
+ 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). The default margins for the component are inherited from the [notification-banner](https://github.com/alphagov/govuk-frontend/blob/main/package/govuk/components/notification-banner/_index.scss) styles defined in the Design System.
43
+ data:
44
+ message: Message to alert the user to a successful action goes here
45
+ margin_bottom: 3
@@ -86,6 +86,8 @@ en:
86
86
  news_and_communications: News and communications
87
87
  statistics: Statistics
88
88
  worldwide: Worldwide
89
+ intervention:
90
+ accessible_link_text_suffix: " (opens in a new tab)"
89
91
  layout_footer:
90
92
  copyright_html: <a class="govuk-footer__link govuk-footer__copyright-logo" href="https://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/uk-government-licensing-framework/crown-copyright/">© Crown copyright</a>
91
93
  licence_html: All content is available under the <a class="govuk-footer__link" href="https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/" rel="license">Open Government Licence v3.0</a>, except where otherwise stated
@@ -1,10 +1,17 @@
1
1
  module GovukPublishingComponents
2
2
  module Presenters
3
3
  class InterventionHelper
4
- attr_reader :query_string
5
-
6
4
  def initialize(local_assigns)
5
+ @accessible_text_suffix = I18n.t("components.intervention.accessible_link_text_suffix")
7
6
  @query_string = local_assigns[:query_string]
7
+ @suggestion_link_text = local_assigns[:suggestion_link_text]
8
+ @suggestion_link_url = local_assigns[:suggestion_link_url]
9
+ end
10
+
11
+ def accessible_text
12
+ @suggestion_link_text << @accessible_text_suffix unless @suggestion_link_text.include?(@accessible_text_suffix)
13
+
14
+ @suggestion_link_text
8
15
  end
9
16
 
10
17
  def dismiss_link
@@ -14,6 +21,17 @@ module GovukPublishingComponents
14
21
  "?hide-intervention=true"
15
22
  end
16
23
  end
24
+
25
+ def security_attr
26
+ rel = "noopener noreferrer"
27
+ rel << " external" unless @suggestion_link_url.start_with?("/", "https://gov.uk", "https://www.gov.uk")
28
+
29
+ rel
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :accessible_text_suffix, :query_string, :suggestion_link_text, :suggestion_link_url
17
35
  end
18
36
  end
19
37
  end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "27.15.0".freeze
2
+ VERSION = "27.16.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_publishing_components
3
3
  version: !ruby/object:Gem::Version
4
- version: 27.15.0
4
+ version: 27.16.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: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2021-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config