govuk_publishing_components 27.14.1 → 27.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1de3732f2f8d07ca871687595bcc8ee4ce0ed90ce07fba59000f91399e543646
4
- data.tar.gz: 5bc957d6e609ab9c946872b7260118aa3e8fb718b0d0fd1a01813c3542715e09
3
+ metadata.gz: 07e0c548e46fc4a7dcb04e7f2838f17b7fc6234804695cfbeca50d1aec4f4431
4
+ data.tar.gz: 33b0e798aed35a5ab8808ad6b6e0ee99a929c6d2b8da837d6acb156cf66d4f2c
5
5
  SHA512:
6
- metadata.gz: 8cffec1a9a81f634492fb7c47f95c9ffb6b2664c951b15bbfa1a6f790fa1fe2e3d9bdaed3910e6b5cbcebe6152e15ba60585bc9438951c205a72a662b0bb1fe1
7
- data.tar.gz: bd6342f5215c706369f52a8461b756a203274253c15832dda29b3aa9b8d883ee48e5b52441e1fba95e9f798e4cb17a00830a8b61c85301b33e1287d039ec6ac1
6
+ metadata.gz: b48854f3ab1990a2166fbef3f8e57f2487778b7c9df6a0327e05318821b978ba3ef21f0a0865c6cc3cb714d0bff8a3fd6e102cd855fa1b28b78c32d66d92f0a0
7
+ data.tar.gz: 7bb47453cfc2208ffe22cb79c6493d85720a137b405709a545b3a6a6f37ee59e05b953a59c8cd067d2661038d3dbe323950b6662378ee24ee1ae8c14e98dbcd0
@@ -31,9 +31,21 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
31
31
  return
32
32
  }
33
33
 
34
+ this.trackType = this.$module.getAttribute('data-track-type')
35
+ var trackHeadings = this.$module.getAttribute('data-track-headings')
36
+ if (trackHeadings) {
37
+ try {
38
+ this.config.trackHeadings = JSON.parse(trackHeadings)
39
+ } catch (e) {
40
+ // if there's a problem with the config, don't start the tracker
41
+ console.error('Scroll tracker configuration error: ' + e.message, window.location)
42
+ window.GOVUK.analyticsVars.scrollTrackerStarted = false
43
+ return
44
+ }
45
+ }
46
+
34
47
  window.GOVUK.analyticsVars.scrollTrackerStarted = true
35
48
 
36
- this.trackType = this.$module.getAttribute('data-track-type')
37
49
  if (this.trackType === 'headings') {
38
50
  this.track = new AutoScrollTracker.Heading(this.config)
39
51
  } else {
@@ -145,15 +157,24 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
145
157
 
146
158
  // check heading is inside allowed elements, generally ignores everything outside of page content
147
159
  AutoScrollTracker.Heading.prototype.findAllowedHeadings = function () {
148
- var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
149
160
  var headingsFound = []
161
+ var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6']
162
+ var trackHeadings = this.config.trackHeadings
150
163
 
164
+ // this is a loop that only happens once as we currently only have one
165
+ // allowed element for headings to be in - 'main'
151
166
  for (var h = 0; h < this.config.allowHeadingsInside.length; h++) {
152
167
  var insideElements = document.querySelectorAll(this.config.allowHeadingsInside[h])
153
168
  for (var e = 0; e < insideElements.length; e++) {
154
169
  var found = insideElements[e].querySelectorAll(headings)
155
170
  for (var f = 0; f < found.length; f++) {
156
- headingsFound.push(found[f])
171
+ if (trackHeadings) {
172
+ if (trackHeadings.includes(found[f].textContent.trim())) {
173
+ headingsFound.push(found[f])
174
+ }
175
+ } else {
176
+ headingsFound.push(found[f])
177
+ }
157
178
  }
158
179
  }
159
180
  }
@@ -10,12 +10,18 @@
10
10
 
11
11
  var cookieBannerEngaged = GOVUK.cookie('cookies_preferences_set')
12
12
 
13
- // If not engaged, append only ?cookie-consent=not-engaged
14
- // If engaged and rejected, append only ?cookie-consent=reject
15
- // If engaged and accepted usage, append ?_ga=clientid if available and cookie-consent=accept
13
+ // If not engaged, append only ?cookie_consent=not-engaged
14
+ // If engaged and rejected, append only ?cookie_consent=reject
15
+ // If engaged and accepted usage, append ?_ga=clientid if available and cookie_consent=accept
16
16
 
17
17
  if (cookieBannerEngaged !== 'true') {
18
18
  this.decorate(element, 'cookie_consent=not-engaged')
19
+ this.start = this.start.bind(this, $module)
20
+
21
+ // if the user has not engaged with the cookie banner yet, listen for the cookie consent accept/reject events
22
+ // re-start the module if cookies are accepted or rejected on the current page – setting cookie preferences does not reload the page
23
+ window.addEventListener('cookie-consent', this.start)
24
+ window.addEventListener('cookie-reject', this.start)
19
25
  return
20
26
  }
21
27
  var cookieConsent = GOVUK.getConsentCookie()
@@ -50,6 +56,8 @@
50
56
  this.decorate = function (element, param) {
51
57
  var attribute = 'href'
52
58
  var attributeValue = element.getAttribute(attribute)
59
+ var cookieConsentParameterPattern = /cookie_consent=[^&]*/
60
+ var paramIsCookieConsent = param.match(cookieConsentParameterPattern)
53
61
 
54
62
  if (!attributeValue) {
55
63
  attribute = 'action'
@@ -58,13 +66,21 @@
58
66
 
59
67
  if (!attributeValue) { return }
60
68
 
61
- if (attributeValue.includes('?')) {
62
- attributeValue += '&' + param
63
- element.setAttribute(attribute, attributeValue)
69
+ var attributeHasCookieConsent = attributeValue.match(cookieConsentParameterPattern)
70
+
71
+ if (attributeHasCookieConsent && paramIsCookieConsent) {
72
+ // if the decorate function has received a cookie_consent parameter, but the target element already has a cookie_consent parameter, replace the existing parameter with the new value
73
+ attributeValue = attributeValue.replace(cookieConsentParameterPattern, param)
64
74
  } else {
65
- attributeValue += '?' + param
66
- element.setAttribute(attribute, attributeValue)
75
+ // otherwise, simply append the parameter to the target element href query string
76
+ if (attributeValue.includes('?')) {
77
+ attributeValue += '&' + param
78
+ } else {
79
+ attributeValue += '?' + param
80
+ }
67
81
  }
82
+
83
+ element.setAttribute(attribute, attributeValue)
68
84
  }
69
85
  }
70
86
 
@@ -97,6 +97,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
97
97
  this.$module.cookieBannerConfirmationMessage.focus()
98
98
  window.GOVUK.cookie('cookies_preferences_set', 'true', { days: 365 })
99
99
  window.GOVUK.setDefaultConsentCookie()
100
+ window.GOVUK.triggerEvent(window, 'cookie-reject')
100
101
  }
101
102
 
102
103
  CookieBanner.prototype.showConfirmationMessage = function () {
@@ -26,9 +26,9 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
26
26
  var html = document.createElement('div')
27
27
  html.innerHTML = newButton
28
28
  // test that the html returned contains the button component; if yes, swap the button for the updated version
29
- var responseHasButton = html.querySelector('form.gem-c-single-page-notification-button .gem-c-single-page-notification-button__submit')
30
- if (responseHasButton) {
31
- this.$module.outerHTML = newButton
29
+ var responseButtonContainer = html.querySelector('form.gem-c-single-page-notification-button')
30
+ if (responseButtonContainer) {
31
+ this.$module.parentNode.replaceChild(responseButtonContainer, this.$module)
32
32
  }
33
33
  }
34
34
  }
@@ -1,9 +1,12 @@
1
1
  <%
2
2
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
3
+ heading_helper = GovukPublishingComponents::Presenters::HeadingHelper.new(local_assigns)
3
4
 
4
5
  aria_controls ||= nil
5
6
  button_text ||= t("components.search_box.search_button")
6
7
  id ||= "search-main-" + SecureRandom.hex(4)
8
+ wrap_label_in_a_heading ||= false
9
+ label_margin_bottom ||= nil
7
10
  label_size ||= nil
8
11
  label_text ||= t("components.search_box.label")
9
12
  name ||= "q"
@@ -14,13 +17,6 @@
14
17
  data_attributes ||= {}
15
18
  data_attributes[:module] = 'gem-track-click'
16
19
 
17
- label_classes = []
18
- if (shared_helper.valid_heading_size?(label_size))
19
- label_classes << "govuk-label govuk-label--#{label_size}"
20
- else
21
- label_classes << "gem-c-search__label"
22
- end
23
-
24
20
  classes = %w[gem-c-search govuk-!-display-none-print]
25
21
  classes << (shared_helper.get_margin_top)
26
22
  classes << (shared_helper.get_margin_bottom) if local_assigns[:margin_bottom]
@@ -32,11 +28,31 @@
32
28
  classes << "gem-c-search--on-white"
33
29
  end
34
30
  classes << "gem-c-search--separate-label" if local_assigns.include?(:inline_label) or local_assigns.include?(:label_size)
31
+
32
+ label_classes = []
33
+ if (shared_helper.valid_heading_size?(label_size))
34
+ label_classes << "govuk-label govuk-label--#{label_size}"
35
+ else
36
+ label_classes << "gem-c-search__label"
37
+ end
38
+ label_classes << "govuk-!-margin-bottom-#{label_margin_bottom}" if [*1..9].include?(label_margin_bottom) and local_assigns.include?(:inline_label)
39
+
40
+ tag_label = capture do
41
+ tag.label({ for: id, class: label_classes }) do
42
+ label_text
43
+ end
44
+ end
35
45
  %>
36
46
 
37
47
  <div class="<%= classes.join(" ") %>" data-module="gem-toggle-input-class-on-focus">
38
- <%= tag.label({ for: id, class: label_classes }) do %>
39
- <%= label_text %>
48
+ <% if wrap_label_in_a_heading %>
49
+ <%= content_tag(shared_helper.get_heading_level, {
50
+ class: "govuk-!-margin-0",
51
+ }) do %>
52
+ <%= tag_label %>
53
+ <% end %>
54
+ <% else %>
55
+ <%= tag_label %>
40
56
  <% end %>
41
57
  <div class="gem-c-search__item-wrapper">
42
58
  <%= tag.input(
@@ -2,16 +2,18 @@
2
2
  component_helper = GovukPublishingComponents::Presenters::SinglePageNotificationButtonHelper.new(local_assigns)
3
3
  shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
4
4
 
5
- wrapper_classes = %w(gem-c-single-page-notification-button govuk-!-display-none-print)
5
+ wrapper_classes = %w(govuk-!-display-none-print)
6
6
  wrapper_classes << shared_helper.get_margin_bottom
7
7
  %>
8
8
  <% button_text = capture do %>
9
9
  <svg class="gem-c-single-page-notification-button__icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" height="18" width="18" viewBox="0 0 459.334 459.334"><path fill="currentColor" d="M177.216 404.514c-.001.12-.009.239-.009.359 0 30.078 24.383 54.461 54.461 54.461s54.461-24.383 54.461-54.461c0-.12-.008-.239-.009-.359H175.216zM403.549 336.438l-49.015-72.002v-89.83c0-60.581-43.144-111.079-100.381-122.459V24.485C254.152 10.963 243.19 0 229.667 0s-24.485 10.963-24.485 24.485v27.663c-57.237 11.381-100.381 61.879-100.381 122.459v89.83l-49.015 72.002a24.76 24.76 0 0 0 20.468 38.693H383.08a24.761 24.761 0 0 0 20.469-38.694z"/></svg><%= component_helper.button_text %>
10
10
  <% end %>
11
- <%= tag.form class: wrapper_classes, action: "/email/subscriptions/single-page/new", method: "POST", data: component_helper.data do %>
12
- <input type="hidden" name="base_path" value="<%= component_helper.base_path %>">
13
- <%= content_tag(:button, button_text, {
14
- class: "govuk-body-s gem-c-single-page-notification-button__submit",
15
- type: "submit",
16
- }) %>
11
+ <%= tag.div class: wrapper_classes, data: { module: "gem-track-click"} do %>
12
+ <%= tag.form class: "gem-c-single-page-notification-button", action: "/email/subscriptions/single-page/new", method: "POST", data: component_helper.data do %>
13
+ <input type="hidden" name="base_path" value="<%= component_helper.base_path %>">
14
+ <%= content_tag(:button, button_text, {
15
+ class: "govuk-body-s gem-c-single-page-notification-button__submit",
16
+ type: "submit",
17
+ }) %>
18
+ <% end %>
17
19
  <% end if component_helper.base_path %>
@@ -69,3 +69,28 @@ examples:
69
69
  Allows the label text size to be set to `xl`, `l`, `m`, or `s`. If this is set, then `inline_label` is automatically set to `false`.
70
70
  data:
71
71
  label_size: "xl"
72
+ wrap_label_inside_a_heading:
73
+ description: |
74
+ Puts the label inside a heading; heading level defaults to 2 if not set.
75
+
76
+ (The size of the label can still be set with `label_size` to appear more like a heading.)
77
+ data:
78
+ wrap_label_in_a_heading: true
79
+ heading_level: 1
80
+ with_margin_bottom:
81
+ description: |
82
+ Allows the spacing at the bottom of the component to be adjusted.
83
+
84
+ This accepts a number 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 no margin bottom.
85
+ data:
86
+ margin_bottom: 9
87
+ with_margin_bottom_for_the_label:
88
+ description: |
89
+ Allows the spacing between the label and the input be adjusted.
90
+
91
+ Requires `inline_label` to be false.
92
+
93
+ This accepts a number 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 no margin bottom.
94
+ data:
95
+ label_margin_bottom: 9
96
+ inline_label: false
@@ -87,7 +87,7 @@ en:
87
87
  statistics: Statistics
88
88
  worldwide: Worldwide
89
89
  layout_footer:
90
- copyright_html: <a class="govuk-footer__link govuk-footer__copyright-logo" href="http://www.nationalarchives.gov.uk/information-management/re-using-public-sector-information/copyright-and-re-use/crown-copyright/">© Crown copyright</a>
90
+ 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
91
  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
92
92
  support_links: Support links
93
93
  layout_for_public:
@@ -14,15 +14,12 @@ module GovukPublishingComponents
14
14
  end
15
15
 
16
16
  def data
17
- module_names = %w[gem-track-click]
18
- module_names << "single-page-notification-button" if js_enhancement
19
-
20
- @data_attributes[:label] = base_path
17
+ @data_attributes[:track_label] = base_path
21
18
  # data-action for tracking should have the format of e.g. "Unsubscribe-button-top", or "Subscribe-button-bottom"
22
19
  # when button_location is not present data-action will fall back to "Unsubscribe-button"/"Subscribe-button"
23
- @data_attributes[:action] = [button_type, "button", button_location].compact.join("-")
24
- @data_attributes[:module] = module_names.join(" ")
25
- @data_attributes[:category] = "Single-page-notification-button"
20
+ @data_attributes[:track_action] = [button_type, "button", button_location].compact.join("-")
21
+ @data_attributes[:module] = "single-page-notification-button" if js_enhancement
22
+ @data_attributes[:track_category] = "Single-page-notification-button"
26
23
  # This attribute is passed through to the personalisation API to ensure when a new button is returned from the API, it has the same button_location
27
24
  @data_attributes[:button_location] = button_location
28
25
  @data_attributes
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "27.14.1".freeze
2
+ VERSION = "27.14.2".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.14.1
4
+ version: 27.14.2
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-22 00:00:00.000000000 Z
11
+ date: 2021-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config