2 lines
2.1 KiB
JavaScript
2 lines
2.1 KiB
JavaScript
import{onDOMReady as o,$$ as n}from"./utils.js";const i=new Map;let t=!1,e=!1;async function s(){if(!t&&!e){e=!0,console.debug("Loading VideoJS dynamically");try{if(window.videojs)return t=!0,void(e=!1);const o=document.createElement("link");o.rel="stylesheet",o.href="/css/vendor/video-js.min.css",document.head.appendChild(o);const s=document.createElement("script");s.src="/js/videojs/video.min.js";const a=new Promise((o=>{s.onload=o}));document.head.appendChild(s),await a;const r=document.createElement("script");r.src="/js/videojs/videojs-http-streaming.min.js";const d=new Promise((o=>{r.onload=o}));document.head.appendChild(r),await d,t=!0,e=!1,function(){const o=n(".video-js");0!==o.length&&o.forEach((o=>{const n=o.getBoundingClientRect();n.top<window.innerHeight&&n.bottom>0&&!i.has(o.id)&&c(o)}))}()}catch(o){console.error("Error loading VideoJS:",o),e=!1}}}async function c(o){if(!i.has(o.id))if(window.videojs||(await s(),window.videojs))if(o.classList.contains("vjs-has-started")||o.classList.contains("vjs-paused")||o.classList.contains("vjs-playing"))console.debug(`Player "${o.id}" already initialized by VideoJS`);else try{const n=window.videojs(o.id,{fluid:!0,responsive:!0,html5:{vhs:{enableLowInitialPlaylist:!0,limitRenditionsByPlayerDimensions:!0,useBandwidthFromLocalStorage:!0}},playbackRates:[.75,1,1.25,1.5,2]});i.set(o.id,n)}catch(n){console.debug(`Error initializing player "${o.id}": ${n.message}`)}else console.warn("Failed to load VideoJS")}function a(){i.forEach(((o,n)=>{try{o&&"function"==typeof o.dispose&&o.dispose()}catch(o){console.debug(`Error disposing player ${n}: ${o.message}`)}})),i.clear()}o((()=>{!function(){const o=n(".video-js");if(0===o.length)return;let i=!1;const a=()=>{i||(i=!0,setTimeout((()=>{s()}),1e3),["click","touchstart","scroll"].forEach((o=>{document.removeEventListener(o,a)})))};["click","touchstart","scroll"].forEach((o=>{document.addEventListener(o,a)}));const r=new IntersectionObserver((o=>{o.forEach((o=>{o.isIntersecting&&(t||e||!i||s(),t&&c(o.target))}))}),{rootMargin:"0px",threshold:.1});o.forEach((o=>{r.observe(o)}))}(),window.addEventListener("beforeunload",a)}));//# sourceMappingURL=video-init.modern.min.js.map
|