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

Overwrite or set attr target=_blank in outlinks for amp-story #14382

Merged
merged 8 commits into from Apr 5, 2018

Conversation

Enriqe
Copy link
Contributor

@Enriqe Enriqe commented Apr 3, 2018

Fixes #13775

Also imports amp-story-cta-layer in amp-story.

@Enriqe
Copy link
Contributor Author

Enriqe commented Apr 3, 2018

/cc @newmuis @gmajoulet

setOrOverwriteTargetAttribute_(){
const ctaLinks = this.element.querySelectorAll('a');
for (let i = 0; i < ctaLinks.length; i++) {
ctaLinks[i].target = '_blank';
Copy link
Contributor

Choose a reason for hiding this comment

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

@calebcordry I think you'll need to make sure that you do this for amp-story-auto-ads separately, right? It's probable that the amp-story-cta-layer buildCallback will complete before the amp-story-auto-ads actually injects all of the ads it will inject for a given story.

Copy link
Member

Choose a reason for hiding this comment

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

I am creating a cta-layer in amp-story-auto-ads so I think at that point the buildCallback will be fired again?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, right 😊

setOrOverwriteTargetAttribute_(){
const ctaLinks = this.element.querySelectorAll('a');
for (let i = 0; i < ctaLinks.length; i++) {
ctaLinks[i].target = '_blank';
Copy link
Contributor

Choose a reason for hiding this comment

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

Today I learned: buildCallback is running in a Vsync mutate context, otherwise this code would have required to be running in a vsync task

setOrOverwriteTargetAttribute_(){
const ctaLinks = this.element.querySelectorAll('a');
for (let i = 0; i < ctaLinks.length; i++) {
ctaLinks[i].target = '_blank';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I have no idea if it makes a difference, but the rest of the codebase uses element.setAttribute('target', '_blank'). Maybe we should write it this way too?

@@ -0,0 +1,58 @@
/**
Copy link
Contributor Author

Choose a reason for hiding this comment

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

could you guys take a look at the test too please @gmajoulet @newmuis

Copy link
Contributor

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

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

Thanks for the tests!

},
}, env => {
let win;
let ampStoryCtaLayer;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could be a const in the beforeEach, since you're then using ampStoryCtaLayer.element?

ampStoryCtaLayer.buildCallback();
return ampStoryCtaLayer.layoutCallback().then(() => {
expect(
ampStoryCtaLayer.element.classList.contains('i-amphtml-story-layer'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: here and below expect(ampStoryCtaLayer.element).to.have.class('i-amphtml-story-layer')

});
});

});
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: please add a new line at the end of the file :) There is probably a setting for your IDE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops sorry, I always forget. Yes I will search if I can set this on my editor.

@Enriqe Enriqe force-pushed the cta-layer-target-overwrite branch from 18b97b6 to 66ee725 Compare April 5, 2018 15:58
@newmuis newmuis merged commit 72d1930 into ampproject:master Apr 5, 2018
glevitzky pushed a commit that referenced this pull request Apr 27, 2018
* overwrite or set attr target=_blank in outlinks for amp-story.

* console loggg

* change method name

* jsdoc

* Adds test for cta layer.

* more verbose in tests

* linter

* Adds test case.
@Enriqe Enriqe deleted the cta-layer-target-overwrite branch April 27, 2018 16:01
@khalid-halo
Copy link

Developers lose control over the flow because of this overriding this. Should consider reverting this change and let the developer decide when target should be _blank vs _self.

@caiotomazelli
Copy link

@newmuis can you explain the rational behind this design choice? I'm hearing from some developers that is frustrating not having a choice here. Will target=_top be available in the foreseeable future, as discussed in this other issue?
Thanks

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.

None yet

7 participants