1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
|
|
import connectionManager from"./../emby-apiclient/connectionmanager.js";import dom from"./../dom.js";import playbackManager from"./../common/playback/playbackmanager.js";import MethodTimer from"./../common/methodtimer.js";let uiDependencies=["css!modules/backdrop/style.css"],supportsAsyncDecodedImages=dom.supportsAsyncDecodedImages(),supportsObjectFit=CSS.supports("object-fit","contain"),supportsImgSrcSet="srcset"in HTMLImageElement.prototype,RotationIntervalMs=24e3;function loadDependencies(){var deps=uiDependencies;deps.length&&require(deps)}loadDependencies();let supportsCssAnimations=CSS.supports("animation-name","a");function enableAnimation(){return supportsCssAnimations&&dom.supportsEventListenerOnce()}function enableRotation(){return!!enableAnimation()}function Backdrop(){}function mapImageSourceToUrl(source){return source.url}function getImageInfoId(imageInfo){var id=imageInfo.id;return id=id||(imageInfo.id=imageInfo.sources.map(mapImageSourceToUrl).join("|"))}function getFallbackImageSource(imageInfo){return imageInfo.sources[imageInfo.sources.length-1]}function mapSourceToString(source){return source.url+" "+source.width+"w"}function setSrcSetIntoImg(img,sources){(sources=sources.slice(0)).pop(),img.sizes="100vw",img.srcset=sources.map(mapSourceToString).join(",")}Backdrop.prototype.load=function(imageInfo,animate,parent,existingBackdropImage){let img=new Image,self=(img.setAttribute("data-id",getImageInfoId(imageInfo)),img.setAttribute("draggable","false"),img.setAttribute("fetchpriority","low"),supportsObjectFit&&(supportsAsyncDecodedImages&&img.setAttribute("decoding","async"),img.setAttribute("loading","lazy")),img.classList.add("backdropImage"),!1===imageInfo.coverImage&&img.classList.add("backdropImage-contain"),this);this.previousBackdropImage=existingBackdropImage;img.onload=function(){if(self.isDestroyed)self.removePreviousBackdropImage();else{let backdropImage=supportsObjectFit?img:document.createElement("div");if(supportsObjectFit||(backdropImage.style.backgroundImage="url('"+getFallbackImageSource(imageInfo).url+"')"),backdropImage.classList.add("backdropImage","displayingBackdropImage"),!1===imageInfo.coverImage&&backdropImage.classList.add("backdropImage-contain"),self.elem=backdropImage,internalBackdrop(!0),animate&&enableAnimation()&&backdropImage.classList.add("backdropImageFadeIn"),supportsObjectFit||parent.appendChild(backdropImage),img.style.visibility=null,enableAnimation()){let onAnimationComplete=function(){dom.removeEventListener(backdropImage,dom.whichAnimationEvent(),onAnimationComplete,{once:!0}),dom.removeEventListener(backdropImage,dom.whichAnimationCancelEvent(),onAnimationComplete,{once:!0}),self.removePreviousBackdropImage()};dom.addEventListener(backdropImage,dom.whichAnimationEvent(),onAnimationComplete,{once:!0}),dom.addEventListener(backdropImage,dom.whichAnimationCancelEvent(),onAnimationComplete,{once:!0})}else self.removePreviousBackdropImage()}},supportsObjectFit&&(img.style.visibility="hidden"),img.src=getFallbackImageSource(imageInfo).url,supportsImgSrcSet&&supportsObjectFit&&1<imageInfo.sources.length&&setSrcSetIntoImg(img,imageInfo.sources),supportsObjectFit&&parent.appendChild(img),this.imageInfo=imageInfo},Backdrop.prototype.removePreviousBackdropImage=function(){var existingBackdropImage=this.previousBackdropImage;existingBackdropImage&&(this.previousBackdropImage=null,existingBackdropImage.remove())},Backdrop.prototype.cancelAnimation=function(){var elem=this.elem;elem&&(elem.classList.remove("backdropImageFadeIn"),this.elem=null)},Backdrop.prototype.destroy=function(){this.isDestroyed=!0,this.cancelAnimation(),this.removePreviousBackdropImage()};let backdropContainer,backgroundContainer=document.querySelector(".backgroundContainer");function getBackdropContainer(){return(backdropContainer=backdropContainer||document.querySelector(".backdropContainer"))||((backdropContainer=document.createElement("div")).classList.add("backdropContainer"),document.body.insertBefore(backdropContainer,document.body.firstChild)),backdropContainer}let hasExternalBackdrop,currentLoad
|