summaryrefslogtreecommitdiff
path: root/web/template/status_attachment.tmpl
blob: 6f50412295b811b03ba284ab38540ebb593e39ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{{- /*
// GoToSocial
// Copyright (C) GoToSocial Authors admin@gotosocial.org
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/ -}}

{{- define "preview" }}
{{- if and .PreviewURL .Meta.Small.Width }}
<img
    src="{{- .PreviewURL -}}"
    loading="lazy"
    {{- if .Description }}
    alt="{{- .Description -}}"
    {{- end }}
    width="{{- .Meta.Small.Width -}}"
    height="{{- .Meta.Small.Height -}}"
    data-blurhash-hash="{{- .Blurhash -}}"
    data-sensitive="{{- .Sensitive -}}"
    {{- if or (ne .Meta.Focus.X 0.0) (ne .Meta.Focus.Y 0.0) }}
    data-object-position="{{ objectPosition .Meta.Focus.X .Meta.Focus.Y }}"
    {{- else }}
    {{- end }}
/>
{{- else }}
<img
    src="/assets/logo.webp"
    loading="lazy"
    {{- if .Description }}
    alt="{{- .Description -}}"
    {{- end }}
    width="518"
    height="460"
/>
{{- end }}
{{- end }}

{{- with . }}
<div class="media-wrapper">
    <details class="{{- .Item.Type -}}-spoiler media-spoiler" {{- if not .Item.Sensitive }} open{{- end -}}>
        <summary
            {{- if .Item.Description }}
            title="{{- .Item.Description -}}"
            {{- end }}
        >
            <div class="show sensitive button" aria-hidden="true">Show sensitive</div>
            {{- with . }}
            {{- /*
                IMPORTANT: Button semantics and aria labels in "eye button" class below are added in
                frontend/index.js, as the button doesn't function as a button without javascript.
            */ -}}
            {{- end }}
            <span class="eye button">
                <i class="hide fa fa-fw fa-eye-slash" aria-hidden="true"></i>
                <i class="show fa fa-fw fa-eye" aria-hidden="true"></i>
            </span>
            {{- if and (not (eq .Item.Type "unknown")) .Item.Meta.Small.Width }}
            <div
                class="blurhash-container"
                data-blurhash-width="{{- .Item.Meta.Small.Width -}}"
                data-blurhash-height="{{- .Item.Meta.Small.Height -}}"
                data-blurhash-hash="{{- .Item.Blurhash -}}"
                data-blurhash-aspect="{{- .Item.Meta.Small.Aspect -}}"
                {{- if or (ne .Item.Meta.Focus.X 0.0) (ne .Item.Meta.Focus.Y 0.0) }}
                data-blurhash-object-position="{{ objectPosition .Item.Meta.Focus.X .Item.Meta.Focus.Y }}"
                {{- else }}
                {{- end }}
            ></div>
            {{- end }}
        </summary>
        {{- if or (eq .Item.Type "video") (eq .Item.Type "gifv") }}
        <video
            {{- if eq .Item.Type "video" }}
            preload="none"
            class="plyr-video photoswipe-slide"
            {{- else }}
            preload="auto"
            muted
            autoplay
            loop
            class="plyr-video photoswipe-slide gifv"
            {{- end }}
            controls
            playsinline
            data-pswp-index="{{- .Index -}}"
            data-pswp-parent-status="{{- .Item.ParentStatusLink -}}"
            data-pswp-attachment-id="{{- .Item.ID -}}"
            poster="{{- .Item.PreviewURL -}}"
            data-pswp-width="{{- .Item.Meta.Original.Width -}}px"
            data-pswp-height="{{- .Item.Meta.Original.Height -}}px"
            {{- if .Item.Description }}
            alt="{{- .Item.Description -}}"
            title="{{- .Item.Description -}}"
            {{- end }}
        >
            <source type="{{- .Item.MIMEType -}}" src="{{- .Item.URL -}}"/>
        </video>
        {{- else if eq .Item.Type "audio" }}
        <video
            preload="none"
            class="plyr-video photoswipe-slide"
            controls
            playsinline
            data-pswp-index="{{- .Index -}}"
            data-pswp-parent-status="{{- .Item.ParentStatusLink -}}"
            data-pswp-attachment-id="{{- .Item.ID -}}"
            {{- if and .Item.PreviewURL .Item.Meta.Small.Width }}
            poster="{{- .Item.PreviewURL -}}"
            data-pswp-width="{{- .Item.Meta.Small.Width -}}px"
            data-pswp-height="{{- .Item.Meta.Small.Height -}}px"
            {{- else }}
            poster="/assets/logo.webp"
            data-pswp-width="518px"
            data-pswp-height="460px"
            {{- end }}
            {{- if .Item.Description }}
            alt="{{- .Item.Description -}}"
            title="{{- .Item.Description -}}"
            {{- end }}
        >
            <source type="{{- .Item.MIMEType -}}" src="{{- .Item.URL -}}"/>
        </video>
        {{- else if eq .Item.Type "image" }}
        <a
            class="photoswipe-slide"
            data-pswp-index="{{- .Index -}}"
            data-pswp-parent-status="{{- .Item.ParentStatusLink -}}"
            data-pswp-attachment-id="{{- .Item.ID -}}"
            href="{{- .Item.URL -}}"
            target="_blank"
            data-pswp-width="{{- .Item.Meta.Original.Width -}}px"
            data-pswp-height="{{- .Item.Meta.Original.Height -}}px"
            data-cropped="true"
            {{- if .Item.Description }}
            title="{{- .Item.Description -}}"
            {{- end }}
        >
            {{- with .Item }}
            {{- include "preview" . | indent 3 }}
            {{- end }}
        </a>
        {{- else }}
        <a
            class="unknown-attachment"
            href="{{- .Item.RemoteURL -}}"
            rel="nofollow noreferrer noopener"
            target="_blank"
            {{- if .Item.Description }}
            title="Open external media: {{ .Item.Description -}}&#10;&#13;{{- .Item.RemoteURL -}}"
            {{- else }}
            title="Open external media.&#10;&#13;{{- .Item.RemoteURL -}}"
            {{- end }}
        >
            <div class="placeholder" aria-hidden="true">
                <i class="placeholder-external-link fa fa-external-link"></i>
                <i class="placeholder-icon fa fa-file-text"></i>
                <div class="placeholder-link-to">External media</div>
            </div>
        </a>
        {{- end }}
    </details>
</div>
{{- end }}