From 40934841435a65aac4e5335d7e377e0430d57f3e Mon Sep 17 00:00:00 2001 From: Jieiku Date: Tue, 31 May 2022 03:02:17 -0700 Subject: SEO Validation & Cleanup --- static/lite-vimeo.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 static/lite-vimeo.min.js (limited to 'static') diff --git a/static/lite-vimeo.min.js b/static/lite-vimeo.min.js new file mode 100644 index 0000000..692eea0 --- /dev/null +++ b/static/lite-vimeo.min.js @@ -0,0 +1 @@ +let LiteVimeoEmbed=(()=>{class i extends HTMLElement{constructor(){super(),this.iframeLoaded=!1,this.setupDom()}static get observedAttributes(){return["videoid"]}connectedCallback(){this.addEventListener("pointerover",i.warmConnections,{once:!0}),this.addEventListener("click",()=>this.addIframe())}get videoId(){return encodeURIComponent(this.getAttribute("videoid")||"")}set videoId(e){this.setAttribute("videoid",e)}get videoTitle(){return this.getAttribute("videotitle")||"Video"}set videoTitle(e){this.setAttribute("videotitle",e)}get videoPlay(){return this.getAttribute("videoPlay")||"Play"}set videoPlay(e){this.setAttribute("videoPlay",e)}get videoStartAt(){return this.getAttribute("videoPlay")||"0s"}set videoStartAt(e){this.setAttribute("videoPlay",e)}get autoLoad(){return this.hasAttribute("autoload")}set autoLoad(e){e?this.setAttribute("autoload",""):this.removeAttribute("autoload")}get autoPlay(){return this.hasAttribute("autoplay")}set autoPlay(e){e?this.setAttribute("autoplay","autoplay"):this.removeAttribute("autoplay")}setupDom(){const e=this.attachShadow({mode:"open"});e.innerHTML=`
`,this.domRefFrame=this.shadowRoot.querySelector("#frame"),this.domRefImg={fallback:this.shadowRoot.querySelector("#fallbackPlaceholder"),webp:this.shadowRoot.querySelector("#webpPlaceholder"),jpeg:this.shadowRoot.querySelector("#jpegPlaceholder")},this.domRefPlayButton=this.shadowRoot.querySelector(".lvo-playbtn")}setupComponent(){this.initImagePlaceholder(),this.domRefPlayButton.setAttribute("aria-label",this.videoPlay+": "+this.videoTitle),this.setAttribute("title",this.videoPlay+": "+this.videoTitle),this.autoLoad&&this.initIntersectionObserver()}attributeChangedCallback(e,t,o){"videoid"===e&&t!==o&&(this.setupComponent(),this.domRefFrame.classList.contains("lvo-activated")&&(this.domRefFrame.classList.remove("lvo-activated"),this.shadowRoot.querySelector("iframe").remove()))}addIframe(){var e;this.iframeLoaded||(e=this.autoLoad&&this.autoPlay||!this.autoLoad?"autoplay=1":"",e=new URL(`/video/${this.videoId}?${e}&#t=`+this.videoStartAt,"https://player.vimeo.com/"),this.domRefFrame.insertAdjacentHTML("beforeend",``),this.domRefFrame.classList.add("lvo-activated"),this.iframeLoaded=!0)}async initImagePlaceholder(){i.addPrefetch("preconnect","https://i.vimeocdn.com/");var e=`https://vimeo.com/api/v2/video/${this.videoId}.json`;let t=(await(await fetch(e)).json())[0].thumbnail_large;var e=t.substr(t.lastIndexOf("/")+1).split("_")[0],o=`https://i.vimeocdn.com/video/${e}.jpg?mw=1100&mh=619&q=70`;this.domRefImg.webp.srcset=`https://i.vimeocdn.com/video/${e}.webp?mw=1100&mh=619&q=70`,this.domRefImg.jpeg.srcset=o,this.domRefImg.fallback.src=o,this.domRefImg.fallback.setAttribute("aria-label",this.videoPlay+": "+this.videoTitle),this.domRefImg.fallback.setAttribute("alt",this.videoPlay+": "+this.videoTitle)}initIntersectionObserver(){if("IntersectionObserver"in window&&"IntersectionObserverEntry"in window){const e=new IntersectionObserver((e,t)=>{e.forEach(e=>{e.isIntersecting&&!this.iframeLoaded&&(i.warmConnections(),this.addIframe(),t.unobserve(this))})},{root:null,rootMargin:"0px",threshold:0});e.observe(this)}}static addPrefetch(e,t,o){const i=document.createElement("link");i.rel=e,i.href=t,o&&(i.as=o),i.crossOrigin="true",document.head.append(i)}static warmConnections(){i.preconnected||(i.addPrefetch("preconnect","https://f.vimeocdn.com"),i.addPrefetch("preconnect","https://player.vimeo.com"),i.addPrefetch("preconnect","https://i.vimeocdn.com"),i.preconnected=!0)}}return i.preconnected=!1,i})();customElements.define("lite-vimeo",LiteVimeoEmbed);export{LiteVimeoEmbed}; -- cgit v1.3.1