| 1 |
(function () { |
| 2 |
function buildIframeSrc(provider, videoId) { |
| 3 |
if (provider === 'vimeo') { |
| 4 |
return 'https://player.vimeo.com/video/' + videoId + '?autoplay=1&title=0&byline=0&portrait=0'; |
| 5 |
} |
| 6 |
/* Default: YouTube */ |
| 7 |
return 'https://www.youtube.com/embed/' + videoId + '?autoplay=1&rel=0&modestbranding=1'; |
| 8 |
} |
| 9 |
|
| 10 |
function initFacade(facade) { |
| 11 |
var provider = facade.getAttribute('data-provider') || 'youtube'; |
| 12 |
var videoId = facade.getAttribute('data-vid') || ''; |
| 13 |
var pulsing = facade.getAttribute('data-pulsing') === '1'; |
| 14 |
|
| 15 |
if (!videoId) return; |
| 16 |
|
| 17 |
/* Apply pulse class if needed */ |
| 18 |
if (pulsing) { |
| 19 |
var playInner = facade.querySelector('.bkbg-vf-play > div'); |
| 20 |
if (playInner) playInner.classList.add('bkbg-vf-play-btn-inner', 'is-pulsing'); |
| 21 |
} |
| 22 |
|
| 23 |
facade.addEventListener('click', function onClick() { |
| 24 |
facade.removeEventListener('click', onClick); |
| 25 |
|
| 26 |
/* Freeze current dimensions */ |
| 27 |
var rect = facade.getBoundingClientRect(); |
| 28 |
facade.style.height = rect.height + 'px'; |
| 29 |
facade.style.paddingBottom = '0'; |
| 30 |
|
| 31 |
/* Remove thumb / overlay / play / text */ |
| 32 |
while (facade.firstChild) { facade.removeChild(facade.firstChild); } |
| 33 |
|
| 34 |
/* Insert iframe wrapper */ |
| 35 |
var wrap = document.createElement('div'); |
| 36 |
wrap.className = 'bkbg-vf-iframe-wrap'; |
| 37 |
var iframe = document.createElement('iframe'); |
| 38 |
iframe.src = buildIframeSrc(provider, videoId); |
| 39 |
iframe.setAttribute('allow', 'autoplay; fullscreen; picture-in-picture'); |
| 40 |
iframe.setAttribute('allowfullscreen', ''); |
| 41 |
iframe.setAttribute('title', 'Video player'); |
| 42 |
iframe.style.border = '0'; |
| 43 |
wrap.appendChild(iframe); |
| 44 |
facade.appendChild(wrap); |
| 45 |
|
| 46 |
facade.style.cursor = 'default'; |
| 47 |
}); |
| 48 |
} |
| 49 |
|
| 50 |
function init() { |
| 51 |
var wrappers = document.querySelectorAll('.bkbg-vf-wrapper'); |
| 52 |
wrappers.forEach(function(wrapper) { |
| 53 |
var facade = wrapper.querySelector('.bkbg-vf-facade'); |
| 54 |
if (facade) initFacade(facade); |
| 55 |
}); |
| 56 |
|
| 57 |
/* Fade-in section on scroll */ |
| 58 |
var io = new IntersectionObserver(function(entries, obs) { |
| 59 |
entries.forEach(function(entry) { |
| 60 |
if (entry.isIntersecting) { |
| 61 |
obs.unobserve(entry.target); |
| 62 |
entry.target.classList.add('is-visible'); |
| 63 |
} |
| 64 |
}); |
| 65 |
}, { threshold: 0.1 }); |
| 66 |
|
| 67 |
wrappers.forEach(function(w){ io.observe(w); }); |
| 68 |
} |
| 69 |
|
| 70 |
if (document.readyState !== 'loading') { init(); } |
| 71 |
else { document.addEventListener('DOMContentLoaded', init); } |
| 72 |
})(); |
| 73 |
|