Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show galleries as sliders #298

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 108 additions & 3 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ nav #redlib {
vertical-align: -2px;
}

figcaption {
margin-top: 5px;
figcaption p {
margin: 5px 0;
text-align: center;
}

Expand Down Expand Up @@ -1112,6 +1112,13 @@ a.search_subreddit:hover {
overflow: hidden;
}

.post_media_content:not(:has(.post_media_video)),
.post_media_video,
.gallery {
border: var(--panel-border);
border-radius: 5px;
}

.post_media_video {
min-width: 100px;
max-width: 100px;
Expand Down Expand Up @@ -1169,9 +1176,107 @@ a.search_subreddit:hover {
vertical-align: bottom;
}

.gallery {
display: flex;
flex-flow: row nowrap;
align-items: center;
overflow-x: auto;
scroll-snap-type: x mandatory;
overscroll-behavior-x: none;
background: var(--background);
transition: background 0.2s;
}

.post:hover .gallery {
background: var(--post);
}

.gallery figure {
flex: 1 0 100%;
scroll-snap-align: center;
scroll-snap-stop: always;
margin: 0;
}

.gallery_overlay {
flex: 1 0 100%;
height: 100%;
position: sticky;
left: 0;
margin-left: -100%;
pointer-events: none;
display: flex;
justify-content: center;
transition: opacity 0.2s;
}

.gallery:focus-within .gallery_overlay {
opacity: 0;
}

.gallery:not(:focus-within) .gallery_overlay * {
pointer-events: auto;
}

.gallery_length {
position: absolute;
right: 10px;
top: 10px;
padding: 10px;
text-align: center;
background-color: rgba(0, 0, 0, 0.8);
border-radius: 5px;
}

@supports not (animation-timeline: scroll()) {
.gallery_progress {
display: none;
}
}

.gallery_progress {
position: absolute;
bottom: 10px;
background-color: rgba(0, 0, 0, 0.8);
border: 10px solid transparent;
border-radius: 15px;
display: flex;
gap: 10px;
}

.gallery_dot,
.gallery_dot_indicator {
width: 10px;
height: 10px;
box-sizing: border-box;
border: 1px solid var(--text);
border-radius: 50%;
}

.gallery_dot_indicator {
background: var(--text);
position: absolute;
animation-name: galleryDotIndicatorScroll;
animation-timeline: scroll(inline nearest);
animation-timing-function: linear;
}

@keyframes galleryDotIndicatorScroll {
from {
left: 0;
}

to {
left: 100%;
transform: translateX(-100%);
}
}

.gallery img {
display: block;
margin: auto;
max-width: 100%;
vertical-align: bottom;
border-radius: 5px;
}

.gallery .outbound_url {
Expand Down
15 changes: 13 additions & 2 deletions templates/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,28 @@ <h1 class="post_title">
{% endif %}
{% else if post.post_type == "gallery" %}
<div class="gallery">
{% for image in post.gallery -%}
<div class="gallery_overlay" title="Hide overlay">
<div class="gallery_length" tabindex="-1">gallery<br>({{ post.gallery.len() }} images)</div>
<div class="gallery_progress" tabindex="-1">
<!-- {% for _ in 0..post.gallery.len() %}
<div class="gallery_dot"></div>
{% endfor %} -->
<div class="gallery_dot_indicator"></div>
</div>
</div>
{% for image in post.gallery -%}
<figure>
<a href="{{ image.url }}" ><img loading="lazy" alt="Gallery image" src="{{ image.url }}"/></a>
<figcaption>
{% if !image.caption.is_empty() %}
<p>{{ image.caption }}</p>
{% endif %}
{% if image.outbound_url.len() > 0 %}
<p><a class="outbound_url" href="{{ image.outbound_url }}" rel="nofollow">{{ image.outbound_url }}</a>
{% endif %}
</figcaption>
</figure>
{%- endfor %}
{%- endfor %}
</div>
{% else if post.post_type == "link" %}
<a id="post_url" href="{{ post.media.url }}" rel="nofollow">{{ post.media.url }}</a>
Expand Down
Loading