From 925ff6edcd05a39c669e25d2ead51afbd5d35161 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Sun, 8 Jan 2023 02:34:11 +0900 Subject: [PATCH] Implement image viewer (#363) --- static/css/style.css | 41 ++++++++++++++++++++++++++ templates/activities/_modal_image.html | 34 +++++++++++++++++++++ templates/activities/_post.html | 5 ++-- templates/base.html | 1 + templates/base_plain.html | 1 + 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 templates/activities/_modal_image.html diff --git a/static/css/style.css b/static/css/style.css index bb8ab07..e0e6a8a 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -1699,6 +1699,47 @@ form .post { transition: 0.2s; } +/* Image viewer */ +#image-viewer { + flex-direction: column; + justify-content: center; + align-items: center; + position: fixed; + top: 0; + left: 0; + margin: 0; + width: 100dvw; + height: 100dvh; + background: rgb(0 0 0 / 75%); + transition: opacity 350ms; + z-index: 100; +} + +#image-viewer picture, #image-viewer img { + display: block; +} + +#image-viewer img { + max-height: calc(100dvh - 8em); + max-width: 100dvw; +} + +#image-viewer figcaption { + width: 100%; + padding: 1em; + background-color: black; + color: var(--color-text-main); + text-align: center; +} + +#image-viewer button { + position: fixed; + right: 10px; + top: 10px; + color: var(--color-text-main); + background: transparent; + cursor: pointer; +} /* Accessibility */ .screenreader-text { diff --git a/templates/activities/_modal_image.html b/templates/activities/_modal_image.html new file mode 100644 index 0000000..9aff88c --- /dev/null +++ b/templates/activities/_modal_image.html @@ -0,0 +1,34 @@ + + diff --git a/templates/activities/_post.html b/templates/activities/_post.html index 38c0bc6..e3a6922 100644 --- a/templates/activities/_post.html +++ b/templates/activities/_post.html @@ -43,8 +43,9 @@
{% for attachment in post.attachments.all %} {% if attachment.is_image %} - - {{ attachment.name }} + + {{ attachment.name|default:'(no description)' }} {% elif attachment.is_video %} diff --git a/templates/base.html b/templates/base.html index 264beea..28014e7 100644 --- a/templates/base.html +++ b/templates/base.html @@ -73,6 +73,7 @@ {% block full_content %} + {% include 'activities/_modal_image.html' %} {% block pre_content %} {% endblock %}
diff --git a/templates/base_plain.html b/templates/base_plain.html index 53d77e8..e5496b4 100644 --- a/templates/base_plain.html +++ b/templates/base_plain.html @@ -27,6 +27,7 @@
+ {% include "activities/_modal_image.html" %} {% block content %} {% endblock %}