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

[amp-story-player] Support poster img from anchor el #33041

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/amp-story-player/amp-story-player-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,16 @@ export class AmpStoryPlayer {
initializeAnchorElStories_() {
const anchorEls = toArray(this.element_.querySelectorAll('a'));
anchorEls.forEach((element) => {
const posterImgEl = element.querySelector(
'img[data-amp-story-player-poster-img]'
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't have the data- in the attribute right (looking at #30753)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should, we ended up bikeshedding on the name and changing it do data-* to make it comply with standard HTML spec.

You can verify by looking at the AMP version validator

name: "data-amp-story-player-poster-img"

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh ok, I had a feeling that data attributes should have a value (not just the empty string) but the documentation seems to be vague on this. LGTM

);
const posterImgSrc = posterImgEl && posterImgEl.getAttribute('src');

const story = /** @type {!StoryDef} */ ({
href: element.href,
title: (element.textContent && element.textContent.trim()) || null,
posterImage: element.getAttribute('data-poster-portrait-src'),
posterImage:
element.getAttribute('data-poster-portrait-src') || posterImgSrc,
});

this.initializeAndAddStory_(story);
Expand Down