| | (function(){ |
| | function preventAll(el){ |
| | var evs = ['click','dblclick','contextmenu','mousedown','mouseup','touchstart','touchend','pointerdown','pointerup','keydown']; |
| | evs.forEach(function(evt){ |
| | el.addEventListener(evt, function(e){ e.preventDefault(); e.stopPropagation(); return false; }, true); |
| | }); |
| | } |
| |
|
| | function prepareVideo(v){ |
| | if (!v || v.dataset.noUiPrepared) return; |
| | v.dataset.noUiPrepared = '1'; |
| | v.autoplay = true; |
| | v.muted = true; |
| | v.loop = true; |
| | v.playsInline = true; |
| | v.setAttribute('playsinline',''); |
| | v.setAttribute('webkit-playsinline',''); |
| | v.removeAttribute('controls'); |
| | v.controls = false; |
| | try { v.disablePictureInPicture = true; } catch(e){} |
| | try { v.setAttribute('tabindex','-1'); } catch(e){} |
| | try { v.setAttribute('aria-hidden','true'); } catch(e){} |
| | preventAll(v); |
| | var fig = (v.closest && v.closest('figure.wp-block-video')) || v.parentElement; |
| | if (fig){ |
| | preventAll(fig); |
| | if (!fig.querySelector('.no-ui-video-cover')){ |
| | var cover = document.createElement('div'); |
| | cover.className = 'no-ui-video-cover'; |
| | fig.appendChild(cover); |
| | |
| | try { |
| | var started = false; |
| | var startAudio = function(){ |
| | if (started) return; started = true; |
| | var a = document.getElementById('bg-music') || document.querySelector('audio'); |
| | if (a) { |
| | try { a.muted = false; } catch(e){} |
| | try { a.play(); } catch(e){} |
| | } |
| | }; |
| | ['pointerdown','touchstart','click'].forEach(function(evt){ |
| | cover.addEventListener(evt, function(){ startAudio(); }, { capture:true, once:true }); |
| | }); |
| | } catch(e){} |
| | preventAll(cover); |
| | } |
| | } |
| | function tryPlay(){ |
| | var p; try { p = v.play(); } catch(e){} |
| | if (p && typeof p.catch === 'function') p.catch(function(){}); |
| | } |
| | tryPlay(); |
| | } |
| |
|
| | |
| | function getBgAudio(){ |
| | return document.getElementById('bg-music') || document.querySelector('audio'); |
| | } |
| |
|
| | function setupAudioUnlock(a){ |
| | a = a || getBgAudio(); |
| | if (!a) return; |
| | var fired = false; |
| | function unlock(){ |
| | if (fired) return; fired = true; |
| | try { a.muted = false; } catch(e){} |
| | try { a.play(); } catch(e){} |
| | } |
| | ['pointerdown','touchstart','click','keydown'].forEach(function(evt){ |
| | window.addEventListener(evt, function handler(){ unlock(); window.removeEventListener(evt, handler, true); }, { capture:true }); |
| | }); |
| | document.addEventListener('visibilitychange', function(){ if (!document.hidden && !fired) unlock(); }); |
| | } |
| |
|
| | function autoPlayAudioImmediate(){ |
| | var a = getBgAudio(); |
| | if (!a) return; |
| | try { a.loop = true; } catch(e){} |
| | try { a.autoplay = true; } catch(e){} |
| | try { if (!a.preload) a.preload = 'auto'; } catch(e){} |
| | try { a.muted = false; } catch(e){} |
| | var p; |
| | try { p = a.play(); } catch(e) { p = null; } |
| | if (p && typeof p.then === 'function') { |
| | p.then(function(){ }).catch(function(){ |
| | try { a.muted = true; a.play().catch(function(){}); } catch(e){} |
| | setupAudioUnlock(a); |
| | }); |
| | } else { |
| | |
| | setupAudioUnlock(a); |
| | } |
| | } |
| |
|
| | function setupAll(){ |
| | var vids = document.querySelectorAll('figure.wp-block-video video, video#mainVideo, video.auto-noui'); |
| | vids.forEach(prepareVideo); |
| | autoPlayAudioImmediate(); |
| | } |
| |
|
| | if (document.readyState === 'loading') { |
| | document.addEventListener('DOMContentLoaded', setupAll); |
| | } else { |
| | setupAll(); |
| | } |
| | try { |
| | var mo = new MutationObserver(function(muts){ |
| | muts.forEach(function(m){ |
| | m.addedNodes && m.addedNodes.forEach(function(n){ |
| | if (n.nodeType === 1) { |
| | if (n.matches && (n.matches('video') || n.matches('figure.wp-block-video'))){ |
| | if (n.matches('video')) prepareVideo(n); |
| | n.querySelectorAll && n.querySelectorAll('video').forEach(prepareVideo); |
| | } else { |
| | n.querySelectorAll && n.querySelectorAll('video').forEach(prepareVideo); |
| | } |
| | } |
| | }); |
| | }); |
| | }); |
| | mo.observe(document.documentElement, { childList: true, subtree: true }); |
| | } catch(e){} |
| | })(); |
| |
|