<div class="background-fullscreen--idle background-fullscreen" data-background-image="../../dist/images/placeholder-images/hero--mona-eendra-313518.jpg">
<iframe class="iframe vimeo__iframe" data-vimeoid="190043829" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen>
</iframe>
</div>
{{> @pageheader-video-fullscreen vimeoid="190043829" backgroundImagePath="/dist/images/placeholder-images/hero--mona-eendra-313518.jpg" }}
/* No context defined for this component. */
'use strict';
var novicell = novicell || {};
novicell.pageheaderVideoFullscreenVimeo =
novicell.pageheaderVideoFullscreenVimeo ||
new function () {
this.init = function () {
if (screenWidth()) {
const fullscreenBackground = document.querySelector(".background-fullscreen") || false;
if (fullscreenBackground) {
// Remove class associated with background image
fullscreenBackground.classList.remove("background-fullscreen--idle");
// Add class associated with ajax gif loader
fullscreenBackground.classList.add("background-fullscreen--loading");
}
const vimeoIframeList = document.querySelector(".vimeo__iframe") || false;
this.removeAjaxLoader = function (element) {
// Function for removing the class associated with the ajax loading gif.
element.classList.remove("background-fullscreen--loading");
};
if (vimeoIframeList) {
const vimeoId = vimeoIframeList.dataset.vimeoid;
const fullUrl = `https://player.vimeo.com/video/${vimeoId}?autoplay=1&loop=1&color=000000&title=0&byline=0&portrait=0&muted=1&controls=0&background=1`;
const shortUrl = `https://vimeo.com/${vimeoId}`;
validateVimeoId(shortUrl)
.then(response => {
if (response === 200) {
// Load video if the vimeo id exists
vimeoIframeList.src = fullUrl;
} else {
// If bad status, we remove the iframe and add the fallback BG image
fullscreenBackground.style.backgroundImage = `url(${fullscreenBackground.dataset.backgroundImage})`;
vimeoIframeList.remove();
}
}).then(() => {
// As we are not using the vimeo API, we can't listen for events on the Iframe.
// Consequently, I've had to make a guesstimate on when's a relatively good time to remove the ajax loader
setTimeout(() => {
novicell.pageheaderVideoFullscreenVimeo.removeAjaxLoader(fullscreenBackground);
}, 5000);
}).catch(err => console.log(err));
}
}
};
}();
function screenWidth() {
return window.screen.width > 768;
}
// Function for checking vimeo video validity
function validateVimeoId(url) {
let options = {
method: 'GET'
};
// Anything but status 200 will throw an error
return fetch(`https://vimeo.com/api/oembed.json?url=${encodeURIComponent(url)}`, options)
.then((response) => {
if (response.status === 200) {
return response.status;
} else {
throw Error(`Bad response: ${response.status}`);
}
})
.catch(err => console.log(err));
}
/**
* Component: pageheader-video-fullscreen
*/
.background-fullscreen {
/* Position it relative if you want to be able to scroll below the video */
position: absolute;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
z-index: -1;
pointer-events: none;
overflow: hidden;
background-size: cover;
background-image: none;
&--idle {
background-image: url("/dist/images/placeholder-images/hero--mona-eendra-313518.jpg");
}
&--loading {
background-image: url("/dist/images/outro_2-loader.gif");
background-size: auto;
background-repeat: no-repeat;
background-position: center;
}
& iframe {
width: 100vw;
height: 56.25vw;
/* Given a 16:9 aspect ratio, 9/16*100 = 56.25 */
min-height: 100vh;
min-width: 190vh;
/* Given a 16:9 aspect ratio, 16/9*100 = 177.77 */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
&__video {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
}
&__foreground {
display: flex;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
font-size: 1.7em;
text-decoration: overline underline;
}
}
In production, consider having preconnect links in the head for faster connection with YT and Vimeo:
link rel=”preconnect” href=”https://player.vimeo.com"
link rel=”preconnect” href=”https://www.youtube.com"