/** * jquery.youtube-background v1.0.14 | Nikola Stamatovic <@stamat> | MIT */ !function(){"use strict";function t(t,e){return t.classList?t.classList.contains(e):new RegExp("\\b"+e+"\\b").test(t.className)}function e(e,s){if(e.classList){const t=s.split(" ");for(var i=0;i',initialState:!1,stateClassName:"paused",condition_parameter:"autoplay",stateChildClassNames:["fa-pause-circle","fa-play-circle"],actions:["play","pause"]}),this.params["mute-button"]&&this.generateActionButton({name:"mute",className:"mute-toggle",innerHtml:'',initialState:!0,stateClassName:"muted",condition_parameter:"muted",stateChildClassNames:["fa-volume-up","fa-volume-mute"],actions:["unmute","mute"]}))},this.__init__()}function m(t,e,s,a){this.is_mobile=i(),this.element=t,this.vid=s,this.uid=a,this.player=null,this.buttons={},this.state={},this.state.play=!1,this.state.mute=!1,this.params={};const r={autoplay:!0,muted:!0,loop:!0,mobile:!1,resolution:"16:9","inline-styles":!0,"fit-box":!1,offset:200,"start-at":0,poster:null};this.__init__=function(){this.vid&&(this.params=n(e,r,this.element,["data-ytbg-","data-vbg-"]),this.params.pause&&(this.params["play-button"]=this.params.pause),this.params.resolution_mod=o(this.params.resolution),this.state.playing=this.params.autoplay,this.state.muted=this.params.muted,this.buildHTML(),this.injectPlayer())},this.__init__()}function h(t,e,s,a){this.is_mobile=i(),this.element=t,this.link=s.link,this.ext=s.id,this.uid=a,this.player=null,this.buttons={},this.state={},this.state.play=!1,this.state.mute=!1,this.params={};const r={ogv:"video/ogg",ogm:"video/ogg",ogg:"video/ogg",avi:"video/avi",mp4:"video/mp4",webm:"video/webm"},l={pause:!1,"play-button":!1,"mute-button":!1,autoplay:!0,muted:!0,loop:!0,mobile:!1,resolution:"16:9","inline-styles":!0,"fit-box":!1,offset:200,poster:null};this.__init__=function(){this.link&&this.ext&&(this.mime=r[this.ext.toLowerCase()],this.params=n(e,l,this.element,["data-ytbg-","data-vbg-"]),this.params.pause&&(this.params["play-button"]=this.params.pause),this.params.resolution_mod=o(this.params.resolution),this.state.playing=this.params.autoplay,this.state.muted=this.params.muted,this.buildHTML(),this.injectPlayer(),this.params["play-button"]&&this.generateActionButton({name:"play",className:"play-toggle",innerHtml:'',initialState:!1,stateClassName:"paused",condition_parameter:"autoplay",stateChildClassNames:["fa-pause-circle","fa-play-circle"],actions:["play","pause"]}),this.params["mute-button"]&&this.generateActionButton({name:"mute",className:"mute-toggle",innerHtml:'',initialState:!0,stateClassName:"muted",condition_parameter:"muted",stateChildClassNames:["fa-volume-up","fa-volume-mute"],actions:["unmute","mute"]}))},this.__init__()}function u(t,e){this.elements=t,"string"==typeof t&&(this.elements=document.querySelectorAll(t)),this.index={},this.re={},this.re.YOUTUBE=/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/i,this.re.VIMEO=/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|video\/|)(\d+)(?:[a-zA-Z0-9_\-]+)?/i,this.re.VIDEO=/\/[^\/]+\.(mp4|ogg|ogv|ogm|webm|avi)\s?$/i,this.__init__=function(){for(let t=0;t0&&this.player.seekTo(t,!0)},p.prototype.onVideoPlayerReady=function(t){this.params.autoplay&&(this.seekTo(this.params["start-at"]),this.player.playVideo())},p.prototype.onVideoStateChange=function(t){0===t.data&&this.params.loop&&(this.seekTo(this.params["start-at"]),this.player.playVideo()),-1===t.data&&this.params.autoplay&&(this.seekTo(this.params["start-at"]),this.player.playVideo(),this.element.dispatchEvent(new CustomEvent("video-background-play",{bubbles:!0,detail:this}))),1===t.data&&(this.iframe.style.opacity=1),this.params.onStatusChange(t)},p.prototype.injectPlayer=function(){this.iframe=document.createElement("iframe"),this.iframe.setAttribute("frameborder",0),this.iframe.setAttribute("allow","autoplay; mute");let t=`https://www.youtube.com/embed/${this.ytid}?&enablejsapi=1&disablekb=1&controls=0&rel=0&iv_load_policy=3&cc_load_policy=0&playsinline=1&showinfo=0&modestbranding=1&fs=0`;if(this.params.muted&&(t+="&mute=1"),this.params.autoplay&&(t+="&autoplay=1"),this.params.loop&&(t+="&loop=1"),this.params["end-at"]>0&&(t+=`&end=${this.params["end-at"]}`),this.iframe.src=t,this.uid&&(this.iframe.id=this.uid),this.params["inline-styles"]&&(this.iframe.style.top="50%",this.iframe.style.left="50%",this.iframe.style.transform="translateX(-50%) translateY(-50%)",this.iframe.style.position="absolute",this.iframe.style.opacity=0),this.element.appendChild(this.iframe),this.params["fit-box"])this.iframe.style.width="100%",this.iframe.style.height="100%";else{const t=this;function e(){const e=t.iframe.parentNode.offsetHeight+t.params.offset,s=t.iframe.parentNode.offsetWidth+t.params.offset,i=t.params.resolution_mod;i>s/e?(t.iframe.style.width=e*i+"px",t.iframe.style.height=e+"px"):(t.iframe.style.width=s+"px",t.iframe.style.height=s/i+"px")}if(window.hasOwnProperty("ResizeObserver")){new ResizeObserver((()=>{window.requestAnimationFrame(e)})).observe(this.element)}else window.addEventListener("resize",(()=>{window.requestAnimationFrame(e)}));e()}},p.prototype.buildHTML=function(){const t=this.element.parentNode;e(this.element,"youtube-background video-background");const s={height:"100%",width:"100%","z-index":"0",position:"absolute",overflow:"hidden",top:0,left:0,bottom:0,right:0};if(this.params["mute-button"]||(s["pointer-events"]="none"),(this.params["load-background"]||this.params.poster)&&(this.params["load-background"]&&(s["background-image"]="url(https://img.youtube.com/vi/"+this.ytid+"/maxresdefault.jpg)"),this.params.poster&&(s["background-image"]=this.params.poster),s["background-size"]="cover",s["background-repeat"]="no-repeat",s["background-position"]="center"),this.params["inline-styles"]){for(let t in s)this.element.style[t]=s[t];["absolute","fixed","relative","sticky"].indexOf(t.style.position)||(t.style.position="relative")}if(this.is_mobile&&!this.params.mobile)return this.element;if(this.params["play-button"]||this.params["mute-button"]){const e=document.createElement("div");e.className="video-background-controls",e.style.position="absolute",e.style.top="10px",e.style.right="10px",e.style["z-index"]=2,this.controls_element=e,t.appendChild(e)}return this.element},p.prototype.play=function(){if(this.buttons.hasOwnProperty("play")){const t=this.buttons.play;s(t.element,t.button_properties.stateClassName),e(t.element.firstChild,t.button_properties.stateChildClassNames[0]),s(t.element.firstChild,t.button_properties.stateChildClassNames[1])}this.player&&(this.params["start-at"]&&this.player.getCurrentTime()s/e?(t.iframe.style.width=e*i+"px",t.iframe.style.height=e+"px"):(t.iframe.style.width=s+"px",t.iframe.style.height=s/i+"px")};if(window.hasOwnProperty("ResizeObserver")){new ResizeObserver((()=>{window.requestAnimationFrame(e)})).observe(this.element)}else window.addEventListener("resize",(()=>{window.requestAnimationFrame(e)}));e()}},m.prototype.buildHTML=function(){const t=this.element.parentNode;e(this.element,"youtube-background");const s={height:"100%",width:"100%","z-index":"0",position:"absolute",overflow:"hidden",top:0,left:0,bottom:0,right:0};if((this.params["load-background"]||this.params.poster)&&(this.params.poster&&(s["background-image"]=this.params.poster),s["background-size"]="cover",s["background-repeat"]="no-repeat",s["background-position"]="center"),this.params["mute-button"]||(s["pointer-events"]="none"),this.params["load-background"]&&(s["background-size"]="cover",s["background-repeat"]="no-repeat",s["background-position"]="center"),this.params["inline-styles"]){for(let t in s)this.element.style[t]=s[t];["absolute","fixed","relative","sticky"].indexOf(t.style.position)||(t.style.position="relative")}return this.element},h.prototype.seekTo=function(t){this.player.hasOwnProperty("fastSeek")?this.player.fastSeek(t):this.player.currentTime=t},h.prototype.injectPlayer=function(){this.player=document.createElement("video"),this.player.muted=this.params.muted,this.player.autoplay=this.params.autoplay,this.player.loop=this.params.loop,this.player.playsinline=!0,this.player.setAttribute("id",this.uid),this.params["inline-styles"]&&(this.player.style.top="50%",this.player.style.left="50%",this.player.style.transform="translateX(-50%) translateY(-50%)",this.player.style.position="absolute",this.player.style.opacity=0,this.player.addEventListener("canplay",(t=>{t.target.style.opacity=1})));const t=this,e=document.createElement("source");if(e.setAttribute("src",this.link),e.setAttribute("type",this.mime),this.player.appendChild(e),this.element.appendChild(this.player),this.params["fit-box"])this.player.style.width="100%",this.player.style.height="100%";else{function e(){const e=t.player.parentNode.offsetHeight+t.params.offset,s=t.player.parentNode.offsetWidth+t.params.offset,i=t.params.resolution_mod;i>s/e?(t.player.style.width=e*i+"px",t.player.style.height=e+"px"):(t.player.style.width=s+"px",t.player.style.height=s/i+"px")}if(window.hasOwnProperty("ResizeObserver")){new ResizeObserver((()=>{window.requestAnimationFrame(e)})).observe(this.element)}else window.addEventListener("resize",(()=>{window.requestAnimationFrame(e)}));e()}},h.prototype.buildHTML=function(){const t=this.element.parentNode;e(this.element,"video-background");const s={height:"100%",width:"100%","z-index":"0",position:"absolute",overflow:"hidden",top:0,left:0,bottom:0,right:0};if(this.params["mute-button"]||(s["pointer-events"]="none"),(this.params["load-background"]||this.params.poster)&&(this.params.poster&&(s["background-image"]=`url('${this.params.poster}')`),s["background-size"]="cover",s["background-repeat"]="no-repeat",s["background-position"]="center"),this.params["inline-styles"]){for(let t in s)this.element.style[t]=s[t];["absolute","fixed","relative","sticky"].indexOf(t.style.position)||(t.style.position="relative")}if(this.is_mobile&&!this.params.mobile)return this.element;if(this.params["play-button"]||this.params["mute-button"]){const e=document.createElement("div");e.className="video-background-controls",e.style.position="absolute",e.style.top="10px",e.style.right="10px",e.style["z-index"]=2,this.controls_element=e,t.appendChild(e)}return this.element},h.prototype.play=function(){if(this.buttons.hasOwnProperty("play")){const t=this.buttons.play;s(t.element,t.button_properties.stateClassName),e(t.element.firstChild,t.button_properties.stateChildClassNames[0]),s(t.element.firstChild,t.button_properties.stateChildClassNames[1])}this.player&&(this.player.play(),this.element.dispatchEvent(new CustomEvent("video-background-play",{bubbles:!0,detail:this})))},h.prototype.pause=function(){if(this.buttons.hasOwnProperty("play")){const t=this.buttons.play;e(t.element,t.button_properties.stateClassName),s(t.element.firstChild,t.button_properties.stateChildClassNames[0]),e(t.element.firstChild,t.button_properties.stateChildClassNames[1])}this.player&&(this.player.pause(),this.element.dispatchEvent(new CustomEvent("video-background-pause",{bubbles:!0,detail:this})))},h.prototype.unmute=function(){if(this.buttons.hasOwnProperty("mute")){const t=this.buttons.mute;s(t.element,t.button_properties.stateClassName),e(t.element.firstChild,t.button_properties.stateChildClassNames[0]),s(t.element.firstChild,t.button_properties.stateChildClassNames[1])}this.player&&(this.player.muted=!1,this.element.dispatchEvent(new CustomEvent("video-background-unmute",{bubbles:!0,detail:this})))},h.prototype.mute=function(){if(this.buttons.hasOwnProperty("mute")){const t=this.buttons.mute;e(t.element,t.button_properties.stateClassName),s(t.element.firstChild,t.button_properties.stateChildClassNames[0]),e(t.element.firstChild,t.button_properties.stateChildClassNames[1])}this.player&&(this.player.muted=!0,this.element.dispatchEvent(new CustomEvent("video-background-mute",{bubbles:!0,detail:this})))},h.prototype.generateActionButton=function(i){const a=document.createElement("button");a.className=i.className,a.innerHTML=i.innerHtml,e(a.firstChild,i.stateChildClassNames[0]),this.params[i.condition_parameter]===i.initialState&&(e(a,i.stateClassName),s(a.firstChild,i.stateChildClassNames[0]),e(a.firstChild,i.stateChildClassNames[1]));const o=this;a.addEventListener("click",(function(e){t(this,i.stateClassName)?(o.state[i.name]=!1,o[i.actions[0]]()):(o.state[i.name]=!0,o[i.actions[1]]())})),this.buttons[i.name]={element:a,button_properties:i},this.controls_element.appendChild(a)},u.prototype.getVidID=function(t){if(null!=t)for(let e in this.re){const s=t.match(this.re[e]);if(s&&s.length)return this.re[e].lastIndex=0,{id:s[1],type:e,regex_pts:s,link:t}}return null},u.prototype.generateUID=function(t){let e=t+"-"+a(0,9999);for(;this.index.hasOwnProperty(e);)e=t+"-"+a(0,9999);return e},u.prototype.pauseVideos=function(){for(let t in this.index)this.index[t].pause()},u.prototype.playVideos=function(){for(let t in this.index)this.index[t].play()},u.prototype.initYTPlayers=function(t){const e=this;window.onYouTubeIframeAPIReady=function(){for(let t in e.index)e.index[t]instanceof p&&e.index[t].initYTPlayer();t&&setTimeout(t,100)},window.hasOwnProperty("YT")&&window.YT.loaded&&window.onYouTubeIframeAPIReady()},"function"==typeof jQuery&&((d=jQuery).fn.youtube_background=function(t){const e=d(this);return new u(this,t),e}),window.VideoBackgrounds=u}();