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

Output class indicating whether an image has a caption #10445

Closed
JohnONolan opened this issue Feb 2, 2019 · 4 comments
Closed

Output class indicating whether an image has a caption #10445

JohnONolan opened this issue Feb 2, 2019 · 4 comments
Labels
affects:editor Work relating to the Koenig Editor css / design / mobile Minor UI issues

Comments

@JohnONolan
Copy link
Member

I think I have a reasonable case for adding a class of .kg-card-hascaption conditionally to a parent card wrapper, when it has a caption.

Example:
image

In this example I'm trying to achieve different layouts for different image sizes. The first image is width-full - where the figcaption overlaid with position absolute. Easy.

The second image is width-wide - which I'm trying to style so that it has room for a caption somewhere around it.

After a solid hour or two, though, I don't think this is going to be doable without a class on the parent. I've cycled through absolute, flexbox, grid, and table display modes - and all of them get you close, but none of them can account for a layout which automatically adapts to whether or not a caption is present.

Short version: All the layout modes require setting fixed proportions to manually "make space" for the caption, with the exception of flexbox -- and flexbox has a bug which destroys image aspect ratio when an img is a flex-child.

So I think the only way to reasonably achieve this for the parent to specify whether it has a caption, which would open up far, far more options for how to display images with captions.

An additional benefit here would be that we'd actually double the number of available image styles/sizes, because every size can have a unique appearance with/without caption - which also opens up a lot more flexibility in terms of design.

TLDR: I think cards should output an additional class based on whether or not they contain a caption

/cc @peterzimon @kevinansfield

@JohnONolan JohnONolan added themes affects:editor Work relating to the Koenig Editor css / design / mobile Minor UI issues labels Feb 2, 2019
@JohnONolan
Copy link
Member Author

Aside: Can we just take a moment to appreciate the colour palette of these labels

@kevinansfield
Copy link
Contributor

kevinansfield commented Feb 11, 2019

Although the change is fairly straightforward it requires the html field for every post to be re-generated which is usually something we only do for major version bumps due to the potential impact for sites with many posts.

In the meantime it's possible to add the class using a small bit of client-side JS:

document.querySelectorAll('figure.kg-card').forEach(function (figure) {
  if (figure.querySelector('figcaption')) {
    figure.classList.add('kg-card-hascaption');
  }
});

Or maybe

document.querySelectorAll('figure.kg-card figcaption').forEach(function (figcaption) {
  figcaption.closest('figure').classList.add('kg-card-hascaption');
});

@JohnONolan
Copy link
Member Author

@kevinansfield That's fine. How would I trigger manual re-generation? Just update a post?

kevinansfield added a commit that referenced this issue Feb 25, 2019
…ptions

refs #10445
- adds class to card renderers
- class will only be present on new or re-saved posts
@kevinansfield
Copy link
Contributor

@JohnONolan the change is now in master so new/re-saved posts will start having the class after the next release.

I've added the full migration to our 3.0 tracking list so I'll close this now.

kevinansfield added a commit to kevinansfield/Ghost that referenced this issue Sep 16, 2019
refs TryGhost#10445

- re-generates HTML for every post so that they are using the most recent Koenig renderer output
kevinansfield added a commit that referenced this issue Sep 16, 2019
refs #10445

- re-generates HTML for every post so that they are using the most recent Koenig renderer output
kevinansfield added a commit to kevinansfield/Koenig that referenced this issue Mar 20, 2020
…ptions

refs TryGhost/Ghost#10445
- adds class to card renderers
- class will only be present on new or re-saved posts
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects:editor Work relating to the Koenig Editor css / design / mobile Minor UI issues
Projects
None yet
Development

No branches or pull requests

2 participants