FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge pull request #20240 from guardian/jp-remove-paid-for-rich-links… · devhttps/frontend@ba5ecc5 · GitHub

Commit ba5ecc5

Browse files
authored
Merge pull request guardian#20240 from guardian/jp-remove-paid-for-rich-links-for-ad-free
Remove paid-for rich links for ad-free
2 parents 5daeaa7 + d078abd commit ba5ecc5

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎static/src/javascripts/projects/common/modules/article/rich-links.js‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import fetchJson from 'lib/fetch-json';
99
import mediator from 'lib/mediator';
1010
import reportError from 'lib/report-error';
1111
import { spaceFiller } from 'common/modules/article/space-filler';
12+
import { commercialFeatures } from 'common/modules/commercial/commercial-features';
1213

1314
const richLinkTag = ({ href }: { href: string }): string =>
1415
`<aside class=" element element-rich-link element-rich-link--tag
@@ -19,6 +20,19 @@ const richLinkTag = ({ href }: { href: string }): string =>
1920
<p><a href="${href}">${href}</a></p>
2021
</aside>`;
2122

23+
const hideIfPaidForAndAdFree = (el: Element): Promise<void> => {
24+
if (!commercialFeatures.adFree) {
25+
return Promise.resolve();
26+
}
27+
return fastdom.write(() => {
28+
[...el.children]
29+
.filter(child =>
30+
child.classList.toString().includes('rich-link--paidfor')
31+
)
32+
.forEach(child => child.classList.add('u-h'));
33+
});
34+
};
35+
2236
const elementIsBelowViewport = (el: Element): Promise<boolean> =>
2337
fastdom.read(() => {
2438
const rect = el.getBoundingClientRect();
@@ -71,6 +85,7 @@ const upgradeRichLink = (el: Element): Promise<void> => {
7185
} else {
7286
doUpgrade(el, resp);
7387
}
88+
hideIfPaidForAndAdFree(el); // only identifiable as paid-for when upgraded
7489
}
7590
})
7691
.catch(ex => {

‎static/src/javascripts/projects/common/modules/article/rich-links.spec.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
richLinkTag,
66
insertTagRichLink,
77
} from 'common/modules/article/rich-links';
8+
import { commercialFeatures } from 'common/modules/commercial/commercial-features';
89

910
let mockParas: ?NodeList<HTMLParagraphElement>;
1011

@@ -21,6 +22,9 @@ jest.mock('common/modules/article/space-filler', () => ({
2122
}),
2223
},
2324
}));
25+
jest.mock('common/modules/commercial/commercial-features', () => ({
26+
commercialFeatures() {},
27+
}));
2428

2529
describe('rich-links', () => {
2630
const getRichLinkElements = (): HTMLCollection<HTMLElement> =>
@@ -39,6 +43,8 @@ describe('rich-links', () => {
3943
showRelatedContent: true,
4044
shouldHideAdverts: false,
4145
};
46+
47+
commercialFeatures.adFree = false;
4248
});
4349

4450
afterEach(() => {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL