Skip to content

Commit

Permalink
#109 add width and heigth attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ephes committed Nov 25, 2023
1 parent a4e2d98 commit f6715aa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cast/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
2 changes: 2 additions & 0 deletions cast/static/js/cast/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions cast/templates/cast/image/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
</picture>
Expand Down

0 comments on commit f6715aa

Please sign in to comment.