Pym.js AMP-compatibility - #276
Conversation
|
Offered this PR upstream to the pym.js plugin: Automattic/pym-shortcode#59 (comment) |
|
@westonruter if you have a chance, I'd appreciate any thoughts on this approach. It's pretty straightforward. I'd also be curious if you know a good solution to making amp-iframe height equal to the height of the inner iframe's content; something like |
Yes, that is supported… but it depends on the document in the iframe window sending this message: window.parent.postMessage({
sentinel: 'amp',
type: 'embed-size',
height: document.body.scrollHeight
}, '*');Without the embedded window sending such a message, there is no way for the host page to “see” into the window to determine its dimensions. This is why Pym.js exists, actually. For more, see the documentation on |
|
It may be possible for you to inject that logic yourself if you have the interactives on the local filesystem: https://gist.github.com/westonruter/73412f3e35cdeaade808f3b8da9d9586#file-pymjs-amp-injected-js If the file is located on a remote server requiring HTTP request to fetch, then this would not be a good approach, because the interactive would need to be cached in a transient. When embedding an interactive for things like election results, such added latency is not ideal 😄 |
|
Thanks for the feedback @westonruter! I've implemented the changes you requested and verified the resizing works well on pages that include your above JS snippet. @jeffersonrabb ping me for instructions if you want to test the resizing. |
|
Don't merge this; I'm going to move the functionality to the Pym.js plugin. Automattic/pym-shortcode#59 (comment) |
|
We've merged Automattic/pym-shortcode#62 and are proceeding to get that released to wp.org. |
|
Thanks for getting that AMP-compatibility work released @benlk! I've removed the handling from here since it's merged upstream, and this PR now just adds Pym.js Embeds to the list of supported plugins. |
|
🎉 This PR is included in version 1.1.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
All Submissions:
Changes proposed in this Pull Request:
This PR adds basic AMP-compatibility to Pym.js embeds. This is a "good enough" solution until native pym.js AMP compatibility. In general, embeds are designed rectangular, so there will be a little extra padding underneath the amp-iframe, as this renders a square container. We don't have access to the intended height of the iframe from only the src url, and we don't know the exact rectangle ratio so square is a safe choice.
An alternate approach I considered that would always "work correctly" is to detect whether a page is using Pym.js embeds, and if the page is using Pym.js embeds force the page to render in non-AMP. That is also not super ideal, but let me know if you think that's a better solution.
How to test the changes in this Pull Request:
Details
.
Note: If you're getting errors because of double-defined
newspack_is_amp, check out this branch of the theme.Other information: