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
3 changes: 0 additions & 3 deletions extensions/amp-auto-lightbox/0.1/amp-auto-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ const DISABLED_BY_ATTR = [
// Runtime-specific.
'[placeholder]',

// Explicitly opted out.
'[data-amp-auto-lightbox-disable]',

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want this documentation here still? How else will people know?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this line from here because it won't be executed as we are excluding the amp-auto-lightbox.js script if the data-amp-auto-lightbox-disable attribute is present in the body. Can you suggest any .md file where we can document this attribute for people to know?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be left, since it allows individual opt outs without disabling all auto-lightbox.

// Considered "actionable", i.e. that are bound to a default
// onclick action(e.g. `button`) or where it cannot be determined whether
// they're actionable or not (e.g. `amp-script`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ describes.realWin(
accepts: 'elements inside non-clickable anchor',
wrapWith: () => html` <a id="my-anchor"></a> `,
},
{
rejects: 'explicitly opted-out subnodes',
mutate: (el) => el.setAttribute('data-amp-auto-lightbox-disable', ''),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo this removal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍🏻

},
{
rejects: 'amp-subscriptions subnodes',
mutate: (el) => el.setAttribute('subscriptions-action', ''),
Expand Down
6 changes: 5 additions & 1 deletion src/auto-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ 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() ||
win.document.body.hasAttribute('data-amp-auto-lightbox-disable')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this is called, we can't guarantee that the <body> (or all of its attributes) have bene parsed. It would be safer to put this on the <html> element instead.

Copy link
Contributor

@AnuragVasanwala AnuragVasanwala Apr 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jridgewell Should it be something like this:

<html  lang="en" data-amp-auto-lightbox-disable>
...
</html>

Please correct me if there is misinterpretation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let me revise implementation 👍🏻

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jridgewell Done. I have revised implementation and updated markdown (refer 02ff8d1)

Let me know if there is anything that needs to be taken care of.

) {
return;
}
chunk(
Expand Down