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

Prevent loading auto lightbox when disabled using data-amp-auto-lightbox-disable attribute #37854

Merged
merged 9 commits into from
Apr 14, 2022
10 changes: 9 additions & 1 deletion docs/spec/auto-lightbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,22 @@ To disable it on a particular document section:
</section>
```

Or to disable it for your entire document altogether:
To disable it for your entire document altogether:

```html
<body data-amp-auto-lightbox-disable>
<!-- No elements in the document will be automatically lightboxed -->
</body>
```

Or to prevent automatically loading of `amp-auto-lightbox` script on page load:

```html
<html ⚡ lang="en" data-amp-auto-lightbox-disable>
<!-- Prevent automatically loading of `amp-auto-lightbox` script on page-load -->
</html>
```

If you'd like manual tuning of disabled/enabled images and/or grouping, please use
[`amp-lightbox-gallery`](https://amp.dev/documentation/components/amp-lightbox-gallery)
directly.
8 changes: 7 additions & 1 deletion src/auto-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ export const AutoLightboxEvents_Enum = {
export function installAutoLightboxExtension(ampdoc) {
const {win} = ampdoc;
// Only enabled on single documents tagged as <html amp> or <html ⚡>.
if (!isAmphtml(win.document) || !ampdoc.isSingleDoc()) {
if (
!isAmphtml(win.document) ||
!ampdoc.isSingleDoc() ||
// Prevent loading auto lightbox when disabled using 'data-amp-auto-lightbox-disable' attribute (#37854)
// Check if HTML Tag has 'data-amp-auto-lightbox-disable' attribute
win.document.documentElement.hasAttribute('data-amp-auto-lightbox-disable')
) {
return;
}
chunk(
Expand Down