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

Conversation

nainar
Copy link
Contributor

@nainar nainar commented Feb 13, 2018

Fixes #12088

It does so by:

  • Forcing the data-embed-as for all videos to 'video'
  • Since that disables post text, enables the ability to see the text by setting the data-show-text to 'true' (changed from the default 'false')
  • Also adds a test to this effect

Initially the issue would repro when switching from desktop to mobile mode in Chrome devtools as well.

@nainar
Copy link
Contributor Author

nainar commented Feb 14, 2018

@cvializ could you take a look at the PR?

@cathyxz cathyxz requested review from cvializ and cathyxz February 16, 2018 13:09
3p/facebook.js Outdated
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) {
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.

3p/facebook.js Outdated
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.

3p/facebook.js Outdated
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) {
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.

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

3p/facebook.js Outdated
if (data.href.indexOf('/videos/') > 0) {
embedAs = 'video';
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

Copy link
Contributor Author

@nainar nainar left a comment

Choose a reason for hiding this comment

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

3p/facebook.js Outdated
if (data.href.indexOf('/videos/') > 0) {
embedAs = 'video';
container.setAttribute('data-embed-as', 'video');
container.setAttribute('data-show-text', 'true');
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

3p/facebook.js Outdated
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 Author

Choose a reason for hiding this comment

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

Done.

3p/facebook.js Outdated
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) {
embedAs = 'video';
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.

@nainar nainar force-pushed the amp_facebook_embed branch from 287147a to d6e6d01 Compare February 21, 2018 02:31
@nainar
Copy link
Contributor Author

nainar commented Feb 22, 2018

@aghassemi could you merge the CL?

@cvializ cvializ merged commit ba7ee25 into ampproject:master Feb 22, 2018
RanAbram pushed a commit to RanAbram/amphtml that referenced this pull request Mar 12, 2018
…post text (ampproject#13454)

* Force the 'data-embed-as' attribute to 'video' and make sure to show the post's text.

* Strengthen regex and force data-embed-as attribute when not specifically set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants