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

Force the 'data-embed-as' attribute to 'video' and make sure to show post text #13454

Merged
merged 4 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion 3p/facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,16 @@ function getPostContainer(global, data) {
setStyle(c, 'text-align', 'center');
}
const container = global.document.createElement('div');
const embedAs = data.embedAs || 'post';
let embedAs = data.embedAs || 'post';
user().assert(['post', 'video'].indexOf(embedAs) !== -1,
'Attribute data-embed-as for <amp-facebook> value is wrong, should be' +
' "post" or "video" was: %s', embedAs);
// Force the `data-embed-as` attribute to 'video' and make sure to show the post's text.
if (data.href.indexOf('/videos/') > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would generate false positives if Facebook username has the word videos in it. Would need to tighten up the regex to only match */(videos)/d+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

embedAs = 'video';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, the behavior of this could be strange to a publisher if they explicitly set data-embed-as="post" but this auto-changes it to video. Is it always better the change the value to video because the user experience is broken with post-videos?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, maybe in addition to the RegEx check, we also check if data.embedAs is falsey meaning user did not explicitly specify a type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, made the change.

container.setAttribute('data-embed-as', 'video');
container.setAttribute('data-show-text', 'true');
Copy link
Contributor

Choose a reason for hiding this comment

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

add a comment why show-text must be true for video. The reason is not obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
container.className = 'fb-' + embedAs;
container.setAttribute('data-href', data.href);
return container;
Expand Down
1 change: 1 addition & 0 deletions build-system/amp.extern.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ data.hideCta;
data.smallHeader;
data.adaptContainerWidth;
data.showFacePile;
data.showText;

// 3p code
var twttr;
Expand Down
22 changes: 22 additions & 0 deletions extensions/amp-facebook/0.1/test/test-amp-facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,28 @@ describes.realWin('amp-facebook', {
expect(fbVideo.getAttribute('data-href')).to.equal(fbVideoHref);
});

it('adds fb-video element with `data-embed-as` and `data-show-text` ' +
'attributes set correctly', () => {
const div = doc.createElement('div');
div.setAttribute('id', 'c');
doc.body.appendChild(div);
win.context = {
tagName: 'AMP-FACEBOOK',
};

facebook(win, {
href: fbVideoHref,
width: 111,
height: 222,
});
const fbVideo = doc.body.getElementsByClassName('fb-video')[0];
expect(fbVideo).not.to.be.undefined;
expect(fbVideo.classList.contains('fb-video')).to.be.true;
expect(fbVideo.getAttribute('data-embed-as')).to.equal('video');
expect(fbVideo.getAttribute('data-show-text')).to.equal('true');
});


it('removes iframe after unlayoutCallback', () => {
return getAmpFacebook(fbPostHref).then(ampFB => {
const iframe = ampFB.querySelector('iframe');
Expand Down