!function(t){"use strict";let e=document.createElement("template");e.innerHTML=`
Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.
`;class s extends HTMLElement{constructor(){super();let t=this.attachShadow({mode:"open"});this.shadowRoot.appendChild(e.content.cloneNode(!0)),this.rootEl=t.querySelector("#root"),this.playButtonEl=t.querySelector("#play-button"),this.cookieConsentMessageEl=t.querySelector("#cookieconsent-message"),this.cookieConsentButtonEl=t.querySelector("#cookieconsent-button"),this.playerEl=null,this._isRendered=!1,this._isCookieConsentAdded=!1,this._isPosterImageAdded=!1,this._isPlayerAdded=!1,this._forcePlayerElement=navigator.vendor.includes("Apple")||navigator.userAgent.includes("Mobi"),this._intersectionObserver=null,this._isInViewport=!1,this._hasPlayerControls=!0,this._hasAutoplayRequested=!1,this._hasMuted=!1,this._hasYTApiEnabled=!1,this._playerApi=null,this._playerType=ayg_config.player_type,this._playerColor=ayg_config.player_color,this._hasCookieConsent=1==parseInt(ayg_config.cookieconsent),this._cookieConsentMessage=ayg_config.cookieconsent_message||"",this._cookieConsentButtonLabel=ayg_config.cookieconsent_button_label||"",this._ajaxUrl=ayg_config.ajax_url,this._ajaxNonce=ayg_config.ajax_nonce}connectedCallback(){if(!this.src)return!1;let t=new URL(this.src),e=new URLSearchParams(t.search);this._hasPlayerControls=!(e.has("controls")&&(0==e.get("controls")||!1==e.get("controls"))),this._hasAutoplayRequested=e.has("autoplay")&&(1==e.get("autoplay")||!0==e.get("autoplay")),this._hasMuted=e.has("mute")&&(1==e.get("mute")||!0==e.get("mute")),this._hasYTApiEnabled=e.has("enablejsapi")&&(1==e.get("enablejsapi")||!0==e.get("enablejsapi")),"custom"==this._playerType&&(this._forcePlayerElement=!0),this.lazyLoad||(this._forcePlayerElement=!0),this.poster||(this._forcePlayerElement=!0),this._hasAutoplayRequested&&(this._forcePlayerElement=!0),this._render(),this.addEventListener("pointerover",()=>this._warmConnections(),{once:!0}),this.addEventListener("focusin",()=>this._warmConnections(),{once:!0}),this.addEventListener("click",()=>this._addPlayer(!0)),this.cookieConsentButtonEl.addEventListener("click",()=>this._onCookieConsent())}disconnectedCallback(){this.removeEventListener("pointerover",()=>this._warmConnections(),{once:!0}),this.removeEventListener("focusin",()=>this._warmConnections(),{once:!0}),this.removeEventListener("click",()=>this._addPlayer(!0)),this.cookieConsentButtonEl.removeEventListener("click",()=>this._onCookieConsent())}static get observedAttributes(){return["ratio"]}attributeChangedCallback(t,e,s){if(e==s)return!1;"ratio"===t&&("auto"==s?this.rootEl.style.paddingBottom=0:this.rootEl.style.paddingBottom=`${parseFloat(s)}%`)}get title(){return this.getAttribute("title")||""}set title(t){this.setAttribute("title",t)}get src(){let t=this.getAttribute("src")||"";return s.isValidUrl(t)?t:""}set src(t){s.isValidUrl(t)&&this.setAttribute("src",t)}get poster(){let t=this.getAttribute("poster")||"";return s.isValidUrl(t)?t:""}set poster(t){s.isValidUrl(t)&&this.setAttribute("poster",t)}get lazyLoad(){return this.hasAttribute("lazyload")}_render(){return!this._isRendered&&(this.lazyLoad&&!this._isInViewport?(this._initIntersectionObserver(),!1):this._hasCookieConsent?(this._addCookieConsent(),!1):void(this._isRendered=!0,this._forcePlayerElement?this._addPlayer():this._addPosterImage()))}_addCookieConsent(){if(this._isCookieConsentAdded)return!1;this._isCookieConsentAdded=!0,this._addPosterImage(),this._cookieConsentMessage&&(this.cookieConsentMessageEl.innerHTML=this._cookieConsentMessage),this._cookieConsentButtonLabel&&(this.cookieConsentButtonEl.innerHTML=this._cookieConsentButtonLabel),this._addClass("cookieconsent")}_onCookieConsent(){this._isRendered=!0;let t=document.querySelectorAll("ayg-player");for(let e=0;e{this._playerApi=t.detail.plyr.embed,this._plyr.autoplay=!0});let a=!1;this._plyr.on("playing",t=>{a||(a=!0,t.target.className+=" plyr--initialized",this._hasPlayerControls||(t.target.className+=" plyr--no-controls"));let e=document.querySelectorAll("ayg-player");for(let s=0;s{t.target.className+=" plyr--stopped"})}_initYTApi(t){if(!this._hasYTApiEnabled)return!1;this._loadYTApi().then(()=>{this._playerApi=new YT.Player(this.playerEl,{events:{onReady:e=>{t&&this.play()},onStateChange:t=>{if(0==t.data&&this._dispatchEvent("ended"),1==t.data){let e=document.querySelectorAll("ayg-player");for(let s=0;s{if(void 0===window.YT&&void 0===s.isApiLoaded){s.isApiLoaded=!0;var e=document.createElement("script");e.src="https://www.youtube.com/iframe_api";var i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(e,i)}if(void 0!==window.YT&&window.YT.loaded)t();else{let a=setInterval(function(){void 0!==window.YT&&window.YT.loaded&&(clearInterval(a),t())},10)}})}_initIntersectionObserver(){if(this._intersectionObserver)return!1;this._intersectionObserver=new IntersectionObserver((t,e)=>{t.forEach(t=>{t.isIntersecting?(this._isInViewport=!0,this._render(),this._isRendered&&e.unobserve(this)):this._isInViewport=!1})},{root:null,rootMargin:"0px",threshold:0}),this._intersectionObserver.observe(this)}_warmConnections(){if(s.isPreconnected)return!1;this.src.indexOf("www.youtube-nocookie.com")>-1?s.addPrefetch("preconnect","https://www.youtube-nocookie.com"):s.addPrefetch("preconnect","https://www.youtube.com"),s.addPrefetch("preconnect","https://www.google.com"),s.addPrefetch("preconnect","https://googleads.g.doubleclick.net"),s.addPrefetch("preconnect","https://static.doubleclick.net"),s.isPreconnected=!0}_hasClass(t){return this.rootEl.classList.contains(t)}_addClass(t){this.rootEl.classList.add(t)}_removeClass(t){this.rootEl.classList.remove(t)}_dispatchEvent(t){let e=new CustomEvent(t,{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(e)}async _setCookie(){try{let t=new FormData;t.append("action","ayg_set_cookie"),t.append("security",this._ajaxNonce),fetch(this._ajaxUrl,{method:"POST",body:t})}catch(e){}}static isValidUrl(t){if(""==t)return!1;try{return new URL(t),!0}catch(e){return!1}}static addPrefetch(t,e){let s=document.createElement("link");s.rel=t,s.href=e,document.head.append(s)}removeCookieConsent(){this._hasCookieConsent=!1,this._removeClass("cookieconsent"),this._render()}play(){if(!this._playerApi)return!1;this._playerApi.playVideo&&this._playerApi.playVideo()}pause(){if(!this._playerApi)return!1;this._playerApi.pauseVideo&&this._playerApi.pauseVideo()}change(t){let e=!0;if(t.hasOwnProperty("autoplay")&&(e=t.autoplay),this._playerApi)t.hasOwnProperty("id")&&(e?this._playerApi.loadVideoById&&this._playerApi.loadVideoById(t.id):this._playerApi.cueVideoById&&this._playerApi.cueVideoById(t.id));else{if(t.hasOwnProperty("id")){let s=new URL(this.src);s.pathname=`/embed/${t.id}`;let i=s.searchParams;i.set("autoplay",e?1:0),s.search=i.toString(),this.src=s.toString(),this._isPlayerAdded&&this.playerEl.setAttribute("src",this.src)}t.hasOwnProperty("poster")&&(this.poster=t.poster,this._isPosterImageAdded&&(this._isPlayerAdded?this.rootEl.style.backgroundImage="none":this.rootEl.style.backgroundImage=`url("${this.poster}")`)),this._isPlayerAdded||this._hasCookieConsent||this._addPlayer(!0)}t.hasOwnProperty("title")&&(this.title=t.title)}stop(){if(!this._playerApi)return!1;this._playerApi.stopVideo&&this._playerApi.stopVideo()}}class i extends HTMLElement{constructor(){super(),this._showMoreButtonLabel=ayg_config.i18n.show_more,this._showLessButtonLabel=ayg_config.i18n.show_less}connectedCallback(){t(this).on("click",".ayg-player-description-toggle-btn",t=>this._toggle(t))}disconnectedCallback(){t(this).off("click",".ayg-player-description-toggle-btn",t=>this._toggle(t))}_toggle(e){e.preventDefault();let s=t(this).find(".ayg-player-description-dots"),i=t(this).find(".ayg-player-description-more");s.is(":visible")?(e.currentTarget.innerHTML=this._showLessButtonLabel,s.hide(),i.fadeIn()):i.fadeOut(()=>{e.currentTarget.innerHTML=this._showMoreButtonLabel,s.show()})}}class a extends HTMLElement{constructor(){super(),this.$el=null,this.$root=null,this.$searchForm=null,this.$searchInput=null,this.$searchBtn=null,this.$resetBtn=null,this.$player=null,this.$videos=null,this.$pagination=null,this._formData={},this._ajaxUrl=ayg_config.ajax_url,this._ajaxNonce=ayg_config.ajax_nonce,this._searchTerm="",this._isLoading=!1}connectedCallback(){this.$el=t(this),this.$root=this.$el.closest(".ayg"),this.$searchForm=this.$el.find("form"),this.$searchInput=this.$el.find(".ayg-search-input"),this.$searchBtn=this.$el.find(".ayg-search-btn"),this.$resetBtn=this.$el.find(".ayg-reset-btn"),this.$player=this.$root.find(".ayg-theme > .ayg-player"),this.$videos=this.$root.find(".ayg-videos"),this.$pagination=this.$root.find(".ayg-pagination"),this._formData=this.$el.data("params"),this._formData.action="ayg_load_videos",this._formData.security=this._ajaxNonce,this._formData.searchTerm="",this.$searchForm.on("submit",t=>this._search(t)),this.$searchInput.on("blur",t=>this._search(t)),this.$searchBtn.on("click",t=>this._search(t)),this.$resetBtn.on("click",t=>this._reset(t))}disconnectedCallback(){this.$searchForm.off("submit",t=>this._search(t)),this.$searchInput.off("blur",t=>this._search(t)),this.$searchBtn.off("click",t=>this._search(t)),this.$resetBtn.off("click",t=>this._reset(t))}set loading(t){if(this._isLoading==t)return!1;this._isLoading=t,this.$searchBtn.hide(),this.$resetBtn.hide(),t?(this.$el.find(".ayg-status-message").remove(),this.$searchBtn.show(),this.$searchBtn.find("svg").hide(),this.$searchBtn.append('')):(this._searchTerm.length>0?this.$resetBtn.show():this.$searchBtn.show(),this.$searchBtn.find(".ayg-loading").remove(),this.$searchBtn.find("svg").show())}set message(t){this.$el.find(".ayg-status-message").remove(),t.data.message&&(t.success?this.$el.append('
'+t.data.message+"
"):this.$el.append('
'+t.data.message+"
"))}_search(t){if(t&&t.preventDefault(),this._searchTerm=this.$searchInput.val(),this._searchTerm==this._formData.searchTerm)return!1;this.loading=!0,this._formData.searchTerm=this._searchTerm,this._formData.pageToken=this._searchTerm.length>0?1:"",this._fetch(this._formData,t=>{t.success&&(this.$videos.html(t.data.html),this._updatePlayer(t),this._updatePagination(t),this.$el.trigger("videos.updated")),this._searchTerm.length>0&&(this.message=t),this.loading=!1})}_reset(t){this.$searchInput.val(""),this._search(t)}_updatePlayer(t){if(0==this.$player.length)return!1;let e=this.$videos.find(".ayg-video").eq(0),s=e.find(".ayg-thumbnail").data("id"),i=e.find(".ayg-thumbnail").data("title"),a=e.find(".ayg-thumbnail-description").html(),o=e.find(".ayg-thumbnail-image").attr("src"),n=this.$player.find("ayg-player").get(0),r=this.$root.find(".ayg-theme").data("params");n.change({id:s,title:i,poster:o,autoplay:!1}),1==r.player_title&&this.$player.find(".ayg-player-title").html(i),1==r.player_description&&this.$player.find(".ayg-player-description").html(a)}_updatePagination(t){if(0==this.$pagination.length)return!1;let e=parseInt(t.data.total_pages||1),s=this.$pagination.find(".ayg-pagination-prev-btn");s.length>0&&s.hide();let i=this.$pagination.find(".ayg-pagination-next-btn");i.length>0&&(1==e?i.hide():i.show());let a=this.$pagination.find(".ayg-pagination-current-page-number");a.length>0&&a.html(1);let o=this.$pagination.find(".ayg-pagination-total-pages");o.length>0&&o.html(e);let n=this.$pagination.get(0),r=n.formData;r.searchTerm=this._searchTerm,r.total_pages=e,r.next_page_token=t.data.next_page_token,n.update(r)}_fetch(e,s){t.post(this._ajaxUrl,e,s,"json")}}class o extends HTMLElement{constructor(){super(),this.$el=null,this.$videos=null,this.$nextButton=null,this.$previousButton=null,this._formData={},this._ajaxUrl=ayg_config.ajax_url,this._ajaxNonce=ayg_config.ajax_nonce,this._totalPages=1,this._paged=1,this._pageTokens=[""]}connectedCallback(){this.$el=t(this),this.$videos=this.$el.closest(".ayg").find(".ayg-videos"),this._formData=this.$el.data("params"),this._formData.action="ayg_load_videos",this._formData.security=this._ajaxNonce,this._totalPages=parseInt(this._formData.total_pages),this.$el.on("click",".ayg-pagination-next-btn",t=>this._next(t)),this.$el.on("click",".ayg-pagination-prev-btn",t=>this._previous(t))}disconnectedCallback(){this.$el.off("click",".ayg-pagination-next-btn",t=>this._next(t)),this.$el.off("click",".ayg-pagination-prev-btn",t=>this._previous(t))}get formData(){return this._formData}_next(e){this.$el.addClass("ayg-loading"),this.$nextButton=t(e.currentTarget);let s=this.$nextButton.data("type");this._formData.pageToken=this._formData.next_page_token,this._pageTokens[this._paged]=this._formData.pageToken,this._fetch(this._formData,t=>{if(t.success){switch(this._paged=Math.min(this._paged+1,this._totalPages),this._formData.next_page_token="",this._paged{t.success&&(this._formData.next_page_token="",t.data.next_page_token&&(this._formData.next_page_token=t.data.next_page_token),this.$videos.html(t.data.html),this.$el.find(".ayg-pagination-next-btn").show(),this.$el.find(".ayg-pagination-current-page-number").html(this._paged),1==this._paged&&this.$previousButton.hide(),this.$el.trigger("videos.updated")),this.$el.removeClass("ayg-loading")})}_fetch(e,s){t.post(this._ajaxUrl,e,s,"json")}update(t){this._formData=t,this._totalPages=parseInt(this._formData.total_pages),this._paged=1,this._pageTokens=[""]}}window.getAYGPlayerHtml=function t(e,s){var i="https://www.youtube.com";1==ayg_config.privacy_enhanced_mode&&(i="https://www.youtube-nocookie.com"),e.src=i+"/embed/"+e.id+"?enablejsapi=1&playsinline=1&rel=0",ayg_config.hasOwnProperty("origin")&&ayg_config.origin.length>0&&(e.src+="&origin="+ayg_config.origin),1==(s.hasOwnProperty("autoplay")?parseInt(s.autoplay):0)&&(e.src+="&autoplay=1"),1==(s.hasOwnProperty("muted")?parseInt(s.muted):0)&&(e.src+="&mute=1"),0==(s.hasOwnProperty("controls")?parseInt(s.controls):1)&&(e.src+="&controls=0"),1==(s.hasOwnProperty("modestbranding")?parseInt(s.modestbranding):0)&&(e.src+="&modestbranding=1"),1==(s.hasOwnProperty("cc_load_policy")?parseInt(s.cc_load_policy):0)&&(e.src+="&cc_load_policy=1"),0==(s.hasOwnProperty("iv_load_policy")?parseInt(s.iv_load_policy):0)&&(e.src+="&iv_load_policy=3"),s.hasOwnProperty("hl")&&s.hl.length>0&&(e.src+="&hl="+s.hl),s.hasOwnProperty("cc_lang_pref")&&s.cc_lang_pref.length>0&&(e.src+="&cc_lang_pref="+s.cc_lang_pref);var a='=0&&e){let r=t("#ayg-"+e);r.length>0&&(history.scrollRestoration?history.scrollRestoration="manual":window.onbeforeunload=function(){window.scrollTo(0,0)},t("html, body").animate({scrollTop:r.offset().top-n},500))}})}(jQuery);