From f6715aac3d3e079baa792895d626bba5cb3edbe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Wersd=C3=B6rfer?= Date: Sat, 25 Nov 2023 06:57:55 +0100 Subject: [PATCH] #109 add width and heigth attributes --- cast/blocks.py | 14 ++++++++++++++ cast/static/js/cast/gallery.js | 2 ++ cast/templates/cast/image/image.html | 2 ++ 3 files changed, 18 insertions(+) diff --git a/cast/blocks.py b/cast/blocks.py index ced726ac..f819b3c8 100644 --- a/cast/blocks.py +++ b/cast/blocks.py @@ -117,6 +117,20 @@ def sizes(self) -> str: return "100vw" return f"{jpg_renditions[0].width}px" + @property + def width(self) -> int: + jpg_renditions = self.renditions["jpeg"] + if len(jpg_renditions) == 0: + return 0 + return jpg_renditions[0].width + + @property + def height(self) -> int: + jpg_renditions = self.renditions["jpeg"] + if len(jpg_renditions) == 0: + return 0 + return jpg_renditions[0].height + class CastImageChooserBlock(ImageChooserBlock): """ diff --git a/cast/static/js/cast/gallery.js b/cast/static/js/cast/gallery.js index c32f501d..0d38d335 100644 --- a/cast/static/js/cast/gallery.js +++ b/cast/static/js/cast/gallery.js @@ -27,6 +27,8 @@ function setModalImage(el) { modalImage.attr('src', curImage.data('modal-src')) modalImage.attr('srcset', curImage.data('modal-srcset')) modalImage.attr('sizes', curImage.data('modal-sizes')) + modalImage.attr('width', curImage.data('modal-width')) + modalImage.attr('height', curImage.data('modal-height')) modalImage.attr('alt', curImage.attr('alt')) // set link for modal image modalImage.parent().parent().attr('href', thumbnailPicture.parent().data("full")) diff --git a/cast/templates/cast/image/image.html b/cast/templates/cast/image/image.html index 2a261003..129e473a 100644 --- a/cast/templates/cast/image/image.html +++ b/cast/templates/cast/image/image.html @@ -13,6 +13,8 @@ src="{{ value.thumbnail.src.jpeg }}" srcset="{{ value.thumbnail.srcset.jpeg }}" sizes="{{ value.thumbnail.sizes }}" + width="{{ value.thumbnail.width }}" + height="{{ value.thumbnail.height }}" loading="lazy" >