forked from aemsites/vg-volvotrucks-us
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
How to display Digital Reveal Cookie management message in Modal video …
…#313 (#318) * refactor low resolution banner * refactor check of cookie setting * add banner when no fallback video is present * add background image, change color for banner, set document cookie on okay button * add rounded corners to video * split livestream code from embed --------- Co-authored-by: Lakshmishri <[email protected]>
- Loading branch information
1 parent
c2669bc
commit c74eca9
Showing
13 changed files
with
366 additions
and
26 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
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,63 @@ | ||
.v2-livestream-embed { | ||
border-radius: var(--border-radius); | ||
aspect-ratio: 16/9; | ||
width: 100%; | ||
} | ||
|
||
.v2-livestream-embed iframe { | ||
display: block; | ||
} | ||
|
||
.v2-livestream-embed .cookie-message { | ||
aspect-ratio: 16/9; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
gap: 16px; | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__title, | ||
.v2-livestream-embed .cookie-message__text { | ||
max-width: var(--text-block-max-width); | ||
margin: 0 auto; | ||
text-align: center; | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__title { | ||
font: var(--f-heading-5-font-size)/var(--f-heading-5-line-height) var(--ff-volvo-novum-medium); | ||
letter-spacing: var(--f-heading-5-letter-spacing); | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__text { | ||
font: var(--f-body-font-size)/var(--f-body-line-height) var(--font-family-body); | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__text a { | ||
color: inherit; | ||
text-decoration: underline; | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__text a:hover { | ||
color: var(--c-grey-300); | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__button-container { | ||
margin-top: 16px; | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
gap: 16px; | ||
} | ||
|
||
@media screen and (min-width: 1200px) { | ||
.v2-livestream-embed .cookie-message__title { | ||
font-size: var(--f-heading-4-font-size); | ||
line-height: var(--f-heading-4-line-height); | ||
} | ||
|
||
.v2-livestream-embed .cookie-message__text { | ||
font-size: var(--f-body-2-font-size); | ||
line-height: var(--f-body-2-line-height); | ||
} | ||
} |
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,113 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable no-unused-vars */ | ||
/* eslint-disable max-len */ | ||
import { loadScript } from '../../scripts/lib-franklin.js'; | ||
import { createElement, getTextLabel, isExternalVideoAllowed } from '../../scripts/common.js'; | ||
import { updateCookieValue } from '../../scripts/delayed.js'; | ||
import { hideModal } from '../../common/modal/modal.js'; | ||
|
||
let player; | ||
|
||
function onPlayerReady(event) { | ||
console.info('Event: onPlayerReady'); | ||
event.target.playVideo(); | ||
} | ||
|
||
function onPlayerError(event) { | ||
console.warn('Event: onPlayerError'); | ||
console.warn(event.data); | ||
} | ||
|
||
function onPlayerAutoplayBlocked(event) { | ||
console.warn('Event: onPlayerAutoplayBlocked'); | ||
console.warn(event.data); | ||
} | ||
|
||
export function playVideo() { | ||
if (player && player.playVideo) { | ||
player.playVideo(); | ||
} | ||
} | ||
|
||
export default function decorate(block) { | ||
loadScript('https://www.youtube.com/iframe_api'); | ||
|
||
let [videoLink] = block.querySelectorAll('a'); | ||
const [, videoId] = videoLink.getAttribute('href').split('/embed/'); | ||
const [videoCode] = videoId.split('?'); | ||
videoLink = videoCode; | ||
|
||
console.info(`video id: ${videoLink}`); | ||
|
||
if (!videoLink) { | ||
block.innerHTML = ''; | ||
/* eslint-disable-next-line no-console */ | ||
console.warn('V2 Livestream Embed block: There is no video link. Please check the provided URL.'); | ||
return; | ||
} | ||
|
||
// eslint-disable-next-line func-names | ||
window.onYouTubeIframeAPIReady = function () { | ||
setTimeout(() => { | ||
// eslint-disable-next-line no-undef | ||
player = new YT.Player('livestream', { | ||
events: { | ||
onReady: onPlayerReady, | ||
onError: onPlayerError, | ||
onAutoplayBlocked: onPlayerAutoplayBlocked, | ||
}, | ||
}); | ||
}, 3000); | ||
}; | ||
|
||
if (!isExternalVideoAllowed()) { | ||
const img = block.querySelector('picture img'); | ||
block.innerHTML = ''; | ||
|
||
const cookieMsgContainer = createElement('div', { | ||
classes: 'cookie-message', | ||
}); | ||
cookieMsgContainer.style.background = `linear-gradient(180deg, rgba(0, 0, 0, 0.00) 0%, rgba(0, 0, 0, 0.80) 100%), url(${img.src}) center / cover no-repeat`; | ||
|
||
const cookieMessage = document.createRange().createContextualFragment(` | ||
<h3 class="cookie-message__title">${getTextLabel('single video message title')}</h3> | ||
${getTextLabel('single video message text')} | ||
<div class="cookie-message__button-container"> | ||
<button class="primary dark">${getTextLabel('single video message button')}</button> | ||
<button class="button secondary dark">${getTextLabel('single video message button deny')}</button> | ||
</div> | ||
`); | ||
|
||
cookieMsgContainer.append(cookieMessage); | ||
block.append(cookieMsgContainer); | ||
|
||
block.querySelector('.cookie-message__button-container .primary')?.addEventListener('click', () => { | ||
const domain = 'localhost'; | ||
const path = '/'; // assuming root path | ||
const expirationDate = new Date(); | ||
expirationDate.setFullYear(expirationDate.getFullYear() + 1); // 1 year from now | ||
const sameSite = 'Lax'; | ||
|
||
console.log('updatecookie'); | ||
|
||
updateCookieValue('OptanonConsent=', 'C0005:0', 'C0005:1', domain, path, expirationDate, sameSite); | ||
}); | ||
|
||
block.querySelector('.cookie-message__button-container .secondary')?.addEventListener('click', () => { | ||
hideModal(); | ||
}); | ||
|
||
return; | ||
} | ||
|
||
const iframeYT = document.createRange().createContextualFragment(` | ||
<iframe class="v2-livestream-embed" id="livestream" | ||
frameborder="0" allowfullscreen="" allow="autoplay" | ||
src="https://www.youtube.com/embed/${videoLink}?color=white&rel=0&playsinline=1&enablejsapi=1&autoplay=1"> | ||
</iframe> | ||
`); | ||
|
||
block.innerHTML = ''; | ||
|
||
block.append(...iframeYT.childNodes); | ||
} |
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
Oops, something went wrong.