Skip to content

Commit

Permalink
🐛 [story-ads] Move click listener to<a> and use target="blank" (#…
Browse files Browse the repository at this point in the history
…36335)

* use anchor and _blank

* A not a
  • Loading branch information
calebcordry committed Oct 13, 2021
1 parent 7cf3fed commit d3062e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions extensions/amp-story-auto-ads/0.1/story-ad-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,15 @@ function createPageOutlink_(doc, uiMetadata, container) {
const pageOutlink = doc.createElement('amp-story-page-outlink');
pageOutlink.setAttribute('layout', 'nodisplay');

const pageAnchorTag = doc.createElement('a');
pageAnchorTag.href = uiMetadata[A4AVarNames.CTA_URL];
const pageAnchorTag = createElementWithAttributes(
doc,
'a',
dict({
'class': 'i-amphtml-story-ad-link',
'target': '_blank',
'href': uiMetadata[A4AVarNames.CTA_URL],
})
);
pageAnchorTag.textContent = uiMetadata[A4AVarNames.CTA_TYPE];

pageOutlink.appendChild(pageAnchorTag);
Expand All @@ -223,7 +230,7 @@ function createPageOutlink_(doc, uiMetadata, container) {
pageOutlink.className = 'i-amphtml-story-page-outlink-container';

container.appendChild(pageOutlink);
return container;
return pageAnchorTag;
}

/**
Expand Down Expand Up @@ -264,6 +271,8 @@ export function createCta(doc, buttonFitter, container, uiMetadata) {
const ctaUrl = uiMetadata[A4AVarNames.CTA_URL];
const ctaText = uiMetadata[A4AVarNames.CTA_TYPE];

// TODO(#36035): we should be using this element in createPageOutlink_
// instead of creating it and dropping.
const a = createElementWithAttributes(
doc,
'a',
Expand Down
2 changes: 2 additions & 0 deletions extensions/amp-story-auto-ads/0.1/test/test-story-ad-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ describes.realWin('story-ad-ui', {amp: true}, (env) => {
'https://www.cats.com/'
);
expect(containerElem.children[0].textContent).to.equal('SHOP');
expect(containerElem.children[0].target).to.equal('_blank');
expect(containerElem.children[0].tagName).to.equal('A');
});
});

Expand Down

0 comments on commit d3062e7

Please sign in to comment.