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

Add noscript iframe fallbacks for amp-iframe for no-JS browsers #1913

Merged
merged 4 commits into from
Mar 1, 2019

Conversation

westonruter
Copy link
Member

This is a follow-up to #1861.

  • When converting iframe to amp-iframe, automatically put the original iframe inside of a noscript element inside or the replacement amp-iframe. This ensures that browsers that have JS turned off will still get the iframe rendering.
  • Prevent converting iframe elements which are already inside of amp-iframe > noscript.
  • Prevent converting img elements which are already inside of amp-img > noscript.
  • Prevent converting video elements which are already inside of amp-video > noscript.
  • Prevent converting audio elements which are already inside of amp-audio > noscript.

@westonruter westonruter added this to the v1.1 milestone Feb 28, 2019
@googlebot googlebot added the cla: yes Signed the Google CLA label Feb 28, 2019
@westonruter westonruter merged commit 225e780 into develop Mar 1, 2019
@westonruter westonruter deleted the add/iframe-noscript-fallbacks branch March 1, 2019 14:20
jeherve pushed a commit to Automattic/jetpack that referenced this pull request Mar 22, 2019
See #9730.

#### Changes proposed in this Pull Request:

Since AMP has built-in responsiveness, the Contact Info widget's map iframe with 600⨉216 dimensions can the actual height to be much less. For example, in Twenty Seventeen the sidebar is 325px wide. This results in the iframe being 117px high, since 325:117 has the same aspect ratio as 600:216. To fix, this PR explicitly uses AMP's `fixed-height` layout for the `amp-iframe` so that the height will always be 216px with the width being responsive.

#### Testing instructions:

1. Activate Twenty Seventeen.
2. Install the AMP plugin and in the AMP settings switch to the paired mode. (You may also need to opt to hide the admin bar in AMP if there is too much CSS resulting.)
3. Add the Contact Info widget and click the checkbox to show the map (which requires a Google Maps API key).
4. Look at the frontend, and the non-AMP version should look like this:

> <img width="358" alt="screen shot 2019-02-28 at 11 17 01" src="https://user-images.githubusercontent.com/134745/53592773-d2660c80-3b4b-11e9-9c9a-2cfae4e434ae.png">

5. Switch to the AMP version (`?amp`) and in `master` it should look erroneously as this (with less vertical height):

> <img width="353" alt="screen shot 2019-02-28 at 11 17 12" src="https://user-images.githubusercontent.com/134745/53592873-148f4e00-3b4c-11e9-8935-50425af128e1.png">

6. Switch to this branch and in the AMP version it should look like the following, which is the same as the non-AMP version:

> <img width="356" alt="screen shot 2019-02-28 at 11 25 43" src="https://user-images.githubusercontent.com/134745/53592925-2a047800-3b4c-11e9-8e31-c98e2b32c49e.png">

The HTML markup for AMP should look like this (after ampproject/amp-wp#1913, without which the `iframe` inside the `noscript` is also converted to `amp-iframe`):

```html
<amp-iframe layout="fixed-height" width="auto" sandbox="allow-scripts allow-same-origin" height="216" frameborder="0"
            src="https://www.google.com/maps/embed/v1/place?q=3999+Mission+Boulevard%2CSan+Diego+CA+92109&amp;key=..."
            class="contact-map">
    <span placeholder>Loading map…</span>
    <noscript>
        <iframe width="600" height="216" frameborder="0"
                src="https://www.google.com/maps/embed/v1/place?q=3999+Mission+Boulevard%2CSan+Diego+CA+92109&amp;key=..."
                class="contact-map"></iframe>
    </noscript>
</amp-iframe>
```

#### Proposed changelog entry for your changes:

* Improve rendering of Contact Info widget map in AMP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants