govuk_publishing_components 28.6.0 → 28.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (24) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/javascripts/govuk_publishing_components/analytics/page-content.js +3 -3
  4. data/app/assets/javascripts/govuk_publishing_components/components/feedback.js +7 -6
  5. data/app/assets/javascripts/govuk_publishing_components/vendor/lux/lux-reporter.js +1796 -911
  6. data/app/models/govuk_publishing_components/component_docs.rb +4 -1
  7. data/app/views/govuk_publishing_components/components/_attachment.html.erb +3 -1
  8. data/app/views/govuk_publishing_components/components/_button.html.erb +3 -3
  9. data/app/views/govuk_publishing_components/components/_input.html.erb +3 -3
  10. data/app/views/govuk_publishing_components/components/_intervention.html.erb +2 -2
  11. data/app/views/govuk_publishing_components/components/_search.html.erb +2 -4
  12. data/app/views/govuk_publishing_components/components/_select.html.erb +15 -43
  13. data/app/views/govuk_publishing_components/components/_subscription_links.html.erb +7 -8
  14. data/app/views/govuk_publishing_components/components/docs/attachment.yml +11 -0
  15. data/app/views/govuk_publishing_components/components/docs/select.yml +1 -1
  16. data/config/initializers/assets.rb +1 -0
  17. data/lib/govuk_publishing_components/presenters/attachment.rb +23 -0
  18. data/lib/govuk_publishing_components/presenters/select_helper.rb +85 -0
  19. data/lib/govuk_publishing_components/version.rb +1 -1
  20. data/lib/govuk_publishing_components.rb +1 -1
  21. metadata +7 -37
  22. data/app/assets/javascripts/govuk_publishing_components/lib/header-navigation.js +0 -100
  23. data/lib/govuk_publishing_components/presenters/select.rb +0 -43
  24. data/lib/tasks/govuk_publishing_components_tasks.rake +0 -49
@@ -45,7 +45,10 @@ module GovukPublishingComponents
45
45
  end
46
46
 
47
47
  def parse_documentation(file)
48
- { id: File.basename(file, ".yml") }.merge(YAML.load_file(file)).with_indifferent_access
48
+ # Psych 4's YAML.unsafe_load_file === Psych 3's YAML.load_file
49
+ # but until we drop support for Ruby 2.7 and Ruby 3.0, we need to support both major versions of Psych
50
+ yaml = YAML.respond_to?(:unsafe_load_file) ? YAML.unsafe_load_file(file) : YAML.load_file(file)
51
+ { id: File.basename(file, ".yml") }.merge(yaml).with_indifferent_access
49
52
  end
50
53
 
51
54
  def app_documentation_directory
@@ -83,7 +83,9 @@
83
83
  <% end %>
84
84
  <% end %>
85
85
 
86
- <% if attachment.alternative_format_contact_email %>
86
+ <% if attachment.display_accessible_format_request_form_link? %>
87
+ <%= link_to "Request an accessible format of this document", "/contact/govuk/request-accessible-format?content_id=#{attachment.owning_document_content_id}&attachment_id=#{attachment.attachment_id}", class: "govuk-link" %>
88
+ <% elsif attachment.alternative_format_contact_email %>
87
89
  <%= tag.p t("components.attachment.request_format_text"), class: "gem-c-attachment__metadata" %>
88
90
  <%= render "govuk_publishing_components/components/details", {
89
91
  title: t("components.attachment.request_format_cta")
@@ -21,11 +21,11 @@
21
21
  %>
22
22
 
23
23
  <% if button.link? %>
24
- <%= link_to button_text, button.href, button.html_options %>
24
+ <%= link_to button_text, button.href, **button.html_options %>
25
25
  <% else %>
26
- <%= content_tag :button, button_text, button.html_options %>
26
+ <%= content_tag :button, button_text, **button.html_options %>
27
27
  <% end %>
28
28
 
29
29
  <% if button.info_text %>
30
- <%= tag.span button.info_text, button.info_text_options %>
30
+ <%= tag.span button.info_text, **button.info_text_options %>
31
31
  <% end %>
@@ -98,7 +98,7 @@
98
98
  } %>
99
99
  <% end %>
100
100
 
101
- <% input_tag = tag.input({
101
+ <% input_tag = tag.input(
102
102
  aria: {
103
103
  describedby: aria_described_by,
104
104
  controls: controls
@@ -116,8 +116,8 @@
116
116
  readonly: readonly,
117
117
  tabindex: tabindex,
118
118
  type: type,
119
- value: value,
120
- }) %>
119
+ value: value
120
+ ) %>
121
121
 
122
122
  <% if prefix && suffix %>
123
123
  <%= tag.div class: "govuk-input__wrapper" do %>
@@ -45,11 +45,11 @@
45
45
  section_options.merge!({ hidden: true }) if hide
46
46
  %>
47
47
  <% if suggestion_text || (suggestion_link_text && suggestion_link_url) %>
48
- <%= tag.section section_options do %>
48
+ <%= tag.section **section_options do %>
49
49
  <p class="govuk-body">
50
50
  <%= tag.span suggestion_text, class: "gem-c-intervention__textwrapper" if suggestion_text %>
51
51
  <% if suggestion_link_text && suggestion_link_url %>
52
- <%= tag.a suggestion_link_text, suggestion_tag_options %>
52
+ <%= tag.a suggestion_link_text, **suggestion_tag_options %>
53
53
  <% end %>
54
54
  </p>
55
55
 
@@ -39,7 +39,7 @@
39
39
  label_classes << "govuk-!-margin-bottom-#{label_margin_bottom}" if [*1..9].include?(label_margin_bottom) and local_assigns.include?(:inline_label)
40
40
 
41
41
  tag_label = capture do
42
- tag.label({ for: id, class: label_classes }) do
42
+ tag.label(for: id, class: label_classes) do
43
43
  label_text
44
44
  end
45
45
  end
@@ -47,9 +47,7 @@
47
47
 
48
48
  <div class="<%= classes.join(" ") %>" data-module="gem-toggle-input-class-on-focus">
49
49
  <% if wrap_label_in_a_heading %>
50
- <%= content_tag(shared_helper.get_heading_level, {
51
- class: "govuk-!-margin-0",
52
- }) do %>
50
+ <%= content_tag(shared_helper.get_heading_level, class: "govuk-!-margin-0") do %>
53
51
  <%= tag_label %>
54
52
  <% end %>
55
53
  <% else %>
@@ -1,67 +1,39 @@
1
1
  <%
2
- shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
3
-
4
- options ||= []
2
+ # select_helper.css_classes generates "gem-c-select"
5
3
  id ||= false
6
4
  label ||= false
7
- full_width ||= false
8
5
  name ||= id
9
6
  is_page_heading ||= false
10
- heading_size = false unless shared_helper.valid_heading_size?(heading_size)
11
- error_message ||= nil
12
- error_id ||= nil
13
- hint ||= nil
14
- hint_id ||= nil
15
-
16
- describedby = %w[]
17
-
18
- if error_message || error_id
19
- error_id = "error-#{SecureRandom.hex(4)}" unless error_id
20
- describedby << error_id
21
- end
22
-
23
- if hint
24
- hint_id = "hint-#{SecureRandom.hex(4)}" unless hint_id
25
- describedby << hint_id
26
- end
27
7
 
28
- aria_describedby = { describedby: describedby } if describedby
29
-
30
- css_classes = %w(govuk-form-group gem-c-select)
31
- css_classes << "govuk-form-group--error" if error_message
32
-
33
- select_classes = %w(govuk-select)
34
- select_classes << "gem-c-select__select--full-width" if full_width
35
- select_classes << "govuk-select--error" if error_id
36
-
37
- label_classes = %w(govuk-label)
38
- label_classes << "govuk-label--#{heading_size}" if heading_size
8
+ shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)
9
+ heading_size = false unless shared_helper.valid_heading_size?(heading_size)
10
+ select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(local_assigns)
39
11
 
40
- select_helper = GovukPublishingComponents::Presenters::SelectHelper.new(options)
12
+ aria_describedby = { describedby: select_helper.describedby }
41
13
  data_module = { module: "track-select-change" } unless select_helper.data_tracking?.eql?(false)
42
14
  %>
43
- <% if options.any? && id && label %>
44
- <%= content_tag :div, class: css_classes do %>
15
+ <% if select_helper.options.any? && id && label %>
16
+ <%= content_tag :div, class: select_helper.css_classes do %>
45
17
  <% if is_page_heading %>
46
- <%= tag.h1 label_tag(id, label, class: label_classes), class: "gem-c-title__text" %>
18
+ <%= tag.h1 label_tag(id, label, class: select_helper.label_classes), class: "gem-c-title__text" %>
47
19
  <% else %>
48
- <%= label_tag(id, label, class: label_classes) %>
20
+ <%= label_tag(id, label, class: select_helper.label_classes) %>
49
21
  <% end %>
50
22
 
51
- <% if hint %>
23
+ <% if select_helper.hint %>
52
24
  <%= render "govuk_publishing_components/components/hint", {
53
- id: hint_id,
25
+ id: select_helper.hint_id,
54
26
  text: hint
55
27
  } %>
56
28
  <% end %>
57
29
 
58
- <% if error_message %>
30
+ <% if select_helper.error_message %>
59
31
  <%= render "govuk_publishing_components/components/error_message", {
60
- id: error_id,
61
- text: error_message
32
+ id: select_helper.error_id,
33
+ text: select_helper.error_message
62
34
  } %>
63
35
  <% end %>
64
36
 
65
- <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_classes, data: data_module, aria: aria_describedby %>
37
+ <%= select_tag name, options_for_select(select_helper.option_markup, select_helper.selected_option), id: id, class: select_helper.select_classes, data: data_module, aria: aria_describedby %>
66
38
  <% end %>
67
39
  <% end %>
@@ -49,17 +49,16 @@
49
49
  <svg xmlns="http://www.w3.org/2000/svg" width="15" height="15" class="gem-c-subscription-links__icon" focusable="false" fill="currentColor" aria-hidden="true"><path d="M1.996 11A2 2 0 0 0 0 12.993c0 1.101.895 1.99 1.996 1.99 1.106 0 2-.889 2-1.99a2 2 0 0 0-2-1.993zM.002 5.097V7.97c1.872 0 3.632.733 4.958 2.059A6.984 6.984 0 0 1 7.015 15h2.888c0-5.461-4.443-9.903-9.9-9.903zM.006 0v2.876c6.676 0 12.11 5.44 12.11 12.124H15C15 6.731 8.273 0 .006 0z"/>
50
50
  </svg><%= sl_helper.feed_link_text %>
51
51
  <% end %>
52
- <%= tag.button feed_link_text, {
52
+ <%= tag.button(feed_link_text,
53
53
  class: "govuk-link govuk-link--no-underline gem-c-subscription-links__item #{brand_helper.color_class} gem-c-subscription-links__item--button",
54
54
  data: sl_helper.feed_link_data_attributes,
55
55
  lang: feed_link_text_locale
56
- } if sl_helper.feed_link_box_value %>
57
- <%= link_to feed_link_text, sl_helper.feed_link,
58
- {
59
- class: "govuk-link govuk-link--no-underline gem-c-subscription-links__item #{brand_helper.color_class} gem-c-subscription-links__item--link",
60
- data: sl_helper.feed_link_data_attributes,
61
- lang: feed_link_text_locale
62
- } unless sl_helper.feed_link_box_value %>
56
+ ) if sl_helper.feed_link_box_value %>
57
+ <%= link_to(feed_link_text, sl_helper.feed_link,
58
+ class: "govuk-link govuk-link--no-underline gem-c-subscription-links__item #{brand_helper.color_class} gem-c-subscription-links__item--link",
59
+ data: sl_helper.feed_link_data_attributes,
60
+ lang: feed_link_text_locale
61
+ ) unless sl_helper.feed_link_box_value %>
63
62
  </li>
64
63
  <% end %>
65
64
  </ul>
@@ -76,6 +76,17 @@ examples:
76
76
  content_type: application/pdf
77
77
  file_size: 20000
78
78
  alternative_format_contact_email: defra.helpline@defra.gsi.gov.uk
79
+ with_link_to_request_accessible_format_form:
80
+ data:
81
+ attachment:
82
+ title: "Department for Transport information asset register"
83
+ url: https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/747661/department-for-transport-information-asset-register.csv
84
+ filename: department-for-transport-information-asset-register.csv
85
+ content_type: application/pdf
86
+ file_size: 20000
87
+ owning_document_content_id: 456_abc
88
+ attachment_id: 123
89
+ alternative_format_contact_email: alternative.formats@education.gov.uk
79
90
  with_data_attributes:
80
91
  data:
81
92
  attachment:
@@ -47,7 +47,7 @@ examples:
47
47
  data:
48
48
  id: 'dropdown2-1'
49
49
  label: 'Choose your preferred thing'
50
- hint_text: 'You might need some more information here'
50
+ hint: 'You might need some more information here'
51
51
  hint_id: 'optional-hint-id'
52
52
  options:
53
53
  - text: 'Something'
@@ -10,6 +10,7 @@ Rails.application.config.assets.precompile += %w[
10
10
  govuk_publishing_components/vendor/lux/lux-reporter.js
11
11
  govuk_publishing_components/vendor/lux/lux-measurer.js
12
12
  govuk_publishing_components/all_components.js
13
+ govuk_publishing_components/dependencies.js
13
14
  govuk_publishing_components/ie.js
14
15
  govuk_publishing_components/modules.js
15
16
  govuk_publishing_components/vendor/modernizr.js
@@ -1,6 +1,16 @@
1
1
  module GovukPublishingComponents
2
2
  module Presenters
3
3
  class Attachment
4
+ # DfE, DWP, DHSC, HMRC, DVSA and PHE are taking part in a pilot to use a form
5
+ # rather than direct email for users to request accessible formats. When the pilot
6
+ # scheme is rolled out further this can be removed.
7
+ EMAILS_IN_ACCESSIBLE_FORMAT_REQUEST_PILOT = %w[alternative.formats@education.gov.uk
8
+ accessible.formats@dwp.gov.uk
9
+ publications@dhsc.gov.uk
10
+ different.format@hmrc.gov.uk
11
+ gov.uk.publishing@dvsa.gov.uk
12
+ publications@phe.gov.uk].freeze
13
+
4
14
  delegate :opendocument?, :document?, :spreadsheet?, to: :content_type
5
15
 
6
16
  attr_reader :attachment_data
@@ -8,6 +18,7 @@ module GovukPublishingComponents
8
18
  # Expects a hash of attachment data
9
19
  # * title and url are required
10
20
  # * content_type, filename, file_size, number of pages, alternative_format_contact_email can be provided
21
+ # * attachment_id and owning_document_content_id are required to use the accessible format request form
11
22
  def initialize(attachment_data)
12
23
  @attachment_data = attachment_data.with_indifferent_access
13
24
  end
@@ -47,6 +58,14 @@ module GovukPublishingComponents
47
58
  attachment_data[:alternative_format_contact_email]
48
59
  end
49
60
 
61
+ def attachment_id
62
+ attachment_data[:attachment_id]
63
+ end
64
+
65
+ def owning_document_content_id
66
+ attachment_data[:owning_document_content_id]
67
+ end
68
+
50
69
  def reference
51
70
  reference = []
52
71
  reference << "ISBN #{attachment_data[:isbn]}" if attachment_data[:isbn].present?
@@ -71,6 +90,10 @@ module GovukPublishingComponents
71
90
  attachment_data[:command_paper_number].present? || attachment_data[:hoc_paper_number].present? || attachment_data[:unnumbered_command_paper].eql?(true) || attachment_data[:unnumbered_hoc_paper].eql?(true)
72
91
  end
73
92
 
93
+ def display_accessible_format_request_form_link?
94
+ EMAILS_IN_ACCESSIBLE_FORMAT_REQUEST_PILOT.include?(alternative_format_contact_email) && owning_document_content_id.present? && attachment_id.present?
95
+ end
96
+
74
97
  class SupportedContentType
75
98
  attr_reader :content_type_data
76
99
 
@@ -0,0 +1,85 @@
1
+ module GovukPublishingComponents
2
+ module Presenters
3
+ class SelectHelper
4
+ attr_reader :options, :option_markup, :selected_option, :error_message, :error_id, :hint, :hint_id, :describedby
5
+
6
+ def initialize(local_assigns)
7
+ @options = local_assigns[:options] || []
8
+ @error_message = local_assigns[:error_message]
9
+ @error_id = local_assigns[:error_id] || nil
10
+ @hint = local_assigns[:hint] || nil
11
+ @hint_id = local_assigns[:hint_id] || nil
12
+ @heading_size = local_assigns[:heading_size]
13
+ @full_width = local_assigns[:full_width] || false
14
+ @option_markup = get_options
15
+ @describedby = get_describedby
16
+ end
17
+
18
+ def data_tracking?
19
+ @options.any? { |item| item[:data_attributes] && item[:data_attributes][:track_category] && item[:data_attributes][:track_action] }
20
+ end
21
+
22
+ def css_classes
23
+ classes = %w[govuk-form-group gem-c-select]
24
+ classes << "govuk-form-group--error" if @error_message
25
+ classes
26
+ end
27
+
28
+ def select_classes
29
+ classes = %w[govuk-select]
30
+ classes << "gem-c-select__select--full-width" if @full_width
31
+ classes << "govuk-select--error" if @error_id
32
+ classes
33
+ end
34
+
35
+ def label_classes
36
+ classes = %w[govuk-label]
37
+ classes << "govuk-label--#{@heading_size}" if @heading_size
38
+ classes
39
+ end
40
+
41
+ private
42
+
43
+ def get_options
44
+ return if options.nil?
45
+
46
+ options.map do |option|
47
+ @selected_option = option[:value] if option[:selected]
48
+ [
49
+ option[:text],
50
+ option[:value],
51
+ options_data_attribute(option[:data_attributes]),
52
+ ]
53
+ end
54
+ end
55
+
56
+ def options_data_attribute(attributes)
57
+ return {} if attributes.nil?
58
+
59
+ attrs = {}
60
+ attributes.each do |key, value|
61
+ key_name = "data-#{key.to_s.split('_').join('-')}"
62
+ attrs[key_name] = value.is_a?(Hash) ? value.to_json : value
63
+ end
64
+
65
+ attrs
66
+ end
67
+
68
+ def get_describedby
69
+ describedby = %w[]
70
+
71
+ if @error_message || @error_id
72
+ @error_id ||= "error-#{SecureRandom.hex(4)}"
73
+ describedby << @error_id
74
+ end
75
+
76
+ if @hint
77
+ @hint_id ||= "hint-#{SecureRandom.hex(4)}"
78
+ describedby << @hint_id
79
+ end
80
+
81
+ describedby
82
+ end
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukPublishingComponents
2
- VERSION = "28.6.0".freeze
2
+ VERSION = "28.8.1".freeze
3
3
  end
@@ -21,7 +21,7 @@ require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_pri
21
21
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
22
22
  require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_topic"
23
23
  require "govuk_publishing_components/presenters/checkboxes_helper"
24
- require "govuk_publishing_components/presenters/select"
24
+ require "govuk_publishing_components/presenters/select_helper"
25
25
  require "govuk_publishing_components/presenters/meta_tags"
26
26
  require "govuk_publishing_components/presenters/content_item"
27
27
  require "govuk_publishing_components/presenters/translation_nav_helper"
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: 28.6.0
4
+ version: 28.8.1
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-02-21 00:00:00.000000000 Z
11
+ date: 2022-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_app_config
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '6'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '6'
83
83
  - !ruby/object:Gem::Dependency
@@ -192,34 +192,6 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: jasmine
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 3.10.0
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 3.10.0
209
- - !ruby/object:Gem::Dependency
210
- name: jasmine_selenium_runner
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 3.0.0
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 3.0.0
223
195
  - !ruby/object:Gem::Dependency
224
196
  name: percy-capybara
225
197
  requirement: !ruby/object:Gem::Requirement
@@ -514,7 +486,6 @@ files:
514
486
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/barchart-enhancement.js
515
487
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/magna-charta.js
516
488
  - app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js
517
- - app/assets/javascripts/govuk_publishing_components/lib/header-navigation.js
518
489
  - app/assets/javascripts/govuk_publishing_components/lib/initial-focus.js
519
490
  - app/assets/javascripts/govuk_publishing_components/lib/primary-links.js
520
491
  - app/assets/javascripts/govuk_publishing_components/lib/toggle-input-class-on-focus.js
@@ -962,14 +933,13 @@ files:
962
933
  - lib/govuk_publishing_components/presenters/public_layout_helper.rb
963
934
  - lib/govuk_publishing_components/presenters/related_navigation_helper.rb
964
935
  - lib/govuk_publishing_components/presenters/schema_org.rb
965
- - lib/govuk_publishing_components/presenters/select.rb
936
+ - lib/govuk_publishing_components/presenters/select_helper.rb
966
937
  - lib/govuk_publishing_components/presenters/shared_helper.rb
967
938
  - lib/govuk_publishing_components/presenters/single_page_notification_button_helper.rb
968
939
  - lib/govuk_publishing_components/presenters/step_by_step_nav_helper.rb
969
940
  - lib/govuk_publishing_components/presenters/subscription_links_helper.rb
970
941
  - lib/govuk_publishing_components/presenters/translation_nav_helper.rb
971
942
  - lib/govuk_publishing_components/version.rb
972
- - lib/tasks/govuk_publishing_components_tasks.rake
973
943
  - node_modules/axe-core/CHANGELOG.md
974
944
  - node_modules/axe-core/CONTRIBUTING.md
975
945
  - node_modules/axe-core/LICENSE
@@ -2017,14 +1987,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
2017
1987
  requirements:
2018
1988
  - - ">="
2019
1989
  - !ruby/object:Gem::Version
2020
- version: '2.6'
1990
+ version: '2.7'
2021
1991
  required_rubygems_version: !ruby/object:Gem::Requirement
2022
1992
  requirements:
2023
1993
  - - ">="
2024
1994
  - !ruby/object:Gem::Version
2025
1995
  version: '0'
2026
1996
  requirements: []
2027
- rubygems_version: 3.0.3.1
1997
+ rubygems_version: 3.3.8
2028
1998
  signing_key:
2029
1999
  specification_version: 4
2030
2000
  summary: A gem to document components in GOV.UK frontend applications
@@ -1,100 +0,0 @@
1
- /* eslint-disable no-var */
2
-
3
- // used by the header navigation from govuk_template
4
-
5
- (function () {
6
- 'use strict'
7
-
8
- if (document.querySelectorAll && document.addEventListener) {
9
- var els = document.querySelectorAll('.js-header-toggle')
10
- for (var i = 0; i < els.length; i++) {
11
- // Reassign current index to bypass rules in Chrome and Firefox around indexed property setting
12
- var thisEl = els[i]
13
-
14
- // If the element is an a tag, convert it to a button
15
- // This is to target instances where we want to change behaviour between a js and a no-js view eg: the search button on the mobile menu for some government pages. On no-js it's just a link to /search
16
- // This swaps a link for no-js to a button, making it interactable. Using a link for interactivity is poor accessibility as it's a misuse of the link tag and can be confusing to assistive tech users
17
-
18
- if (thisEl.tagName === 'A') {
19
- var attributes = thisEl.attributes
20
- var button = document.createElement('button')
21
-
22
- for (var k = 0; k < attributes.length; k++) {
23
- var thisAttr = attributes[k].name
24
-
25
- if (thisAttr === 'href') {
26
- if (button.getAttribute('data-search-toggle-for')) {
27
- continue
28
- } else {
29
- button.setAttribute('data-search-toggle-for', thisEl.getAttribute('href').substr(1))
30
- }
31
- } else if (thisAttr !== 'data-button-text') {
32
- button.setAttribute(thisAttr, thisEl.getAttribute(thisAttr))
33
- }
34
- }
35
-
36
- button.innerText = thisEl.getAttribute('data-button-text') || thisEl.innerText
37
-
38
- thisEl.parentNode.replaceChild(button, thisEl)
39
- thisEl = button
40
- }
41
-
42
- thisEl.addEventListener('click', function (e) {
43
- e.preventDefault()
44
- var target = document.getElementById(this.getAttribute('data-search-toggle-for'))
45
- var targetClass = target.getAttribute('class') || ''
46
- var sourceClass = this.getAttribute('class') || ''
47
- var isSearchToggle = sourceClass.match('search-toggle')
48
- var showText = this.getAttribute('data-show-text') || 'Show search'
49
- var hideText = this.getAttribute('data-hide-text') || 'Hide search'
50
- var buttonName = this.getAttribute('data-button-name') || 'menu'
51
-
52
- if (targetClass.indexOf('js-visible') !== -1) {
53
- target.setAttribute('class', targetClass.replace(/(^|\s)js-visible(\s|$)/, ''))
54
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
55
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Closed', { label: 'none' })
56
- }
57
- } else {
58
- target.setAttribute('class', targetClass + ' js-visible')
59
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
60
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Opened', { label: 'none' })
61
- }
62
- }
63
- if (sourceClass.indexOf('js-visible') !== -1) {
64
- this.setAttribute('class', sourceClass.replace(/(^|\s)js-visible(\s|$)/, ''))
65
- if (isSearchToggle) {
66
- this.innerText = showText
67
- }
68
- } else {
69
- this.setAttribute('class', sourceClass + ' js-visible')
70
- if (isSearchToggle) {
71
- this.innerText = hideText
72
- }
73
- }
74
- this.setAttribute('aria-expanded', this.getAttribute('aria-expanded') !== 'true')
75
- target.setAttribute('aria-hidden', target.getAttribute('aria-hidden') === 'false')
76
- })
77
- }
78
- }
79
- }).call(this)
80
-
81
- ;(function () {
82
- var $menuToggleButtons = document.querySelectorAll('.govuk-js-header-toggle')
83
-
84
- for (var j = 0; j < $menuToggleButtons.length; j++) {
85
- var element = $menuToggleButtons[j]
86
-
87
- element.addEventListener('click', function (event) {
88
- var buttonName = event.target.getAttribute('data-button-name') || 'menu'
89
- var expanded = event.target.getAttribute('aria-expanded')
90
-
91
- if (window.GOVUK.analytics && window.GOVUK.analytics.trackEvent) {
92
- if (expanded === 'true') {
93
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Closed', { label: 'none' })
94
- } else {
95
- window.GOVUK.analytics.trackEvent('headerClicked', buttonName + 'Opened', { label: 'none' })
96
- }
97
- }
98
- })
99
- }
100
- })()
@@ -1,43 +0,0 @@
1
- module GovukPublishingComponents
2
- module Presenters
3
- class SelectHelper
4
- attr_reader :options, :option_markup, :selected_option
5
-
6
- def initialize(options)
7
- @options = options
8
- @option_markup = get_options
9
- end
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
-
15
- private
16
-
17
- def get_options
18
- return if options.nil?
19
-
20
- options.map do |option|
21
- @selected_option = option[:value] if option[:selected]
22
- [
23
- option[:text],
24
- option[:value],
25
- options_data_attribute(option[:data_attributes]),
26
- ]
27
- end
28
- end
29
-
30
- def options_data_attribute(attributes)
31
- return {} if attributes.nil?
32
-
33
- attrs = {}
34
- attributes.each do |key, value|
35
- key_name = "data-#{key.to_s.split('_').join('-')}"
36
- attrs[key_name] = value.is_a?(Hash) ? value.to_json : value
37
- end
38
-
39
- attrs
40
- end
41
- end
42
- end
43
- end