|
13 | 13 | )
|
14 | 14 | ) -}}
|
15 | 15 | */}}
|
| 16 | +{{- $globals := .globals -}} |
16 | 17 | {{- $context := .context | default dict -}}
|
17 | 18 | {{- $options := .options | default dict -}}
|
18 | 19 | {{- $params := (merge $context $options) -}}
|
19 | 20 | {{- $mime_type := $params.mime_type -}}
|
20 | 21 | {{- $class_name := $params.class_name -}}
|
21 | 22 | {{- $url := $params.src | default $params.url -}}
|
| 23 | +{{- $width := $params.width -}} |
| 24 | +{{- $height := $params.height -}} |
22 | 25 | {{- $loop := $params.loop | default true -}}
|
23 | 26 | {{- $autoplay := $params.autoplay | default true -}}
|
| 27 | +{{- $playsinline := $params.playsinline | default true -}} |
24 | 28 | {{- $controls := $params.controls | default false -}}
|
25 | 29 | {{- $poster := $params.poster | default false -}}
|
26 | 30 | {{- $muted := (or $autoplay $params.muted) -}}
|
| 31 | +{{- $loading := cond (eq $params.lazy true) "lazy" ($params.loading | default false) -}} |
| 32 | +{{- $preload := $params.preload | default false -}} |
27 | 33 |
|
28 | 34 | {{- $attributes := partialCached "utils/html/attribute" (dict
|
29 | 35 | "loop" $loop
|
|
35 | 41 | ) $params -}}
|
36 | 42 |
|
37 | 43 | {{- if in $mime_type "video" -}}
|
| 44 | + {{- $preload_attr := (dict |
| 45 | + "as" "image" |
| 46 | + "href" $poster |
| 47 | + ) -}} |
| 48 | + {{- if and $preload $poster (not (in ($globals.Scratch.Get "preload") $preload)) -}} |
| 49 | + {{- $globals.Scratch.Add "preload" (slice $preload) -}} |
| 50 | + {{- end -}} |
38 | 51 | <video {{$attributes}}>
|
39 |
| - <source src="{{- $url -}}" type="{{- $mime_type -}}"> |
| 52 | + {{- if eq $loading "lazy" -}} |
| 53 | + <source data-src="{{- $url -}}" type="{{- $mime_type -}}" /> |
| 54 | + {{- else -}} |
| 55 | + <source src="{{- $url -}}" type="{{- $mime_type -}}" /> |
| 56 | + {{- end -}} |
40 | 57 | </video>
|
41 | 58 | {{- end -}}
|
0 commit comments