-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image block: Add aspect ratio support to lightbox (#52765)
* Add docs for `afterLoad` * Move store options to the end * Initial aspect-ration support implementation * Move `inherit` property to `wp-style` directive * Add `object-fit` cover * Fix big images aspect ratio * Fix animation on mobile; add comments * Remove obsolete variable declaration * Fix PHP spacing * Optimize animation performance; add comments; fix fade and thumbnail bugs * Handle images in content with aspect ratios that differ from source images Note: This commit does not yet contain support for images with the `contain` style enabled, or for the images with 16x9 aspect ratio. For the moment, This code works by checking the aspect ratio of the image's natural dimensions and comparing it to the target dimensions. If these aspect ratios differ, then we calculate the space the lightbox image would use as a cover image and apply that as a `scale` CSS attribute. It also currently sets the image as a square using that resized dimension, which seems to work in many but not all cases, so will continue to explore the best way to approach. Animation for translation and scale have been separated in this commit to allow for flexibility in handling various scenarios. * Simplify zooming lightbox * Add support for thumbnails * Clean code and change variable names * Fix thumbnails with cropped width and height * Add support for contain setting * Add 5% padding to the lightbox container * Move CSS properties to style tag * Add wp prefix to CSS global variables * Remove `!important` from CSS * Reuse zooming logic for the fade animation * Remove fade conditional * Fix php standards * Remove unnecessary inheritSize selector * Update e2e test to fit new style tag * Fix width of image container so button isn't wider than image * Add variable horizontal padding and fixed vertical padding * Fix fade out animation; modify animation for image slightly * Prevent scroll after focusing last image * Add support for contain in lightbox image button * Add logic to set button styles only when needed and on image load * Simplify lazy loading logic * Remove extra div from image markup As part of this commit, I added handling for button styles in all images with the lightbox enabled, as we can't rely on the CSS as was written to set the right dimensions without breaking the layout on mobile. * Add 1 pixel to container dimensions to fix style bug on iOS * Add logic to center button when using 'contain' * (After merge) Add logic to set button styles on window resize * Replace loading=lazy with manual setting of src attribute The combination of 'loading=lazy' and the 'hidden' attributes was breaking progressive image loading in Safari and Chrome; instead we are now taking what seems to be a more reliable approach to accomplish lazy loading of the enlarged image, namely setting the src manually when the lightbox is opened. *This was an approach we had implemented before, but we began using 'loading=lazy' during a code cleanup. * Add link to comment * Remove obsolete code * Update tests * Add clarifying comment to setting of responsive image src attribute * Update clarifying comment on 1px bug in iOS * Add namespace to state --------- Co-authored-by: David Arenas <[email protected]> Co-authored-by: Mario Santos <[email protected]> Co-authored-by: Carlos Bravo <[email protected]>
- Loading branch information
1 parent
20bf292
commit 676f259
Showing
4 changed files
with
547 additions
and
377 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.