Skip to content

Commit

Permalink
<amp-pinterest> Add alt attribute (#12862)
Browse files Browse the repository at this point in the history
  • Loading branch information
nainar authored and aghassemi committed Jan 24, 2018
1 parent ea3c4fe commit 13757d5
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/pinterest.amp.html
Expand Up @@ -26,7 +26,8 @@ <h3>Embedded Pins</h3>

<amp-pinterest width=245 height=330
data-do="embedPin"
data-url="https://www.pinterest.com/pin/99360735500167749/">
data-url="https://www.pinterest.com/pin/99360735500167749/"
alt="Hands making a heart over Pinterest logo">
</amp-pinterest>

<amp-pinterest width=355 height=410
Expand Down
8 changes: 8 additions & 0 deletions extensions/amp-pinterest/0.1/pin-widget.js
Expand Up @@ -40,6 +40,7 @@ export class PinWidget {
this.element = rootElement;
this.xhr = Services.xhrFor(toWin(rootElement.ownerDocument.defaultView));
this.pinId = '';
this.alt = '';
this.pinUrl = '';
this.width = '';
this.layout = '';
Expand Down Expand Up @@ -110,12 +111,18 @@ export class PinWidget {
'data-pin-log': 'embed_pin',
}});

// If no alternate text is set, set it to the title gotten from the pin data
if (!this.alt && pin['attribution']) {
this.alt = pin['attribution']['title'];
}

const img = Util.make(this.element.ownerDocument, {'img': {
'src': imgUrl,
'className': '-amp-pinterest-embed-pin-image',
'data-pin-no-hover': true,
'data-pin-href': 'https://www.pinterest.com/pin/' + pin['id'] + '/',
'data-pin-log': 'embed_pin_img',
'alt': this.alt,
}});
container.appendChild(img);

Expand Down Expand Up @@ -237,6 +244,7 @@ export class PinWidget {
this.pinUrl = this.element.getAttribute('data-url');
this.width = this.element.getAttribute('data-width');
this.layout = this.element.getAttribute('layout');
this.alt = this.element.getAttribute('alt');

this.pinId = '';
try {
Expand Down
59 changes: 58 additions & 1 deletion extensions/amp-pinterest/0.1/test/test-amp-pinterest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -50,7 +50,8 @@
width=245
height=330
data-do="embedPin"
data-url="https://www.pinterest.com/pin/99360735500167749">
data-url="https://www.pinterest.com/pin/99360735500167749"
alt="Hands making heart over Pinterest logo">
</amp-pinterest>
</body>
</html>
Expand Up @@ -51,7 +51,8 @@ PASS
| width=245
| height=330
| data-do="embedPin"
| data-url="https://www.pinterest.com/pin/99360735500167749">
| data-url="https://www.pinterest.com/pin/99360735500167749"
| alt="Hands making heart over Pinterest logo">
| </amp-pinterest>
| </body>
| </html>
4 changes: 4 additions & 0 deletions extensions/amp-pinterest/amp-pinterest.md
Expand Up @@ -173,6 +173,10 @@ Must contain the fully-qualified URL of the Pinterest resource to be shown as a
data-url="https://www.pinterest.com/pin/99360735500167749/"
```

##### alt

This property like the the `alt` attribute on an `<img>` tag specifies the alternate text. If not provided it will be infered from the pin data provided by the Pinterest API.

## Validation

See [amp-pinterest rules](https://github.com/ampproject/amphtml/blob/master/extensions/amp-pinterest/validator-amp-pinterest.protoascii) in the AMP validator specification.
Expand Up @@ -38,6 +38,7 @@ tags: { # <amp-pinterest>
name: "data-do"
mandatory: true
}
attrs: { name: "alt" }
attr_lists: "extended-amp-global"
spec_url: "https://www.ampproject.org/docs/reference/components/amp-pinterest"
amp_layout: {
Expand Down

0 comments on commit 13757d5

Please sign in to comment.