Skip to content

Commit 4069d8b

Browse files
Prevent loading auto lightbox when disabled using data-amp-auto-lightbox-disable attribute (ampproject#37854)
* Prevent loading auto lightbox when disabled using attribute * Fix failing test case * ✨ Add `data-amp-auto-lightbox-disable` to `DISABLED_BY_ATTR` Marking `data-amp-auto-lightbox-disable` as `<html ⚡ lang="en" data-amp-auto-lightbox-disable>` will disable `amp-auto-lightbox` from auto-load on page load. * ♻️ Move `data-amp-auto-lightbox-disable` attribute checking from `body` to `html` This will check if HTML Tag has `data-amp-auto-lightbox-disable` attribute like: `<html ⚡ lang="en" data-amp-auto-lightbox-disable>`. If it has, it will disable auto-loading of `amp-auto-lightbox` on page load. * 📖 Update markdown `auto-lightbox.md` * ⏪ Revert unit-test changes to original Co-authored-by: Anurag Vasanwala <[email protected]>
1 parent 20d4566 commit 4069d8b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: docs/spec/auto-lightbox.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,22 @@ To disable it on a particular document section:
5353
</section>
5454
```
5555

56-
Or to disable it for your entire document altogether:
56+
To disable it for your entire document altogether:
5757

5858
```html
5959
<body data-amp-auto-lightbox-disable>
6060
<!-- No elements in the document will be automatically lightboxed -->
6161
</body>
6262
```
6363

64+
Or to prevent automatically loading of `amp-auto-lightbox` script on page load:
65+
66+
```html
67+
<html lang="en" data-amp-auto-lightbox-disable>
68+
<!-- Prevent automatically loading of `amp-auto-lightbox` script on page-load -->
69+
</html>
70+
```
71+
6472
If you'd like manual tuning of disabled/enabled images and/or grouping, please use
6573
[`amp-lightbox-gallery`](https://amp.dev/documentation/components/amp-lightbox-gallery)
6674
directly.

Diff for: src/auto-lightbox.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ export const AutoLightboxEvents_Enum = {
2727
export function installAutoLightboxExtension(ampdoc) {
2828
const {win} = ampdoc;
2929
// Only enabled on single documents tagged as <html amp> or <html ⚡>.
30-
if (!isAmphtml(win.document) || !ampdoc.isSingleDoc()) {
30+
if (
31+
!isAmphtml(win.document) ||
32+
!ampdoc.isSingleDoc() ||
33+
// Prevent loading auto lightbox when disabled using 'data-amp-auto-lightbox-disable' attribute (#37854)
34+
// Check if HTML Tag has 'data-amp-auto-lightbox-disable' attribute
35+
win.document.documentElement.hasAttribute('data-amp-auto-lightbox-disable')
36+
) {
3137
return;
3238
}
3339
chunk(

0 commit comments

Comments
 (0)