<div class="pageheader-video pageheader-video--idle" data-background-image=../../.html>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1">
<div class="pageheader-content">
<h1 class="heading-page heading-page--pageheader ">Pageheader video</h1>
<p class="paragraph paragraph--pageheader ">Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Quisque velit nisi, pretium ut lacinia in, elementum id enim.</p>
<button type="button" class="button button--large">
See more
</button>
</div>
</div>
</div>
</div>
</div>
<div class="pageheader-video pageheader-video--idle" data-background-image={{ path '{{backgroundImagePath}}' }}>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-10 col-sm-offset-1">
{{ render '@pageheader-content' content }}
</div>
</div>
</div>
{{#if selfHostVideoMp4Path}}
<video class="pageheader-video__video" src="{{ selfHostVideoMp4Path }}" type="video/mp4" autoplay muted loop playsinline>
{{/if}}
{{#if selfHostVideoWebmPath}}
<video class="pageheader-video__video" src="{{ selfHostVideoWebmPath }}" type="video/webm" autoplay muted loop playsinline>
{{/if}}
{{#if youtubeId}}
<div class="video-wrapper" data-youtube-id="{{ youtubeId }}">
<div class="tv">
<div id="player" class="screen"></div>
</div>
</div>
{{/if}}
{{#if vimeoId}}
<div class="vimeo-wrapper">
<iframe class="vimeo__iframe" data-vimeoId="{{vimeoId}}" width="100%" height="100%" frameborder="0" allow="autoplay; encrypted-media" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
{{/if}}
</div>
{
"content": {
"header": {
"text": "Pageheader video"
},
"description": {
"text": "Vivamus magna justo, lacinia eget consectetur sed, convallis at tellus. Quisque velit nisi, pretium ut lacinia in, elementum id enim."
},
"button": {
"text": "See more"
}
}
}
"use strict";
var novicell = novicell || {};
novicell.pageheaderVideoYoutube =
novicell.pageheaderVideoYoutube ||
new function () {
var videoStart = 0;
var player;
var youtubeId;
const pageheaderBackground = document.querySelector(".pageheader-video");
this.init = function () {
const youtubeVideoWrapper = document.querySelector(".tv");
if (youtubeVideoWrapper != null) {
youtubeId = document
.querySelector(".video-wrapper")
.getAttribute("youtube-id");
var tag = document.createElement("script");
tag.src = "https://www.youtube.com/player_api";
var lastScriptTag = document.getElementsByTagName("script")[
document.getElementsByTagName("script").length - 1
];
lastScriptTag.parentNode.insertBefore(tag, lastScriptTag);
}
};
this.onPlayerReady = function (event) {
novicell.pageheaderVideoYoutube.vidRescale();
event.target.mute();
event.target.seekTo(videoStart);
};
this.onPlayerStateChange = function (e) {
var tv2 = document.getElementById("player");
if (e.data === 1) {
tv2.classList.add("active");
} else if (e.data === 0) {
player.seekTo(videoStart);
}
};
this.vidRescale = function () {
var tvScreen = document.querySelector(".tv .screen");
if (tvScreen != null) {
var w = window.innerWidth;
player.setSize(w, (w / 16) * 9);
}
};
this.onErrorResponse = function (event) {
// In case of bad response, kill the player and add the background image.
// Currently, the url for the BG image is stored on the pageheader-video wrapper itself.
// An alternative would be having a css class added that holds a background image attribute and the path value already, and simply append the classname to the element
pageheaderBackground.style.backgroundImage = `url(${pageheaderBackground.dataset.backgroundImage})`;
event.target.destroy();
};
this.onYouTubeIframeAPIReady = function () {
player = new YT.Player("player", {
videoId: youtubeId,
playerVars: {
autoplay: 0,
autohide: 1,
loop: 1,
modestbranding: 1,
rel: 0,
showinfo: 0, //This is deprecated apparently
controls: 0,
disablekb: 1,
enablejsapi: 0,
iv_load_policy: 3
},
events: {
onReady: novicell.pageheaderVideoYoutube.onPlayerReady,
onStateChange: novicell.pageheaderVideoYoutube.onPlayerStateChange,
onError: novicell.pageheaderVideoYoutube.onErrorResponse
}
});
};
}();
function onYouTubeIframeAPIReady() {
novicell.pageheaderVideoYoutube.onYouTubeIframeAPIReady();
}
window.addEventListener(
"load",
function () {
novicell.pageheaderVideoYoutube.vidRescale();
},
true
);
window.addEventListener(
"resize",
function () {
novicell.pageheaderVideoYoutube.vidRescale();
},
true
);
/**
* Component: pageheader-video
*/
:root {
--hero-text-color: var(--color-white);
--video-background-color: var(--color-black);
--video-content-opacity: 70%;
--video-height: 600px;
}
.pageheader-video {
position: relative;
display: flex;
align-items: center;
height: calc(var(--video-height) / 1.5);
overflow: hidden;
background-size: cover;
@media (--viewport-lg-min) {
height: var(--video-height);
}
@media (--viewport-sm-max) {
background-image: url("/dist/images/placeholder-images/hero--mona-eendra-313518.jpg");
}
&__video {
@media (--viewport-xs-min) {
display: block;
position: absolute;
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: 0;
transform: translateX(-50%) translateY(-50%);
object-fit: contain;
}
&--iframe-video {
&::before {
display: block;
content: '';
width: 100%;
padding-top: calc((9 / 16) * 100%);
}
iframe {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
}
}
}
//vimeo
.vimeo-wrapper {
display: none;
@media (--viewport-sm-min) {
display: block;
width: 100%;
pointer-events: none;
overflow: hidden;
position: absolute;
height: 100%;
}
}
.vimeo-wrapper iframe {
display: none;
@media (--viewport-sm-min) {
display: block;
width: 100vw;
height: 56.25vw;
/* Given a 16:9 aspect ratio, 16/9*100 = 177.77 */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
//youtube
.video-wrapper {
display: none;
@media (--viewport-xs-min) {
display: block;
position: absolute;
width: 100%;
margin: 0;
height: 100%;
z-index: 0;
overflow: hidden;
}
}
.tv {
display: none;
pointer-events: none;
@media (--viewport-sm-min) {
display: block;
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 100%;
height: 100%;
overflow: hidden;
}
.screen {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
margin: auto;
opacity: 0;
transition: opacity 0.5s;
&.active {
opacity: 1;
}
}
}
'use strict';
var novicell = novicell || {};
novicell.pageheaderVideo =
novicell.pageheaderVideo ||
new function () {
this.init = function () {
if (screenWidth()) {
const vimeoIframeList = document.querySelectorAll(".vimeo__iframe") || false;
const youtubeList = document.querySelectorAll(".video-wrapper[data-youtube-id]") || false;
if (vimeoIframeList) {
for (let i = 0; i < vimeoIframeList.length; i++) {
// Simply change dataset src to the src attribute.
let vimeoId = vimeoIframeList[i].dataset.vimeoid;
vimeoIframeList[i].src = `https://player.vimeo.com/video/${vimeoId}?autoplay=1&loop=1&color=000000&title=0&byline=0&portrait=0&muted=1&controls=0&background=1`;
}
}
if (youtubeList) {
for (let i = 0; i < youtubeList.length; i++) {
// Grab the data-youtube-id from the elements in the list and add the value as "youtube-id"
// With youtube-id, the specific YT javascript will fire
youtubeList[i].setAttribute("youtube-id", youtubeList[i].dataset.youtubeId);
}
}
}
};
}();
function screenWidth() {
return window.screen.width > 768;
}
NB! The default pageheader-video does not contain a video. This is because each variation specify how the video is made, therefore you need to choose a variant to see a video. So the default is working as intended :)