govuk_publishing_components 13.5.1 → 13.5.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 +4 -4
- data/app/assets/javascripts/govuk_publishing_components/components/select.js +50 -0
- data/app/views/govuk_publishing_components/components/_accessible_autocomplete.html.erb +1 -0
- data/app/views/govuk_publishing_components/components/_select.html.erb +2 -1
- data/app/views/govuk_publishing_components/components/docs/accessible_autocomplete.yml +1 -1
- data/app/views/govuk_publishing_components/components/docs/select.yml +37 -10
- data/lib/govuk_publishing_components/presenters/select.rb +5 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db548793e2560002edb6bc2ac4fc0cf0fbcb48342d76c008de00f7b4e3519b4e
|
4
|
+
data.tar.gz: 7ff2b9a1602ed29bc5badfc740ec73cc615d0659c38d5441595d0b78b0a5ee68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f0a65ebf42f6cbbe6cf61b1e0be7b51964d4d6ab0219b2fae6a2b30f4f1d0cf8995722afbdb5098e0ca0b7f38a5fca9648a8592dba73850e44cda849f1105f5
|
7
|
+
data.tar.gz: 3fd2cc7380e755078aa4da8fa86a0af6cc9bd83144944f0cb1d154e4e363491ecb1278a5543d3c2f8abaedce4f3ddc8997d75f96bdaf77356eebea72cde9933a
|
@@ -0,0 +1,50 @@
|
|
1
|
+
window.GOVUK = window.GOVUK || {};
|
2
|
+
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
3
|
+
|
4
|
+
(function (Modules) {
|
5
|
+
'use strict';
|
6
|
+
|
7
|
+
Modules.TrackSelectChange = function () {
|
8
|
+
this.start = function (element) {
|
9
|
+
element.change(function(e) {
|
10
|
+
var selectedOption = $(this).find(":selected");
|
11
|
+
var trackable = '[data-track-category][data-track-action]';
|
12
|
+
|
13
|
+
if (selectedOption.is(trackable)) {
|
14
|
+
fireTrackingChange(selectedOption);
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
18
|
+
function fireTrackingChange(element) {
|
19
|
+
var options = {transport: 'beacon'},
|
20
|
+
category = element.attr('data-track-category'),
|
21
|
+
action = element.attr('data-track-action'),
|
22
|
+
label = element.attr('data-track-label'),
|
23
|
+
value = element.attr('data-track-value'),
|
24
|
+
dimension = element.attr('data-track-dimension'),
|
25
|
+
dimensionIndex = element.attr('data-track-dimension-index'),
|
26
|
+
extraOptions = element.attr('data-track-options');
|
27
|
+
|
28
|
+
if (label) {
|
29
|
+
options.label = label;
|
30
|
+
}
|
31
|
+
|
32
|
+
if (value) {
|
33
|
+
options.value = value;
|
34
|
+
}
|
35
|
+
|
36
|
+
if (dimension && dimensionIndex) {
|
37
|
+
options['dimension' + dimensionIndex] = dimension;
|
38
|
+
}
|
39
|
+
|
40
|
+
if (extraOptions) {
|
41
|
+
$.extend(options, JSON.parse(extraOptions));
|
42
|
+
}
|
43
|
+
|
44
|
+
if (GOVUK.analytics && GOVUK.analytics.trackEvent) {
|
45
|
+
GOVUK.analytics.trackEvent(category, action, options);
|
46
|
+
}
|
47
|
+
};
|
48
|
+
};
|
49
|
+
};
|
50
|
+
})(window.GOVUK.Modules);
|
@@ -4,13 +4,14 @@
|
|
4
4
|
label ||= false
|
5
5
|
|
6
6
|
select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(options)
|
7
|
+
data_module = "data-module=track-select-change" unless select_helper.data_tracking?.eql?(false)
|
7
8
|
%>
|
8
9
|
<% if options.any? && id && label %>
|
9
10
|
<div class="govuk-form-group gem-c-select">
|
10
11
|
<label class="govuk-label" for="<%= id %>">
|
11
12
|
<%= label %>
|
12
13
|
</label>
|
13
|
-
<select class="govuk-select" id="<%= id %>" name="<%= id %>">
|
14
|
+
<select class="govuk-select" id="<%= id %>" name="<%= id %>" <%= data_module %> >
|
14
15
|
<%= options_for_select(select_helper.option_markup, select_helper.selected_option) %>
|
15
16
|
</select>
|
16
17
|
</div>
|
@@ -13,7 +13,7 @@ examples:
|
|
13
13
|
data:
|
14
14
|
label:
|
15
15
|
text: 'Countries'
|
16
|
-
options: [['', ''], ['France', 'fr'], ['Germany', 'de'], ['Sweden', 'se'], ['Switzerland', 'ch'], ['United Kingdom', 'gb'], ['United States', 'us']]
|
16
|
+
options: [['', ''], ['France', 'fr'], ['Germany', 'de'], ['Sweden', 'se'], ['Switzerland', 'ch'], ['United Kingdom', 'gb'], ['United States', 'us'], ['The Separate Customs Territory of Taiwan, Penghu, Kinmen, and Matsu (Chinese Taipei)', 'tw']]
|
17
17
|
with_unique_identifier:
|
18
18
|
data:
|
19
19
|
id: 'unique-autocomplete'
|
@@ -31,25 +31,52 @@ examples:
|
|
31
31
|
selected: true
|
32
32
|
- text: 'Option three'
|
33
33
|
value: 'option3'
|
34
|
-
|
35
|
-
description:
|
34
|
+
with_tracking:
|
35
|
+
description: 'Tracking can be enabled on the select component by passing a minimum of data_track_category and data_track_action. Other tracking attributes are optional. Note: tracking events do not currently fire within the component guide.'
|
36
36
|
data:
|
37
37
|
id: 'dropdown3'
|
38
|
-
label: 'With
|
38
|
+
label: 'With tracking enabled'
|
39
39
|
options:
|
40
40
|
- text: 'Option one'
|
41
41
|
value: 'option1'
|
42
42
|
data_attributes:
|
43
|
-
track_category:
|
44
|
-
|
43
|
+
track_category: 'relatedLinkClicked'
|
44
|
+
track_action: 1.1
|
45
|
+
track_label: '/link-1'
|
46
|
+
track_options:
|
47
|
+
dimension28: 1
|
48
|
+
dimension29: 'Link 1'
|
45
49
|
- text: 'Option two'
|
46
50
|
value: 'option2'
|
51
|
+
data_attributes:
|
52
|
+
track_category: 'relatedLinkClicked'
|
53
|
+
track_action: 1.2
|
54
|
+
track_label: '/link-2'
|
55
|
+
track_options:
|
56
|
+
dimension28: 2
|
57
|
+
dimension29: 'Link 2'
|
47
58
|
- text: 'Option three'
|
48
59
|
value: 'option3'
|
49
60
|
data_attributes:
|
50
|
-
track_category: '
|
51
|
-
track_action: 1.
|
52
|
-
track_label: '/
|
61
|
+
track_category: 'relatedLinkClicked'
|
62
|
+
track_action: 1.3
|
63
|
+
track_label: '/link-3'
|
53
64
|
track_options:
|
54
|
-
dimension28:
|
55
|
-
dimension29: '
|
65
|
+
dimension28: 3
|
66
|
+
dimension29: 'Link 3'
|
67
|
+
with_data_attributes:
|
68
|
+
description: Other data attributes can be passed to the component if needed.
|
69
|
+
data:
|
70
|
+
id: 'dropdown4'
|
71
|
+
label: 'With data attributes'
|
72
|
+
options:
|
73
|
+
- text: 'Option one'
|
74
|
+
value: 'option1'
|
75
|
+
data_attributes:
|
76
|
+
another_attribute: "attribute 1"
|
77
|
+
something_else: "attribute 2"
|
78
|
+
- text: 'Option two'
|
79
|
+
value: 'option2'
|
80
|
+
- text: 'Option three'
|
81
|
+
value: 'option3'
|
82
|
+
|
@@ -8,6 +8,10 @@ module GovukPublishingComponents
|
|
8
8
|
@option_markup = get_options
|
9
9
|
end
|
10
10
|
|
11
|
+
def data_tracking?
|
12
|
+
@options.any? { |item| item[:data_attributes] && item[:data_attributes][:track_category] && item[:data_attributes][:track_action] }
|
13
|
+
end
|
14
|
+
|
11
15
|
private
|
12
16
|
|
13
17
|
def get_options
|
@@ -31,6 +35,7 @@ module GovukPublishingComponents
|
|
31
35
|
key_name = "data-#{key.to_s.split('_').join('-')}"
|
32
36
|
attrs[key_name] = value.is_a?(Hash) ? value.to_json : value
|
33
37
|
end
|
38
|
+
|
34
39
|
attrs
|
35
40
|
end
|
36
41
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 13.5.
|
4
|
+
version: 13.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -316,6 +316,7 @@ files:
|
|
316
316
|
- app/assets/javascripts/govuk_publishing_components/components/feedback.js
|
317
317
|
- app/assets/javascripts/govuk_publishing_components/components/initial-focus.js
|
318
318
|
- app/assets/javascripts/govuk_publishing_components/components/radio.js
|
319
|
+
- app/assets/javascripts/govuk_publishing_components/components/select.js
|
319
320
|
- app/assets/javascripts/govuk_publishing_components/components/step-by-step-nav.js
|
320
321
|
- app/assets/javascripts/govuk_publishing_components/dependencies.js
|
321
322
|
- app/assets/javascripts/govuk_publishing_components/lib/current-location.js
|