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

Fix lightbox effect if images are aligned #7178

Merged
merged 13 commits into from
Aug 3, 2022

Conversation

thelovekesh
Copy link
Collaborator

@thelovekesh thelovekesh commented Jul 7, 2022

Summary

Fix the lightbox effect when the images are aligned. This is due to the adding of data-amp-lightbox="true" to the <figure> element instead of adding it in <div>.

Also improved the logic of determining media URL and replacing it for lightbox effect.

Fixes #7154

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@thelovekesh thelovekesh self-assigned this Jul 7, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jul 7, 2022

Plugin builds for 1131c4d are ready 🛎️!

@westonruter westonruter added this to the v2.3.1 milestone Jul 7, 2022
@westonruter
Copy link
Member

For a left-aligned block with lightbox added…

Block markup in Twenty Twenty-Two (FSE theme) where lightbox works:

<figure data-amp-lightbox="true" class="wp-block-image alignleft size-full amp-wp-d9a41c3" data-amp-original-style="border-radius:0px"><amp-img width="384" height="384" src="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png" alt="" class="wp-image-10 amp-wp-enforced-sizes i-amphtml-layout-intrinsic i-amphtml-layout-size-defined" srcset="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png 384w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-300x300.png 300w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-150x150.png 150w" sizes="(max-width: 384px) 100vw, 384px" data-amp-lightbox="" lightbox="" layout="intrinsic" disable-inline-width="" data-hero-candidate="" data-hero i-amphtml-ssr i-amphtml-layout="intrinsic"><i-amphtml-sizer slot="i-amphtml-svc" class="i-amphtml-sizer"><img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjM4NCIgd2lkdGg9IjM4NCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiLz4="></i-amphtml-sizer><img class="i-amphtml-fill-content i-amphtml-replaced-content" decoding="async" loading="lazy" alt="" src="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png" srcset="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png 384w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-300x300.png 300w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-150x150.png 150w" sizes="(max-width: 384px) 100vw, 384px"></amp-img></figure>

Block markup in Twenty Twenty-One (non-FSE theme) where lightbox fails:

<div class="wp-block-image">
<figure data-amp-lightbox="true" class="alignleft size-full amp-wp-d9a41c3" data-amp-original-style="border-radius:0px"><amp-img width="384" height="384" src="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png" alt="" class="wp-image-10 amp-wp-enforced-sizes i-amphtml-layout-intrinsic i-amphtml-layout-size-defined" srcset="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png 384w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-300x300.png 300w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-150x150.png 150w" sizes="(max-width: 384px) 100vw, 384px" layout="intrinsic" disable-inline-width="" data-hero-candidate="" data-hero i-amphtml-ssr i-amphtml-layout="intrinsic"><i-amphtml-sizer slot="i-amphtml-svc" class="i-amphtml-sizer"><img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjM4NCIgd2lkdGg9IjM4NCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiLz4="></i-amphtml-sizer><img class="i-amphtml-fill-content i-amphtml-replaced-content" decoding="async" alt="" src="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png" srcset="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png 384w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-300x300.png 300w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-150x150.png 150w" sizes="(max-width: 384px) 100vw, 384px"></amp-img></figure>
</div>

With the changes in this PR, the non-FSE markup becomes:

<div class="wp-block-image">
<figure data-amp-lightbox="true" class="alignleft size-full amp-wp-d9a41c3" data-amp-original-style="border-radius:0px"><amp-img width="384" height="384" src="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png" alt="" class="wp-image-10 amp-wp-enforced-sizes i-amphtml-layout-intrinsic i-amphtml-layout-size-defined" srcset="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png 384w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-300x300.png 300w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-150x150.png 150w" sizes="(max-width: 384px) 100vw, 384px" data-amp-lightbox="" lightbox="" layout="intrinsic" disable-inline-width="" data-hero-candidate="" data-hero i-amphtml-ssr i-amphtml-layout="intrinsic"><i-amphtml-sizer slot="i-amphtml-svc" class="i-amphtml-sizer"><img alt="" aria-hidden="true" class="i-amphtml-intrinsic-sizer" role="presentation" src="data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjM4NCIgd2lkdGg9IjM4NCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiLz4="></i-amphtml-sizer><img class="i-amphtml-fill-content i-amphtml-replaced-content" decoding="async" alt="" src="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png" srcset="http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1.png 384w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-300x300.png 300w, http://localhost:8888/wp-content/uploads/2022/06/amp-logo-icon-512x512-1-150x150.png 150w" sizes="(max-width: 384px) 100vw, 384px"></amp-img></figure></div>

And lightbox works. It also still works in an FSE theme.

@thelovekesh
Copy link
Collaborator Author

@westonruter Is this PR good to merge? If needed any changes please LMK.

@westonruter
Copy link
Member

I haven't had a chance to finish reviewing yet. Sorry for the delay.

includes/sanitizers/class-amp-img-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-img-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-img-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-img-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-img-sanitizer.php Outdated Show resolved Hide resolved
includes/sanitizers/class-amp-img-sanitizer.php Outdated Show resolved Hide resolved
@thelovekesh thelovekesh force-pushed the fix/lightbox-fails-on-aligned-image branch from 18727d2 to 7d56e06 Compare July 29, 2022 06:13
@thelovekesh thelovekesh force-pushed the fix/lightbox-fails-on-aligned-image branch from 7d56e06 to 3e3dfdf Compare July 29, 2022 06:13
@westonruter
Copy link
Member

Thanks for your persistence with this.

@westonruter westonruter merged commit c8b7f69 into develop Aug 3, 2022
@westonruter westonruter deleted the fix/lightbox-fails-on-aligned-image branch August 3, 2022 21:29
@westonruter westonruter modified the milestones: v2.3.1, v2.4 Jan 26, 2023
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lightbox effect: Fails if image is aligned
2 participants