Skip to content

Commit 6f14dbe

Browse files
jmooringgideonstar-git
authored andcommitted
tpl/tplimpl: Fix full screen option in vimeo and youtube shortcodes
Closes #13531 Co-authored-by: Stefan Ritter <60473875+gideonstar-git@users.noreply.github.com>
1 parent 8d2379b commit 6f14dbe

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

‎tpl/tplimpl/embedded/templates/shortcodes/vimeo.html‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
Accepts named or positional arguments. If positional, order is id, class,
55
title, then loading.
66

7-
@param {string} [class] The class attribute of the wrapping div element. When specified, removes the style attributes from the iframe element and its wrapping div element.
87
@param {string} [id] The video id. Optional if the id is provided as first positional argument.
8+
@param {string} [class] The class attribute of the wrapping div element. When specified, removes the style attributes from the iframe element and its wrapping div element.
99
@param {string} [loading=eager] The loading attribute of the iframe element.
1010
@param {string} [title=Vimeo video] The title attribute of the iframe element.
11+
@param {bool} [allowFullScreen=true] Whether the iframe element can activate full screen mode.
1112

1213
@returns {template.HTML}
1314

@@ -19,11 +20,24 @@
1920
{{- if $pc.Simple }}
2021
{{- template "_internal/shortcodes/vimeo_simple.html" . }}
2122
{{- else }}
23+
{{- $dnt := cond $pc.EnableDNT 1 0 }}
24+
2225
{{- $id := or (.Get "id") (.Get 0) "" }}
2326
{{- $class := or (.Get "class") (.Get 1) "" }}
2427
{{- $title := or (.Get "title") (.Get 2) "Vimeo video" }}
2528
{{- $loading := or (.Get "loading") (.Get 3) "eager" }}
26-
{{- $dnt := cond $pc.EnableDNT 1 0 }}
29+
{{- $allowFullScreen := or (.Get "allowFullScreen") (.Get 4) true }}
30+
31+
{{- if in (slice "false" false 0) ($.Get "allowFullScreen") }}
32+
{{- $allowFullScreen = false }}
33+
{{- else if in (slice "true" true 1) ($.Get "allowFullScreen") }}
34+
{{- $allowFullScreen = true }}
35+
{{- end }}
36+
37+
{{- $iframeAllowList := "" }}
38+
{{- if $allowFullScreen }}
39+
{{- $iframeAllowList = "fullscreen" }}
40+
{{- end }}
2741

2842
{{- $divStyle := "position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;" }}
2943
{{- $iframeStyle := "position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" }}
@@ -36,11 +50,12 @@
3650
{{- else }}
3751
style="{{ $divStyle | safeCSS }}"
3852
{{- end }}>
39-
<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen
53+
<iframe
4054
src="{{- $src }}"
4155
{{- if not $class }}
4256
style="{{ $iframeStyle | safeCSS }}"
4357
{{- end }}
58+
{{- with $iframeAllowList }} allow="{{ . }}" {{- end }}
4459
{{- with $loading }} loading="{{ . }}" {{- end }}
4560
{{- with $title }} title="{{ . }}" {{- end }}>
4661
</iframe>

‎tpl/tplimpl/embedded/templates/shortcodes/youtube.html‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{{- with $id := or (.Get "id") (.Get 0) }}
2828

2929
{{- /* Set defaults. */}}
30-
{{- $allowFullScreen := "allowfullscreen" }}
30+
{{- $allowFullScreen := true }}
3131
{{- $autoplay := 0 }}
3232
{{- $class := "" }}
3333
{{- $controls := 1 }}
@@ -37,12 +37,11 @@
3737
{{- $mute := 0 }}
3838
{{- $start := 0 }}
3939
{{- $title := "YouTube video" }}
40+
{{- $iframeAllowList := "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" }}
4041

4142
{{- /* Get arguments. */}}
42-
{{- if in (slice "false" false 0) ($.Get "allowFullScreen") }}
43-
{{- $allowFullScreen = "" }}
44-
{{- else if in (slice "true" true 1) ($.Get "allowFullScreen") }}
45-
{{- $allowFullScreen = "allowfullscreen" }}
43+
{{- if in (slice "true" true 1) ($.Get "allowFullScreen") }}
44+
{{- $iframeAllowList = printf "%s; fullscreen" $iframeAllowList }}
4645
{{- end }}
4746
{{- if in (slice "false" false 0) ($.Get "autoplay") }}
4847
{{- $autoplay = 0 }}
@@ -99,7 +98,6 @@
9998
{{- if $class }}
10099
{{- $iframeStyle = "" }}
101100
{{- end }}
102-
{{- $allow := "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" }}
103101
{{- $referrerpolicy := "strict-origin-when-cross-origin" }}
104102

105103
{{- /* Render. */ -}}
@@ -108,8 +106,7 @@
108106
{{- with $divStyle }} style="{{ . | safeCSS }}" {{- end -}}
109107
>
110108
<iframe
111-
{{- with $allow }} allow="{{ . }}" {{- end }}
112-
{{- with $allowFullScreen }} allowfullscreen="{{ . }}" {{- end }}
109+
{{- with $iframeAllowList }} allow="{{ . }}" {{- end }}
113110
{{- with $loading }} loading="{{ . }}" {{- end }}
114111
{{- with $referrerpolicy }} referrerpolicy="{{ . }}" {{- end }}
115112
{{- with $src }} src="{{ . }}" {{- end }}

‎tpl/tplimpl/shortcodes_integration_test.go‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -464,26 +464,38 @@ func TestVimeoShortcode(t *testing.T) {
464464

465465
files := `
466466
-- hugo.toml --
467-
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
467+
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
468468
privacy.vimeo.simple = false
469-
-- content/_index.md --
469+
-- content/p1.md --
470470
---
471-
title: home
471+
title: p1
472472
---
473473
{{< vimeo 55073825 >}}
474-
-- layouts/index.html --
474+
-- content/p2.md --
475+
---
476+
title: p2
477+
---
478+
{{< vimeo id=55073825 allowFullScreen=true >}}
479+
-- content/p3.md --
480+
---
481+
title: p3
482+
---
483+
{{< vimeo id=55073825 allowFullScreen=false >}}
484+
-- layouts/_default/single.html --
475485
Hash: {{ .Content | hash.XxHash }}
476486
Content: {{ .Content }}
477487
`
478488

479489
// Regular mode
480490
b := hugolib.Test(t, files)
481-
b.AssertFileContent("public/index.html", "d1f592d2256ac3ff")
491+
b.AssertFileContent("public/p1/index.html", "f7687b0c4e85b7d4")
492+
b.AssertFileContent("public/p2/index.html", "f7687b0c4e85b7d4")
493+
b.AssertFileContent("public/p3/index.html", "caca499bdc7f1e1e")
482494

483495
// Simple mode
484496
files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true")
485497
b = hugolib.Test(t, files)
486-
b.AssertFileContent("public/index.html", "c5bf16d87e2a370b")
498+
b.AssertFileContent("public/p1/index.html", "c5bf16d87e2a370b")
487499

488500
// Simple mode with non-existent id
489501
files = strings.ReplaceAll(files, "{{< vimeo 55073825 >}}", "{{< vimeo __id_does_not_exist__ >}}")
@@ -675,12 +687,12 @@ title: p2
675687

676688
b := hugolib.Test(t, files)
677689

678-
b.AssertFileContent("public/p1/index.html", "a0a6f5ade9cc3a9f")
690+
b.AssertFileContent("public/p1/index.html", "5156322adda11844")
679691
b.AssertFileContent("public/p2/index.html", "289c655e727e596c")
680692

681693
files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true")
682694

683695
b = hugolib.Test(t, files)
684-
b.AssertFileContent("public/p1/index.html", "b76d790c20d2bd04")
696+
b.AssertFileContent("public/p1/index.html", "599174706edf963a")
685697
b.AssertFileContent("public/p2/index.html", "a6db910a9cf54bc1")
686698
}

0 commit comments

Comments
 (0)