Closed johnwatkins0 closed 2 years ago
See also https://github.com/ampproject/amp-wp/issues/3579#issuecomment-545567310. So the answer to that question apparently is yes: we still do need the lightbox toggle.
Here's a mini plugin that adds the the data-amp-auto-lightbox-disable
attribute to the body
: https://gist.github.com/westonruter/b6691407af1648b402b09371a9faf7f0
I think it makes sense to go ahead and update the plugin to do this by default. Maybe there should be a filter to control whether the attribute is added, but it would be added by default.
Note that even when data-amp-auto-lightbox-disable
is added to the body
, the amp-auto-lightbox-0.1.js
script will continue to be downloaded even though it won't be used for anything. See https://github.com/ampproject/amphtml/issues/26452.
As opposed to a filter, enabling/disabling the auto-lightbox functionality could be an advanced option on the Settings screen. There may be some other such settings that would be relevant in such a section, such as whether galleries should by default use a carousel and/or lightbox per https://github.com/ampproject/amp-wp/issues/4989#issuecomment-689677233.
I'm just wary of adding too many settings. If we find that most users benefit from something being enabled (or disabled) we should just do it and provide an API to override the default behavior. If there are more than 20% of users who would be wanting to override the default, then in that case the UI would make sense.
I'm just wary of adding too many settings. If we find that most users benefit from something being enabled (or disabled) we should just do it and provide an API to override the default behavior. If there are more than 20% of users who would be wanting to override the default, then in that case the UI would make sense.
As of now, I have added the filter to disable the auto lightbox. (by default auto lightbox will be enabled). Let me know if we should add a UI for that option.
cc: @westonruter
As of now, I have added the filter to disable the auto lightbox. (by default auto lightbox will be enabled). Let me know if we should add a UI for that option.
No UI is needed, no. But let's disable the auto-lightbox by default. See https://github.com/ampproject/amp-wp/pull/6936/files#r822046774.
To test this, try with a theme like Twenty Seventeen. I found that auto-lightbox didn't engage in Twenty Twenty or Twenty Twenty-One because they already use lightboxes.
QA Passed ✅
Before: Image had lightbox effect even if lightbox toggle was off
After: Image is displayed in lightbox only if lightbox toggle is enabled
Bug Description
With this plugin active on a site, any page that (a) contains one or more
amp-img
es and (b) doesn't have lightboxing explicitly turned on for anyamp-img
receives auto lightboxing for all images on the page. This document pretty much explains why: https://github.com/ampproject/amphtml/blob/master/spec/auto-lightbox.mdWhile auto-lightboxing is probably fine for many sites, there are cases where it's not desirable -- e.g. very small images tend not to look great when expanded into a lightbox, and decorative graphical elements generally don't benefit from the lightbox.
Expected Behaviour
Image blocks with "Add lightbox effect" toggled off should never have a lightbox.
Perhaps the plugin could make it possible to opt out of auto lightboxing at the post level. Where auto lightboxing is disabled, however, it should still be possible to enable the lightbox for individual images using the "Add lightbox effect" toggle.
On the project where this came up, we did just that -- we added a post meta field to the editor sidebar, to the effect of "Disable lightbox for this post." When this is on, we add
data-amp-auto-lightbox-disable
to the element wrapping the post content. When this attribute is present, images with "Add lightbox effect" turned on still have the lightbox. This approach could be difficult to implement from the plugin, though, because the plugin can't easily modify the theme's markup. The attribute could be added to thebody
tag, maybe.Steps to reproduce
develop
branch)Additional context
develop
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
data-amp-auto-lightbox-disable
attribute should be added to thebody
.Implementation brief
See https://gist.github.com/westonruter/b6691407af1648b402b09371a9faf7f0
AMP_Auto_Lightbox_Disable_Sanitizer
which sets thedata-amp-auto-lightbox-disable
attribute on thebody
.amp_get_content_sanitizers()
, conditionally add this sanitizer to the$sanitizers
ifapply_filters( 'amp_auto_lightbox_disabled', true )
returnsfalse
.QA testing instructions
Demo
Changelog entry