-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add right column and mobile sticky ads to football fixtures pages (#1379
) * Add advert in right of desktop football pages * add football fixtures pages to rules for mobile sticky ad slot * fix and update tests for mobile sticky conditions * move fixture page detection to commercial features constructor * add optional chaining to avoid issues in unrelated tests * Revert "move fixture page detection to commercial features constructor" This reverts commit d9e4e16. * move fixture page detection to commercial features constructor, add page id to initial Jest setup config to prevent test issues * add changeset --------- Co-authored-by: Dominik Lander <dominik.lander@guardian.co.uk>
- Loading branch information
Showing
11 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@guardian/commercial': major | ||
--- | ||
|
||
add new football-right slot and show ads on fixture pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { AD_LABEL_HEIGHT } from 'core/constants'; | ||
import { createAdSlot, wrapSlotInContainer } from 'core/create-ad-slot'; | ||
import { commercialFeatures } from 'lib/commercial-features'; | ||
import { getBreakpoint } from 'lib/detect/detect-breakpoint'; | ||
import { getViewport } from 'lib/detect/detect-viewport'; | ||
import fastdom from '../utils/fastdom-promise'; | ||
import { fillDynamicAdSlot } from './fill-dynamic-advert-slot'; | ||
|
||
const LARGEST_AD_SIZE = 600; // px, double mpu | ||
const SPACING = 10; // px, above ad | ||
|
||
const insertFootballRightAd = (anchor: HTMLElement) => { | ||
const slot = createAdSlot('football-right'); | ||
|
||
const container = wrapSlotInContainer(slot, { | ||
className: 'ad-slot-container football-right-ad-container', | ||
}); | ||
|
||
/** | ||
* TODO: Move these to a class in frontend | ||
*/ | ||
container.style.position = 'sticky'; | ||
container.style.top = '0'; | ||
container.style.marginTop = '10px'; | ||
|
||
void fastdom | ||
.mutate(() => { | ||
anchor.style.height = '100%'; | ||
anchor.appendChild(container); | ||
}) | ||
.then(() => fillDynamicAdSlot(slot, false)); | ||
}; | ||
|
||
/** | ||
* Inserts an advert on certain football fixtures/results/tables | ||
* pages in the right column. | ||
*/ | ||
export const init = (): Promise<void> => { | ||
if (window.guardian.config.isDotcomRendering) { | ||
return Promise.resolve(); | ||
} | ||
|
||
const currentBreakpoint = getBreakpoint(getViewport().width); | ||
if (currentBreakpoint !== 'desktop' && currentBreakpoint !== 'wide') { | ||
return Promise.resolve(); | ||
} | ||
|
||
if (!commercialFeatures.footballFixturesAdverts) { | ||
return Promise.resolve(); | ||
} | ||
|
||
/** | ||
* On Football pages, this right-hand column exists in the DOM but does not | ||
* appear to be used. Can we use it for an advert? | ||
*/ | ||
const anchor: HTMLElement | null = document.querySelector( | ||
'.content__secondary-column', | ||
); | ||
|
||
const minSpaceForAd = LARGEST_AD_SIZE + AD_LABEL_HEIGHT + SPACING; | ||
|
||
if ( | ||
anchor === null || | ||
anchor.parentElement === null || | ||
anchor.parentElement.offsetHeight < minSpaceForAd | ||
) { | ||
return Promise.resolve(); | ||
} | ||
|
||
insertFootballRightAd(anchor); | ||
|
||
return Promise.resolve(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters