Skip to content

Commit 6492d83

Browse files
author
Ben Zörb
committed
fix(media): adds preload fix to c-image
1 parent f649960 commit 6492d83

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

templates/theme-default/layouts/partials/components/c-image.html

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,51 @@
2121
{{- end -}}
2222
{{- end -}}
2323

24+
{{- $different_ratios := and $has_mobile $has_desktop -}}
25+
26+
2427
<figure class="c-image{{ range $modifier }} c-image--{{ . }}{{ end }}{{ with $class_name }} {{ . }}{{end}}">
25-
{{- with $image_mobile -}}
26-
{{- partial "utils/asset" (dict
27-
"globals" $globals
28-
"context" .
29-
"options" (merge $params (dict
30-
"class_name" (print "c-image__asset" (cond $has_desktop " md:u-hidden" "") )
31-
))
32-
) -}}
33-
{{- end -}}
34-
{{- with $image_desktop -}}
35-
{{- partial "utils/asset" (dict
36-
"globals" $globals
37-
"context" .
38-
"options" (merge $params (dict
39-
"class_name" (print "c-image__asset" (cond $has_mobile " -md:u-hidden" "") )
40-
))
41-
) -}}
28+
{{ if $different_ratios }}
29+
<picture class="c-image__asset">
30+
{{- partial "utils/asset/image/sources" (dict
31+
"globals" $globals
32+
"context" $image_mobile
33+
"options" (merge $params (dict
34+
"media" "(max-width: 767px)"
35+
))
36+
) -}}
37+
{{- partial "utils/asset/image/sources" (dict
38+
"globals" $globals
39+
"context" $image_desktop
40+
"options" (merge $params (dict
41+
"media" "(min-width: 768px)"
42+
))
43+
) -}}
44+
{{- partial "utils/asset/image/img" (dict
45+
"globals" $globals
46+
"context" $image_desktop
47+
"options" $params
48+
) -}}
49+
</picture>
50+
{{ else }}
51+
{{- with $image_mobile -}}
52+
{{- partial "utils/asset" (dict
53+
"globals" $globals
54+
"context" .
55+
"options" (merge $params (dict
56+
"class_name" (print "c-image__asset" (cond $has_desktop " md:u-hidden" "") )
57+
))
58+
) -}}
59+
{{- end -}}
60+
{{- with $image_desktop -}}
61+
{{- partial "utils/asset" (dict
62+
"globals" $globals
63+
"context" .
64+
"options" (merge $params (dict
65+
"class_name" (print "c-image__asset" (cond $has_mobile " -md:u-hidden" "") )
66+
))
67+
) -}}
68+
{{- end -}}
4269
{{- end -}}
4370
{{- with $caption -}}
4471
<figcaption>{{ . }}</figcaption>

templates/theme-default/layouts/partials/components/c-media.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{{- end -}}
3232
{{- if $different_ratios -}}
3333
{{- if $only_img -}}
34-
<picture class="c-media__asset{{ with $class_name }} {{ . }}{{ end }}">
34+
<picture class="c-media__asset">
3535
{{- partial "utils/asset/image/sources" (dict
3636
"globals" $globals
3737
"context" $media_mobile

0 commit comments

Comments
 (0)