-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add caption support to the Gallery block in <amp-carousel> and fix displaying Gallery block as carousel in WP 5.3 #3285
Conversation
For images in a gallery that have a caption, display them when in an <amp-carousel>.
There are probably more styling considerations with this. Sometimes the caption overlaps the Simply placing the caption on top of the |
… an example." This reverts commit 0b0b2fd.
Couldn't Get Styling To Work With Core Themes I couldn't get the captions to look good on all of the Core themes, and having them look good on all themes would probably be even harder. Maybe a CSS specialist could help here. Also, I tried placing the caption above the Here are the displays with the current state of the PR (without the scrim): Twenty FifteenTwenty SixteenTwenty SeventeenTwenty NineteenSteps To Reproduce
Of course, galleries could have any combination of image sizes, but the screenshots above all use 600 x 400 images to simplify this. |
BeforeThe plugin output the <amp-carousel type="slides" ...>
<amp-img ...>
</amp-carousel> After (with captions)With this PR, the plugin outputs something like: <amp-carousel type="slides" ...>
<div class="slide">
<amp-img ...>
<div class="amp-wp-gallery-caption">
This is a caption
</div>
</div>
</amp-carousel> (Though the AMP runtime adds a lot of tags, like It looks like amp-carousels with captions have to have something like a But on the Core themes like Twenty Fifteen and Twenty Nineteen, I couldn't find a way to style the caption so it appears in the same place, or at least looks good. And ensuring that captions look good on any theme would probably be much harder. I'm not sure if there's a solution for this 😄 |
Also, please do |
I've been unable, time wise, to look into this more deeply but the prospect of not only adding but modifying these is of great importance to several of my clients. |
@kienstra I suppose this will then need UX support. |
Hi @westonruter, If it's alright, we've asked Bart Makos to work on this, as he's much better with CSS than me. Though I'm not sure there is a good solution for captions, where they'll look good on any theme. |
This is starting to sound fun. I love the word CSS!!!
…On Tue, Oct 1, 2019, 6:36 PM Ryan Kienstra ***@***.***> wrote:
Hi @westonruter <https://github.com/westonruter>,
Yeah, that makes sense.
If it's alright, we've asked Bart Makos to work on this, as he's much
better with CSS than me.
Though I'm not sure there is a good solution
<#3285 (comment)>
for captions, where they'll look good on any theme.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3285?email_source=notifications&email_token=AHC4FRO6VO4EQY5SB6C4Y3LQMPNGHA5CNFSM4IXV6JCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEADCQBA#issuecomment-537274372>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHC4FRMWJSHRWY3KOWIH4NLQMPNGHANCNFSM4IXV6JCA>
.
|
Haha, I wish I was great at CSS 😄 |
This may have some inspiration: Automattic/newspack-blocks#143 |
Nice, thanks for posting that! It could help. |
It looks like this is working well with the Core themes Twenty Fifteen through Twenty Nineteen.
Instead of modifying the ->textContent property, create a new text node, and append it to the <span> node.
Thanks to Weston's suggestion, captions look good so far. Though there's still some work left. |
foreach ( $images as $image ) { | ||
$amp_carousel->appendChild( $image ); | ||
$div = AMP_DOM_Utils::create_node( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to simply append the image to the <amp-carousel>
. But now it creates a <div class="slide">
wrapper that includes the image the caption if one exists.
Then, it appends that <div class="slide">
to the <amp-carousel>
.
It looks like that's needed in order to display a caption.
It's actually a slide in the <amp-carousel> Also, add a comment, and remove an extra newline.
Gallery Blocks With amp-carousel Sometimes Look Different Some Gallery blocks look different with this PR. But it looks like they better display the images at the BeforeAfterThe This is from the new object-fit="cover" for the Steps to reproduce
|
Steps to test
|
This is more important than text-align: center.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The style of the captions overlaying the gallery looks very good now. Nevertheless, I had try to update the gallery block sanitizer to work with the new markup now coming in WordPress 5.3. See #3285 (comment)
I took an initial stab at adding compatibility, but some tests are broken now and need to be fixed. The changes need to be in WordPress 5.2 without Gutenberg active as well, to ensure the carousel is displaying as expected.
Hi Weston, thanks for making those commits. Ah, I should have tested this with WordPress 5.3. I'll work on the tests. |
assets/css/src/amp-default.css 76:37 ✖ Expected double quotes string-quotes Simply change the ' to ".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a couple small bugs in the implementation. In general, though, this works great with and without Gutenberg 6.5+!
' or ', | ||
[ | ||
'( parent::figure[ contains( @class, "wp-block-gallery" ) and @data-amp-carousel = "true" ] )', | ||
'( contains( @class, "wp-block-gallery" ) and @data-amp-carousel = "true" )', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you've lost some functionality with this change. Previously you could have the carousel "off" and lightbox "on" for the gallery, but this sanitizer will now ignore that setting combination.
* Element | ||
* | ||
* @var DOMElement $node | ||
*/ | ||
|
||
$attributes = AMP_DOM_Utils::get_node_attributes_as_assoc_array( $node ); | ||
$is_amp_lightbox = isset( $attributes['data-amp-lightbox'] ) && true === filter_var( $attributes['data-amp-lightbox'], FILTER_VALIDATE_BOOLEAN ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like $is_amp_carousel
, $is_amp_lightbox
also needs to check the parentNode
to see if data-amp-lightbox
is set (for Gutenberg 6.5+ compatibility). The simplest way of handling this situation for both $is_amp_carousel
and $is_amp_lightbox
might be something like this:
$attributes = array_merge( AMP_DOM_Utils::get_node_attributes_as_assoc_array( $node ), AMP_DOM_Utils::get_node_attributes_as_assoc_array( $node->parentNode ) );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @claudiulodro, thanks for pointing that out. I ended up doing something similar to that.
In that case, I think the sanitizer should still run. This could still use more testing.
Though maybe this isn't applied as intended.
Hi @westonruter, In my testing, the Gallery block is looking good with the following combinations: Environment
Gallery Block Settings
Though it looks like all Gallery blocks appear with a lightbox, whether it's selected or not. This issue also seems to appear on the |
Hi @claudiulodro, |
One thing I missed is that this doesn't add captions to gallery shortcodes with 'Display as carousel' selected, like:
This PR now only addresses Gallery blocks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latest version looks good. Thanks for making those revisions. 👍
@kienstra So the only outstanding thing is classic |
Hi @westonruter,
That's right, this PR doesn't affect the Gallery shortcode (or the Classic editor galleries, which use that shortcode). |
Hi @westonruter, The support topic that prompted this PR's issue (#2855) looks to use a Gallery shortcode. Thanks, Weston. |
Great stuff y'all!!
…On Mon, Oct 28, 2019, 4:40 PM Ryan Kienstra ***@***.***> wrote:
@kienstra <https://github.com/kienstra> So the only outstanding thing is
classic gallery shortcode instances will continue to be rendered without
captions? If that's the case, then I think we can merge this and then
follow-up with another issue/PR to do the rest.
Hi @westonruter <https://github.com/westonruter>,
Thanks a lot for reviewing this. Would it be alright if I opened an issue
for [gallery] shortcode captions, then worked on a PR for that?
The support topic
<https://wordpress.org/support/topic/amp-carousel-with-captions/> that
prompted this PR's issue (#2855
<#2855>) looks to use a
Gallery shortcode.
Thanks, Weston.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#3285?email_source=notifications&email_token=AHC4FRO7U5TOAP34XCIVEGDQQ5L5BA5CNFSM4IXV6JCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECOPP3I#issuecomment-547157997>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHC4FROMU7YEYJOFROULDFDQQ5L5BANCNFSM4IXV6JCA>
.
|
@kienstra por supuesto. 👍 |
Gracias! |
Update: this has changed a lot, please see more recent comments
For images in a gallery that have a caption, this adds caption support when 'Display as carousel' is selected:
Before
After
Closes #2855
(Please do
npm run build:css
for the CSS here)