Skip to content

Commit

Permalink
Ship remote page attachments (#27709)
Browse files Browse the repository at this point in the history
- Adds docs
- Adds validator rules
- Adds example
- Fixes robustness of drawer stylesheet (Ideally the UI would move into shadow DOM)
  • Loading branch information
cramforce committed Apr 13, 2020
1 parent 623383d commit b213e1a
Show file tree
Hide file tree
Showing 8 changed files with 229 additions and 11 deletions.
144 changes: 144 additions & 0 deletions examples/amp-story/attachment.html
@@ -0,0 +1,144 @@
<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-story" src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script>
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
<link href='https://fonts.googleapis.com/css?family=Georgia|Open+Sans|Roboto' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
<title>Attachments</title>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link rel="canonical" href="index.html">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<style amp-custom>
body {
font-family: 'Roboto', sans-serif;
color: #fff;
}

amp-story-page {
background-color: #000;
}

span {
padding: 0 96px 0 20px;
align-items: center;
font-size: 18px;
line-height: 1.5em;
}

amp-story-page-attachment {
color: rgba(0, 0, 0, 0.93);
}
</style>
</head>

<body>
<amp-story
standalone
publisher="The AMP team"
publisher-logo-src="/examples/visual-tests/amp-story/img/AMP-Brand-White-Icon.svg"
poster-portrait-src="/examples/visual-tests/amp-story/img/overview.jpg"
title="Landscape story"
supports-landscape>
<amp-story-page id="cover" title="Relentlessly pursues moth annoy owner">
<amp-story-grid-layer template="fill">
<amp-img layout="fill" src="/examples/visual-tests/amp-story/img/cat1.jpg"></amp-img>
</amp-story-grid-layer>
<amp-story-grid-layer template="vertical" class="bottom blue-bottom-gradient">
<p>
<span data-text-background-color="#00A3DB">Relentlessly pursues moth annoy owner until he gives you food say meow repeatedly until belly rubs, feels good drool that box?</span>
</p>
</amp-story-grid-layer>
<amp-story-page-attachment data-title="Lorem ipsum" layout="nodisplay">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ultricies integer quis auctor elit. Quis eleifend quam adipiscing vitae proin. Id faucibus nisl tincidunt eget nullam. Est pellentesque elit ullamcorper dignissim cras tincidunt lobortis feugiat. Sodales ut etiam sit amet nisl purus. Non enim praesent elementum facilisis leo vel fringilla. Sagittis vitae et leo duis ut diam quam nulla. Id diam maecenas ultricies mi eget mauris pharetra et. Sodales neque sodales ut etiam sit amet. Eu sem integer vitae justo eget magna fermentum iaculis eu. Faucibus interdum posuere lorem ipsum dolor sit amet consectetur. Bibendum est ultricies integer quis auctor elit sed vulputate.</p>

<p>In nisl nisi scelerisque eu ultrices vitae auctor eu. Tristique magna sit amet purus gravida. Tincidunt id aliquet risus feugiat in ante metus dictum. Mattis nunc sed blandit libero volutpat sed. Imperdiet massa tincidunt nunc pulvinar sapien et ligula ullamcorper malesuada. Sit amet mattis vulputate enim nulla aliquet porttitor lacus luctus. Proin sagittis nisl rhoncus mattis rhoncus. Pulvinar neque laoreet suspendisse interdum consectetur libero. Nibh tellus molestie nunc non blandit massa enim nec dui. Sagittis eu volutpat odio facilisis. Tristique senectus et netus et malesuada fames ac. Molestie a iaculis at erat. Sit amet cursus sit amet. Suscipit tellus mauris a diam maecenas sed enim ut. Gravida quis blandit turpis cursus in. Tincidunt vitae semper quis lectus nulla at volutpat diam ut. Morbi tempus iaculis urna id. Faucibus et molestie ac feugiat sed lectus vestibulum. Mauris augue neque gravida in. Ac turpis egestas sed tempus.</p>

<p>Ut tristique et egestas quis ipsum. Aliquam malesuada bibendum arcu vitae elementum curabitur vitae nunc sed. Elementum curabitur vitae nunc sed velit dignissim. Tristique et egestas quis ipsum suspendisse ultrices gravida dictum fusce. At elementum eu facilisis sed odio morbi. Imperdiet proin fermentum leo vel orci porta non. Quam lacus suspendisse faucibus interdum. Eu non diam phasellus vestibulum lorem sed risus. Commodo viverra maecenas accumsan lacus vel facilisis volutpat est velit. Sagittis aliquam malesuada bibendum arcu vitae elementum. Ut sem viverra aliquet eget sit amet. Nulla facilisi morbi tempus iaculis. Sed odio morbi quis commodo odio aenean sed adipiscing diam. Donec ultrices tincidunt arcu non sodales. Amet venenatis urna cursus eget. Sapien et ligula ullamcorper malesuada proin. Tristique sollicitudin nibh sit amet commodo nulla facilisi. Venenatis tellus in metus vulputate eu scelerisque felis.</p>
</amp-story-page-attachment>
</amp-story-page>

<amp-story-page id="page1">
<amp-story-grid-layer template="fill">
<amp-img layout="fill" src="/examples/visual-tests/amp-story/img/cat2.jpg"></amp-img>
</amp-story-grid-layer>
<amp-story-grid-layer template="center">
<p>
<span data-text-background-color="crimson">i can fit in that box but inspect anything brought into the house wack the mini furry mouse intently stare at the same spot. Flee in terror at cucumber discovered on floor shake treat bag</span>
</p>
</amp-story-grid-layer>
<amp-story-page-attachment data-title="Link Description" href="https://www.google.com" layout="nodisplay"></amp-story-page-attachment>
</amp-story-page>

<amp-story-page id="page3">
<amp-story-grid-layer template="fill">
<amp-img layout="fill" src="/examples/visual-tests/amp-story/img/cat1.jpg"></amp-img>
</amp-story-grid-layer>
<amp-story-grid-layer template="vertical" class="bottom blue-bottom-gradient">
<p>
<span data-text-background-color="#00A3DB">Third page</span>
</p>
</amp-story-grid-layer>
</amp-story-page>

<amp-story-bookend layout="nodisplay">
<script type="application/json">
{
"bookendVersion": "v1.0",
"shareProviders": [
"email",
{"provider": "facebook", "app_id": "254325784911610"},
{"provider": "twitter", "text": "This is custom share text that I would like for the Twitter platform"},
"whatsapp",
"pinterest",
"line"
],
"components": [
{
"type": "heading",
"text": "test"
},
{
"type": "small",
"title": "This is an example article",
"url": "/article.html",
"image": "http://placehold.it/500x600"
},
{
"type": "small",
"title": "This is an example article2",
"url": "http://example.com/article.html",
"image": "http://placehold.it/256x128"
},
{
"type": "small",
"title": "This is an example article3",
"url": "http://example.com/article.html",
"image": "http://placehold.it/256x128"
},
{
"type": "heading",
"text": "test2"
},
{
"type": "small",
"title": "This is an example article",
"url": "http://example.com/article.html",
"image": "http://placehold.it/256x128"
},
{
"type": "portrait",
"title": "Heading for portrait",
"category": "This is an example portrait",
"url": "http://example.com/article.html",
"image": "http://placehold.it/350x470"
}
]
}
</script>
</amp-story-bookend>
</amp-story>
</body>
</html>
1 change: 1 addition & 0 deletions extensions/amp-story/1.0/amp-story-page-attachment.css
Expand Up @@ -49,6 +49,7 @@
display: block !important;
height: 24px !important;
width: 24px !important;
padding: 0px !important;
background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="24px" height="24px" viewBox="0 0 48 48" fill="#9F9F9F"><path d="M0 0h48v48H0z" fill="none"/><path d="M38 38H10V10h14V6H10c-2.21 0-4 1.79-4 4v28c0 2.21 1.79 4 4 4h28c2.21 0 4-1.79 4-4V24h-4v14zM28 6v4h7.17L15.51 29.66l2.83 2.83L38 12.83V20h4V6H28z"/></svg>') !important;
}

Expand Down
Expand Up @@ -39,6 +39,13 @@ <h1>Amazing title</h1>
<p>Bacon ipsum dolor cat cat cat.</p>
</amp-story-page-attachment>

<amp-story-page-attachment layout="nodisplay" href="javascript:alert(1)"></amp-story-page-attachment>

<amp-story-page-attachment layout="nodisplay" href="https://www.gooogle.com">
<h1>Illegal child element</h1>
</amp-story-page-attachment>


<amp-story-page-attachment layout="nodisplay">
<h1>Amazing title</h1>
<p>Bacon ipsum dolor cat cat cat.</p>
Expand Down
Expand Up @@ -37,26 +37,37 @@ FAIL
|
| <amp-story-page-attachment layout="nodisplay" theme="cat">
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:37:6 The attribute 'theme' in tag 'amp-story-page-attachment' is set to the invalid value 'cat'.
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:37:6 The attribute 'theme' in tag 'amp-story-page-attachment[href]' is set to the invalid value 'cat'.
| <h1>Amazing title</h1>
| <p>Bacon ipsum dolor cat cat cat.</p>
| </amp-story-page-attachment>
|
| <amp-story-page-attachment layout="nodisplay">
| <amp-story-page-attachment layout="nodisplay" href="javascript:alert(1)"></amp-story-page-attachment>
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:42:6 Invalid URL protocol 'javascript:' for attribute 'href' in tag 'amp-story-page-attachment[href]'.
|
| <amp-story-page-attachment layout="nodisplay" href="https://www.gooogle.com">
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:44:6 Tag 'amp-story-page-attachment[href]' must have 0 child tags - saw 1 child tags.
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:44:6 Tag 'amp-story-page-attachment[href]', if present, must be the last child of tag 'amp-story-page'.
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:42:6 Tag 'amp-story-page-attachment', if present, must be the last child of tag 'amp-story-page'.
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:44:6 Tag 'amp-story-page-attachment[href]', if present, must be the last child of tag 'amp-story-page'.
| <h1>Illegal child element</h1>
| </amp-story-page-attachment>
|
|
| <amp-story-page-attachment layout="nodisplay">
| <h1>Amazing title</h1>
| <p>Bacon ipsum dolor cat cat cat.</p>
|
| <amp-story-grid-layer template="vertical">
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:46:8 The tag 'amp-story-grid-layer' may not appear as a descendant of tag 'amp-story-page-attachment'.
| <h1>fill</h1>
| </amp-story-grid-layer>
|
| <amp-story-bookend src="bookendv1.json" layout="nodisplay">
>> ^~~~~~~~~
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:50:8 The tag 'amp-story-bookend' may not appear as a descendant of tag 'amp-story-page-attachment'.
amp-story/1.0/test/validator-amp-story-page-attachment-error.html:57:8 Tag 'amp-story-bookend', if present, must be the last child of tag 'amp-story-page-attachment'.
| </amp-story-bookend>
|
| <amp-youtube
Expand All @@ -79,4 +90,4 @@ amp-story/1.0/test/validator-amp-story-page-attachment-error.html:50:8 The tag '
| </amp-story-page>
| </amp-story>
| </body>
| </html>
| </html>
Expand Up @@ -50,6 +50,13 @@ <h1>Amazing title</h1>
</amp-youtube>
</amp-story-page-attachment>
</amp-story-page>
<amp-story-page id="fill-template-title">
<amp-story-grid-layer template="vertical">
<h1>fill</h1>
</amp-story-grid-layer>
<amp-story-page-attachment layout="nodisplay" href="https://www.google.com">
</amp-story-page-attachment>
</amp-story-page>
</amp-story>
</body>
</html>
Expand Up @@ -51,6 +51,13 @@ PASS
| </amp-youtube>
| </amp-story-page-attachment>
| </amp-story-page>
| <amp-story-page id="fill-template-title">
| <amp-story-grid-layer template="vertical">
| <h1>fill</h1>
| </amp-story-grid-layer>
| <amp-story-page-attachment layout="nodisplay" href="https://www.google.com">
| </amp-story-page-attachment>
| </amp-story-page>
| </amp-story>
| </body>
| </html>
| </html>
16 changes: 14 additions & 2 deletions extensions/amp-story/amp-story-page-attachment.md
Expand Up @@ -24,7 +24,7 @@ limitations under the License.

# amp-story-page-attachment

Story page attachments allow you to provide additional AMPHTML content to specific pages. This content can be revealed by users through a "swipe up" gesture, or a tap on the call to action element.
Story page attachments allow you to provide additional content in the form of a link or inline AMPHTML content to specific pages. This content can be revealed by users through a "swipe up" gesture, or a tap on the call to action element.
A UI prompt to open the attachment will automatically be added at the bottom of every page that configured an attachment.

<amp-img alt="AMP Story page attachment" layout="fixed" src="https://github.com/ampproject/amphtml/raw/master/extensions/amp-story/img/amp-story-page-attachment.gif" width="240" height="480">
Expand Down Expand Up @@ -72,7 +72,19 @@ Values: "light" (default), "dark"
>
```

## Allowed content and components
## Linked content

When providing a `href` attribute as page attachment, the respective URL is opened when the user activates the page attachment.

```html
<amp-story-page-attachment layout="nodisplay" href="https://www.example.com"
>...</amp-story-page-attachment
>
```

## Inline content

As an alternative to linking a page attachment, you may also provide inline AMP HTML as the page attachment.

Story page attachments allow the same HTML elements as AMP Story along with additional components listed below, such as third party video players or social media embeds. This means you can add additional content that is too verbose or disallowed in an AMP Story page.

Expand Down
31 changes: 30 additions & 1 deletion extensions/amp-story/validator-amp-story.protoascii
Expand Up @@ -755,9 +755,38 @@ descendant_tag_list: {
tag: "VKERN"
tag: "WBR"
}
tags: { # <amp-story-page-attachment>
tags: { # <amp-story-page-attachment> with href
html_format: AMP
tag_name: "AMP-STORY-PAGE-ATTACHMENT"
spec_name: "amp-story-page-attachment[href]"
mandatory_ancestor: "AMP-STORY-PAGE"
mandatory_last_child: true
attrs: {
name: "layout"
mandatory: true
value: "nodisplay"
}
attrs: {
name: "theme"
value: "dark"
value: "light"
}
attrs: {
name: "href"
mandatory: true
value_url: {
protocol: "http"
protocol: "https"
}
}
child_tags: {
mandatory_num_child_tags: 0
}
}
tags: { # <amp-story-page-attachment> with no href
html_format: AMP
tag_name: "AMP-STORY-PAGE-ATTACHMENT"
spec_name: "amp-story-page-attachment"
mandatory_ancestor: "AMP-STORY-PAGE"
descendant_tag_list: "amp-story-page-attachment-allowed-descendants"
mandatory_last_child: true
Expand Down

0 comments on commit b213e1a

Please sign in to comment.