govuk_publishing_components 56.3.0 → 56.3.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/analytics-ga4/ga4-form-tracker.js +1 -1
- data/app/assets/javascripts/govuk_publishing_components/analytics-ga4/ga4-page-views.js +5 -1
- data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js +23 -0
- data/app/views/govuk_publishing_components/components/docs/govspeak.yml +19 -4
- data/lib/govuk_publishing_components/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d76c938f0964afb347980522c6baca92610afaf0d035ffde0f3d8b6bb8fcb03
|
4
|
+
data.tar.gz: d8da458559e80bde908f7d80abcf435df61b0c495bcd2d4348e2c39b49553978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fab8b889f851e16fa0bc0d0dfe3e79ca3140d26d10479bc9ebb99ed1395e6d65833ba4c224e85ad751352538731050b9d7408fc27b5265797a0a271b4ddae155
|
7
|
+
data.tar.gz: 5d07560bb97b95bcba67ae3b5fa4744b60994e5dae7c27f80175171df124eee3dab5b9534ce1d1c06b311b641f6b781688124f7e69d8622b84a3d2a5a32d73ae
|
@@ -86,7 +86,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
86
86
|
|
87
87
|
if (inputType === 'checkbox' && elem.checked) {
|
88
88
|
input.answer = labelText
|
89
|
-
} else if (inputNodename === 'SELECT' && elem.options[elem.selectedIndex].value) {
|
89
|
+
} else if (inputNodename === 'SELECT' && elem.options[elem.selectedIndex] && elem.options[elem.selectedIndex].value) {
|
90
90
|
input.answer = elem.options[elem.selectedIndex].text
|
91
91
|
} else if (inputTypes.indexOf(inputType) !== -1 && elem.value) {
|
92
92
|
if (this.includeTextInputValues || elem.hasAttribute('data-ga4-form-include-input')) {
|
@@ -67,7 +67,11 @@ window.GOVUK.analyticsGa4.analyticsModules = window.GOVUK.analyticsGa4.analytics
|
|
67
67
|
tool_name: this.getToolName(),
|
68
68
|
spelling_suggestion: this.getMetaContent('spelling-suggestion'),
|
69
69
|
discovery_engine_attribution_token: this.getMetaContent('discovery-engine-attribution-token'),
|
70
|
-
canonical_url: this.getCanonicalHref()
|
70
|
+
canonical_url: this.getCanonicalHref(),
|
71
|
+
|
72
|
+
user_created_at: this.getMetaContent('user-created-at'),
|
73
|
+
user_organisation_name: this.getMetaContent('user-organisation-name'),
|
74
|
+
user_role: this.getMetaContent('user-role')
|
71
75
|
}
|
72
76
|
}
|
73
77
|
window.GOVUK.analyticsGa4.core.sendData(data)
|
data/app/assets/javascripts/govuk_publishing_components/lib/govspeak/youtube-link-enhancement.js
CHANGED
@@ -6,6 +6,7 @@
|
|
6
6
|
var YoutubeLinkEnhancement = function ($element, $classOverride) {
|
7
7
|
this.$element = $element
|
8
8
|
this.$classOverride = typeof $classOverride !== 'undefined' ? $classOverride : 'gem-c-govspeak__youtube-video'
|
9
|
+
this.punctuationRegex = /[\.!\?"']/g // eslint-disable-line no-useless-escape
|
9
10
|
}
|
10
11
|
|
11
12
|
YoutubeLinkEnhancement.prototype.init = function () {
|
@@ -18,11 +19,26 @@
|
|
18
19
|
this.startModule()
|
19
20
|
}
|
20
21
|
|
22
|
+
YoutubeLinkEnhancement.prototype.paragraphHasOtherContent = function (paragraph, link) {
|
23
|
+
return paragraph.innerHTML.replaceAll(this.punctuationRegex, '') !== link.outerHTML.replaceAll(this.punctuationRegex, '')
|
24
|
+
}
|
25
|
+
|
21
26
|
YoutubeLinkEnhancement.prototype.decorateLink = function () {
|
22
27
|
var $youtubeLinks = this.$element.querySelectorAll('a[href*="youtube.com"], a[href*="youtu.be"]')
|
23
28
|
for (var i = 0; i < $youtubeLinks.length; ++i) {
|
24
29
|
var $link = $youtubeLinks[i]
|
30
|
+
if (this.hasDisabledEmbed($link) || $link.getAttribute('href').includes('/playlist')) {
|
31
|
+
continue
|
32
|
+
}
|
33
|
+
|
25
34
|
var $linkParent = $link.closest('p')
|
35
|
+
|
36
|
+
// Only replace the <p> with a YT embed if the YT link is the only thing in the <p>.
|
37
|
+
// This prevents other content in the <p> being lost.
|
38
|
+
// However, if a <p> exists with only a YT link and punctuation, we do allow the punctuation characters to be lost to the YT embed.
|
39
|
+
if (this.paragraphHasOtherContent($linkParent, $link)) {
|
40
|
+
continue
|
41
|
+
}
|
26
42
|
var href = $link.getAttribute('href')
|
27
43
|
var text = $link.textContent
|
28
44
|
var placeholder = document.createElement('p')
|
@@ -89,6 +105,13 @@
|
|
89
105
|
var parentPara = $link.parentNode
|
90
106
|
var parentContainer = parentPara.parentNode
|
91
107
|
|
108
|
+
// Only replace the <p> with a YT embed if the YT link is the only thing in the <p>.
|
109
|
+
// This prevents other content in the <p> being lost.
|
110
|
+
// However, if a <p> exists with only a YT link and punctuation, we do allow the punctuation characters to be lost to the YT embed.
|
111
|
+
if (this.paragraphHasOtherContent(parentPara, $link)) {
|
112
|
+
return
|
113
|
+
}
|
114
|
+
|
92
115
|
var youtubeVideoContainer = document.createElement('div')
|
93
116
|
youtubeVideoContainer.className += this.$classOverride
|
94
117
|
youtubeVideoContainer.innerHTML = '<span id="' + elementId + '" data-video-id="' + id + '"></span>'
|
@@ -1025,16 +1025,31 @@ examples:
|
|
1025
1025
|
youtube_embed:
|
1026
1026
|
data:
|
1027
1027
|
block: |
|
1028
|
-
<p>This content has a YouTube video link, converted to an accessible embedded player by component JavaScript.</p>
|
1028
|
+
<p>This content has a YouTube video link, converted to an accessible embedded player by component JavaScript. Bear in mind that the link will not convert if the paragraph it is in contains other content.</p>
|
1029
1029
|
<p><a href="https://www.youtube.com/watch?v=y6hbrS3DheU">Operations: a developer's guide, by Anna Shipman</a></p>
|
1030
|
-
|
1030
|
+
youtube_embed_with_punctuation:
|
1031
|
+
description: YouTube links should still be enhanced if punctuation is in the same paragraph but outside the YT <a> tag.
|
1032
|
+
data:
|
1033
|
+
block: |
|
1034
|
+
<p>"<a href="https://www.youtube.com/watch?v=y6hbrS3DheU">Operations: a developer's guide, by Anna Shipman</a>."</p>
|
1035
|
+
youtube_embed_disabled_by_component:
|
1031
1036
|
data:
|
1032
1037
|
disable_youtube_expansions: true
|
1033
1038
|
block: |
|
1034
|
-
<p>This content has a YouTube video link, where the govspeak expansion has been disabled
|
1039
|
+
<p>This content has a YouTube video link, where the govspeak expansion has been disabled by the render statement for the component.</p>
|
1035
1040
|
<p><a href="https://www.youtube.com/watch?v=y6hbrS3DheU">Operations: a developer's guide, by Anna Shipman</a></p>
|
1041
|
+
youtube_embed_disabled_by_content:
|
1042
|
+
description: YouTube links should not become an embed if the YouTube link is in a paragraph with other content.
|
1043
|
+
data:
|
1044
|
+
block: |
|
1045
|
+
<p>This youtube video titled <a href="https://www.youtube.com/watch?v=y6hbrS3DheU">Operations: a developer's guide, by Anna Shipman</a> should stay as a link due to this non-link text existing in the paragraph.</p>
|
1046
|
+
youtube_embed_disabled_by_editors:
|
1047
|
+
description: Editors can disable YouTube link enhancement by using the `data-youtube-player="off"` HTML attribute.
|
1048
|
+
data:
|
1049
|
+
block: |
|
1050
|
+
<p><a href="https://www.youtube.com/watch?v=y6hbrS3DheU" data-youtube-player="off">Operations: a developer's guide, by Anna Shipman</a></p>
|
1036
1051
|
youtube_livestream:
|
1037
1052
|
data:
|
1038
1053
|
block: |
|
1039
|
-
<p>This content has a YouTube livestream link, converted to an accessible embedded player by component JavaScript.</p>
|
1054
|
+
<p>This content has a YouTube livestream link, converted to an accessible embedded player by component JavaScript. Bear in mind that the link will not convert if the paragraph it is in contains other content.</p>
|
1040
1055
|
<p><a href="https://www.youtube.com/embed/live_stream?channel=UCoMdktPbSTixAyNGwb-UYkQ">Livestream video</a></p>
|
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: 56.3.
|
4
|
+
version: 56.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
@@ -2039,7 +2039,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
2039
2039
|
- !ruby/object:Gem::Version
|
2040
2040
|
version: '0'
|
2041
2041
|
requirements: []
|
2042
|
-
rubygems_version: 3.6.
|
2042
|
+
rubygems_version: 3.6.9
|
2043
2043
|
specification_version: 4
|
2044
2044
|
summary: A gem to document components in GOV.UK frontend applications
|
2045
2045
|
test_files: []
|