[frontend] Sensitive media spoilers (#752)

* sensitive media spoilers

* small tweaks, use pointer-events (thanks @owl!)

* allow hiding all media

* add button roles

* add tabindices

* s/Show media/Show sensitive media/

* show hovering alt-text on hidden sensitive images

Co-authored-by: tobi <31960611+tsmethurst@users.noreply.github.com>
This commit is contained in:
f0x52 2022-08-14 19:22:13 +02:00 committed by GitHub
parent bfcd80a0f2
commit 52fe681ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 27 deletions

View file

@ -68,6 +68,9 @@ $status_focus_bg: $bg_accent;
$status_unfocus_bg: $sloth_gray2_darker3; $status_unfocus_bg: $sloth_gray2_darker3;
$status_info_fg: #CBCBD7; $status_info_fg: #CBCBD7;
$bg_no_img_desc: $sloth_orange2;
$bg_sensitive: $sloth_gray2_darker15;
$boxshadow: 0 0.4rem 1rem -0.1rem rgba(0,0,0,0.15); $boxshadow: 0 0.4rem 1rem -0.1rem rgba(0,0,0,0.15);
$boxshadow_border: 0.08rem solid $sloth_gray2_darker5; $boxshadow_border: 0.08rem solid $sloth_gray2_darker5;

View file

@ -173,7 +173,7 @@ main {
.media { .media {
margin-top: 0.6rem; margin-top: 0.6rem;
border-radius: 0.2rem; border-radius: $br;
grid-column: span 3; grid-column: span 3;
display: grid; display: grid;
grid-template-columns: 50% 50%; grid-template-columns: 50% 50%;
@ -181,24 +181,101 @@ main {
overflow: hidden; overflow: hidden;
gap: 0.3rem; gap: 0.3rem;
a { .media-wrapper {
position: relative; position: relative;
} }
&.single .media-wrapper {
grid-column: span 2;
}
&.odd .media-wrapper:first-child, &.double .media-wrapper {
grid-row: span 2;
}
.open, .open .button {
display: none;
}
.closed {
z-index: 2;
}
input.sensitive-checkbox:checked { /* Media is shown */
& ~ .sensitive {
.closed {
transition: 0.8s;
pointer-events: none;
opacity: 0;
& > * {
display: none;
}
}
.open {
display: flex;
justify-content: flex-start;
.button {
align-self: flex-start;
display: initial;
z-index: 4;
}
}
}
}
.sensitive {
position: absolute;
height: 100%;
width: 100%;
.open, .closed {
display: flex;
position: absolute;
height: 100%;
width: 100%;
justify-content: center;
padding: 1rem;
label {
z-index: 3;
}
}
.closed {
transition: 0.3s;
background: $bg_sensitive;
@supports (backdrop-filter: blur(2rem)) {
background: transparent;
backdrop-filter: blur(2rem);
}
.button {
align-self: center;
justify-self: center;
}
}
}
.no-image-desc { .no-image-desc {
color: $button_fg;
display: flex; display: flex;
position: absolute; position: absolute;
bottom: 0.1rem; bottom: 0.1rem;
right: 0.4rem; right: 0.4rem;
color: white; margin-bottom: 0.4rem;
background: $blue; margin-right: 0.4rem;
padding: 0.2rem 0.4rem; background: $bg_no_img_desc;
padding: 0.1rem 0.45rem;
border-radius: 100%; border-radius: 100%;
border: 0.2rem solid $button_fg;
z-index: 3; z-index: 3;
i.fa { i.fa {
display: block; display: block;
line-height: 1.3rem; line-height: 1.6rem;
} }
span { span {
@ -219,14 +296,6 @@ main {
height: 100%; height: 100%;
object-fit: cover; object-fit: cover;
} }
&.single a {
grid-column: span 2;
}
&.odd a:first-child, &.double a {
grid-row: span 2;
}
} }
.info { .info {
@ -244,7 +313,7 @@ main {
} }
grid-column: span 3; grid-column: span 3;
margin-top: 0.5rem; margin-top: 1.5rem;
flex-wrap: wrap; flex-wrap: wrap;
div.stats::after { div.stats::after {
@ -313,8 +382,8 @@ main {
} }
.media { .media {
grid-auto-rows: 1fr; /* grid-auto-rows: 1fr; */
max-height: 120rem; /* max-height: 120rem; */
} }
} }
} }

View file

@ -7,7 +7,7 @@
<input class="spoiler" id="hideSpoiler-{{.ID}}" type="checkbox" style="display: none" aria-hidden="true" checked="true" /> <input class="spoiler" id="hideSpoiler-{{.ID}}" type="checkbox" style="display: none" aria-hidden="true" checked="true" />
<div class="spoiler"> <div class="spoiler">
<span class="spoiler-text">{{.SpoilerText}}</span> <span class="spoiler-text">{{.SpoilerText}}</span>
<label class="button spoiler-label" for="hideSpoiler-{{.ID}}">Toggle visibility</label> <label class="button spoiler-label" for="hideSpoiler-{{.ID}}" tabindex="0">Toggle visibility</label>
</div> </div>
{{end}} {{end}}
<div class="content"> <div class="content">
@ -15,16 +15,29 @@
</div> </div>
</div> </div>
{{with .MediaAttachments}} {{with .MediaAttachments}}
<div class="media photoswipe-gallery {{(len .) | oddOrEven }}{{if eq (len .) 1}} single{{end}}{{if eq (len .) 2}} double{{end}}"> <div class="media photoswipe-gallery {{(len .) | oddOrEven }}{{if eq (len .) 1}} single{{end}}{{if eq (len .) 2}} double{{end}}">
{{range .}} {{range .}}
<a href="{{.URL}}" target="_blank" title="{{.Description}}" data-pswp-width="{{.Meta.Original.Width}}px" data-pswp-height="{{.Meta.Original.Height}}px"> <div class="media-wrapper">
{{if not .Description}} {{if not .Description}}
<div class="no-image-desc" aria-hidden="true" ><i class="fa fa-info-circle"></i><span>Missing image description</span></div> <div class="no-image-desc" aria-hidden="true" ><i class="fa fa-info-circle"></i><span>Missing image description</span></div>
{{end}} {{end}}
<img src="{{.PreviewURL}}" alt="{{.Description}}"/> <input type="checkbox" id="sensitiveMedia-{{.ID}}" class="sensitive-checkbox hidden" {{if not $.Sensitive}}checked{{end}}/>
</a> <div class="sensitive">
{{end}} <div class="open">
<label for="sensitiveMedia-{{.ID}}" class="button" role="button" tabindex="0">
<i class="fa fa-eye-slash" title="Hide sensitive media"></i>
</label>
</div>
<div class="closed" {{if .Description}}title="{{.Description}}"{{end}}>
<label for="sensitiveMedia-{{.ID}}" class="button" role="button" tabindex="0">Show sensitive media</label>
</div>
</div>
<a href="{{.URL}}" target="_blank" {{if .Description}}title="{{.Description}}"{{end}} data-pswp-width="{{.Meta.Original.Width}}px" data-pswp-height="{{.Meta.Original.Height}}px">
<img src="{{.PreviewURL}}" {{if .Description}}alt="{{.Description}}"{{end}} data-blurhash="{{.Blurhash}}"/>
</a>
</div> </div>
{{end}}
</div>
{{end}} {{end}}
</div> </div>
<div class="info"> <div class="info">