!function(e){"use strict";let t=document.createElement("template");t.innerHTML=`
<style>
:host {
display: block;
width: 100%;
contain: content;
}
:host([hidden]){
display: none;
}
:host([ratio="auto"]){
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#root {
display: block;
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
cursor: pointer;
line-height: 1.5;
font-size: 16px;
}
:host([ratio="auto"]) #root {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
:host:not([ratio="auto"]) #root {
position: relative;
padding-bottom: 56.25%;
width: 100%;
height: 0;
}
iframe {
position: absolute;
inset: 0;
z-index: 1;
border: 0;
width: 100%;
height: 100%;
}
#play-button {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
z-index: 1;
border: 0;
background: center/72px 48px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 72 48'%3E%3Cpath fill='%23f00' fill-opacity='.9' d='M66.5 7.7c-.8-2.9-2.5-5.4-5.4-6.2C55.8.1 34 0 34 0S12.2.1 6.9 1.6c-3 .7-4.6 3.2-5.4 6.1a89.6 89.6 0 000 32.5c.8 3 2.5 5.5 5.4 6.3C12.2 47.9 34 48 34 48s21.8-.1 27.1-1.6c3-.7 4.6-3.2 5.4-6.1C68 35 68 24 68 24s0-11-1.5-16.3z'/%3E%3Cpath fill='%23fff' d='M45 24L27 14v20'/%3E%3C/svg%3E");
cursor: pointer;
width: 72px;
height: 48px;
filter: grayscale(1);
}
#root:hover > #play-button,
#play-button:focus {
filter: none;
}
#cookieconsent-modal {
box-sizing: border-box;
display: none;
position: absolute;
top: 50%;
left: 50%;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 0.75em;
transform: translate3d(-50%, -50%, 0);
z-index: 1;
border-radius: 3px;
background: rgba(0, 0, 0, 0.7);
padding: 1em;
width: 90%;
max-width: 640px;
color: #fff;
}
#cookieconsent-button {
display: block;
margin: 0;
border: 0;
border-radius: 3px;
background: #e70808;
cursor: pointer;
padding: 0.5em 1em;
color: #fff;
}
#cookieconsent-button:hover,
#cookieconsent-button:focus {
background: #fff;
color: #333;
}
#root.cookieconsent {
cursor: unset;
}
#root.cookieconsent > #play-button {
display: none;
}
#root.cookieconsent > #cookieconsent-modal {
display: flex;
}
@media only screen and (max-width: 480px){
#cookieconsent-modal {
width: 100%;
height: 100%;
font-size: 90%;
}}
@media only screen and (max-width: 320px){
#cookieconsent-modal {
gap: 0.5em;
}
#cookieconsent-button {
border-radius: 2px;
padding: 0.35em 0.75em;
}}
#root.initialized {
cursor: unset;
}
#root.initialized > #play-button,
#root.initialized > #cookieconsent-modal {
display: none;
}
#root .plyr {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#root .plyr__control--overlaid {
--plyr-control-spacing: 15px;
}
#root .plyr__control--overlaid svg {
--plyr-control-icon-size: 27px;
}
#root .plyr--youtube-no-logo iframe {
top: -50%;
height: 200%;
}
#root .plyr--initialized.plyr--no-controls .plyr__control--overlaid {
display: none;
}
#root .plyr--initialized iframe {
pointer-events: none;
}
</style>
<div id="root" part="root">
<button type="button" id="play-button" aria-label="Play Video"></button>
<div id="cookieconsent-modal">
<div id="cookieconsent-message">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.</div>
<button type="button" id="cookieconsent-button">I Agree</button>
</div>
<div id="player" class="plyr__video-embed"></div>
</div>
`;let i={};window.AYGLoadStyle=e=>e&&e.id?i[e.id]?i[e.id]:document.getElementById(e.id)?Promise.resolve():(i[e.id]=new Promise((t,i)=>{let s=document.createElement("link");s.id=e.id,s.rel="stylesheet",s.href=e.href,s.onload=t,s.onerror=i,document.head.appendChild(s)}),i[e.id]):Promise.resolve();let s={};window.AYGLoadScript=e=>e&&e.id?s[e.id]?s[e.id]:document.getElementById(e.id)?Promise.resolve():(s[e.id]=new Promise((t,i)=>{let s=document.createElement("script");s.id=e.id,s.src=e.src,s.defer=!0,s.onload=t,s.onerror=i,document.body.appendChild(s)}),s[e.id]):Promise.resolve(),window.getAYGPlayerHtml=(e,t)=>{let 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==(t.hasOwnProperty("autoplay")?parseInt(t.autoplay):0)&&(e.src+="&autoplay=1");1==(t.hasOwnProperty("muted")?parseInt(t.muted):0)&&(e.src+="&mute=1");0==(t.hasOwnProperty("controls")?parseInt(t.controls):1)&&(e.src+="&controls=0");1==(t.hasOwnProperty("modestbranding")?parseInt(t.modestbranding):0)&&(e.src+="&modestbranding=1");1==(t.hasOwnProperty("cc_load_policy")?parseInt(t.cc_load_policy):0)&&(e.src+="&cc_load_policy=1");0==(t.hasOwnProperty("iv_load_policy")?parseInt(t.iv_load_policy):0)&&(e.src+="&iv_load_policy=3"),t.hasOwnProperty("hl")&&t.hl.length>0&&(e.src+="&hl="+t.hl),t.hasOwnProperty("cc_lang_pref")&&t.cc_lang_pref.length>0&&(e.src+="&cc_lang_pref="+t.cc_lang_pref);let s='<ayg-player class="mfp-prevent-close"';return s+=' title="'+e.title+'"',s+=' src="'+e.src+'"',s+=' poster="'+e.poster+'"',s+=' ratio="'+e.ratio+'"',s+=">",s+="</ayg-player>"};class o extends HTMLElement{constructor(){super();let e=this.attachShadow({mode:"open"});this.shadowRoot.appendChild(t.content.cloneNode(!0)),this.rootEl=e.querySelector("#root"),this.playButtonEl=e.querySelector("#play-button"),this.cookieConsentMessageEl=e.querySelector("#cookieconsent-message"),this.cookieConsentButtonEl=e.querySelector("#cookieconsent-button"),this.playerEl=e.querySelector("#player"),this.iframeEl=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._hideYouTubeLogo=!1,this._playerApi=null,this._playerType=ayg_config.player_type,this._playerColor=ayg_config.player_color,this._pendingPlay=!1,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 e=new URL(this.src),t=new URLSearchParams(e.search);this._hasPlayerControls=!(t.has("controls")&&(0==t.get("controls")||!1==t.get("controls"))),this._hasAutoplayRequested=t.has("autoplay")&&(1==t.get("autoplay")||!0==t.get("autoplay")),this._hasMuted=t.has("mute")&&(1==t.get("mute")||!0==t.get("mute")),this._hasYTApiEnabled=t.has("enablejsapi")&&(1==t.get("enablejsapi")||!0==t.get("enablejsapi")),this._hideYouTubeLogo=t.has("modestbranding")&&(1==t.get("modestbranding")||!0==t.get("modestbranding")),"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(e,t,i){if(t==i)return!1;"ratio"===e&&("auto"==i?this.rootEl.style.paddingBottom=0:this.rootEl.style.paddingBottom=`${parseFloat(i)}%`)}get title(){return this.getAttribute("title")||""}set title(e){this.setAttribute("title",e)}get src(){let e=this.getAttribute("src")||"";return o.isValidUrl(e)?e:""}set src(e){o.isValidUrl(e)&&this.setAttribute("src",e)}get poster(){let e=this.getAttribute("poster")||"";return o.isValidUrl(e)?e:""}set poster(e){o.isValidUrl(e)&&this.setAttribute("poster",e)}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 e=document.querySelectorAll("ayg-player");for(let t=0;t<e.length;t++)e[t].removeCookieConsent();this._addPlayer(!0),this._setCookie()}_addPosterImage(){if(this._isPosterImageAdded)return!1;this._isPosterImageAdded=!0,this.poster&&(this.rootEl.style.backgroundImage=`url("${this.poster}")`)}_addPlayer(e=!1){if(this._isPlayerAdded||this._hasCookieConsent)return!1;if(this._isPlayerAdded=!0,this._addClass("initialized"),this.iframeEl=this._createIframeEmbed(e),this.playerEl.append(this.iframeEl),"custom"==this._playerType){this.playerEl.style="--plyr-color-main: "+this._playerColor;let t=this._loadStyle(ayg_config.plugin_url+"vendor/plyr/plyr.css?ver=3.7.8").then(()=>window.Plyr?Promise.resolve():window.AYGLoadScript({id:"automatic-youtube-gallery-plyr-js",src:ayg_config.plugin_url+"vendor/plyr/plyr.polyfilled.js?ver=3.7.8"}));t.then(()=>{this._initPlyrApi(e)}).catch(e=>{console.error("Failed to initialize Plyr:",e)})}else this.iframeEl.focus(),this._initYTApi(e)}_createIframeEmbed(e){let t=document.createElement("iframe");if(t.id="player",t.width=560,t.height=315,t.title=this.title,t.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",t.referrerPolicy="strict-origin-when-cross-origin",t.allowFullscreen=!0,e){let i=new URL(this.src),s=i.searchParams;s.set("autoplay",1),i.search=s.toString(),t.src=i.toString()}else t.src=this.src;return t.dataset.poster=this.poster,t}_initPlyrApi(e){let t={iconUrl:ayg_config.plugin_url+"vendor/plyr/plyr.svg",resetOnEnd:!0,fullscreen:{enabled:!0,iosNative:!0}};e&&(t.autoplay=!0),this._hasMuted&&(t.muted=!0);let i=["play-large"];if(this._hasPlayerControls){i=["play-large","play","current-time","progress","duration","mute","volume","fullscreen"];let s=/Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);s&&(i=["play-large","play","progress","current-time","mute","fullscreen"])}t.controls=i,this._plyr=new Plyr(this.playerEl,t),this._plyr.on("ready",e=>{this._playerApi=e.detail.plyr.embed,this._plyr.autoplay=!0,this._hideYouTubeLogo&&(e.target.className+=" plyr--youtube-no-logo")});let o=!1;this._plyr.on("playing",e=>{o||(o=!0,e.target.className+=" plyr--initialized",this._hasPlayerControls||(e.target.className+=" plyr--no-controls"));let t=document.querySelectorAll("ayg-player");for(let i=0;i<t.length;i++)t[i]!=this&&t[i].pause()}),this._plyr.on("ended",e=>{e.target.className+=" plyr--stopped"})}_initYTApi(e){if(!this._hasYTApiEnabled)return!1;this._loadYTApi().then(()=>{this._playerApi=new YT.Player(this.iframeEl,{events:{onReady:t=>{e&&this._pendingPlay&&(t.target.playVideo(),this._pendingPlay=!1)},onStateChange:e=>{if(0==e.data&&(document.fullscreenElement?(document.exitFullscreen().catch(()=>{}),setTimeout(()=>{this._dispatchEvent("ended")},500)):this._dispatchEvent("ended")),1==e.data){let t=document.querySelectorAll("ayg-player");for(let i=0;i<t.length;i++)t[i]!=this&&t[i].pause()}}}})})}_loadYTApi(){return new Promise(e=>{if(void 0===window.YT&&void 0===o.isApiLoaded){o.isApiLoaded=!0;let t=document.createElement("script");t.src="https://www.youtube.com/iframe_api";let i=document.getElementsByTagName("script")[0];i.parentNode.insertBefore(t,i)}if(void 0!==window.YT&&window.YT.loaded)e();else{let s=setInterval(function(){void 0!==window.YT&&window.YT.loaded&&(clearInterval(s),e())},10)}})}_initIntersectionObserver(){if(this._intersectionObserver)return!1;this._intersectionObserver=new IntersectionObserver((e,t)=>{e.forEach(e=>{e.isIntersecting?(this._isInViewport=!0,this._render(),this._isRendered&&t.unobserve(this)):this._isInViewport=!1})},{root:null,rootMargin:"0px",threshold:0}),this._intersectionObserver.observe(this)}_warmConnections(){if(o.isPreconnected)return!1;this.src.indexOf("www.youtube-nocookie.com")>-1?o.addPrefetch("preconnect","https://www.youtube-nocookie.com"):o.addPrefetch("preconnect","https://www.youtube.com"),o.addPrefetch("preconnect","https://www.google.com"),o.addPrefetch("preconnect","https://googleads.g.doubleclick.net"),o.addPrefetch("preconnect","https://static.doubleclick.net"),o.isPreconnected=!0}_hasClass(e){return this.rootEl.classList.contains(e)}_addClass(e){this.rootEl.classList.add(e)}_removeClass(e){this.rootEl.classList.remove(e)}_dispatchEvent(e){let t=new CustomEvent(e,{detail:{},bubbles:!0,cancelable:!0});this.dispatchEvent(t)}async _loadStyle(e){if(!o.plyrCssText){let t=await fetch(e);if(!t.ok)throw Error(t.status);o.plyrCssText=await t.text()}if("adoptedStyleSheets"in Document.prototype&&"replaceSync"in CSSStyleSheet.prototype){let i=new CSSStyleSheet;i.replaceSync(o.plyrCssText),this.shadowRoot.adoptedStyleSheets=[i]}else{let s=document.createElement("style");s.textContent=o.plyrCssText,this.shadowRoot.appendChild(s)}}async _setCookie(){try{let e=new FormData;e.append("action","ayg_set_cookie"),e.append("security",this._ajaxNonce),fetch(this._ajaxUrl,{method:"POST",body:e})}catch(t){}}static isValidUrl(e){if(""==e)return!1;try{return new URL(e),!0}catch(t){return!1}}static addPrefetch(e,t){let i=document.createElement("link");i.rel=e,i.href=t,document.head.append(i)}removeCookieConsent(){this._hasCookieConsent=!1,this._removeClass("cookieconsent"),this._render()}play(e=null){if(e&&"object"==typeof e){this.change(e);return}this._playerApi&&this._playerApi.playVideo?this._playerApi.playVideo():this._pendingPlay=!0}pause(){this._playerApi&&this._playerApi.pauseVideo&&this._playerApi.pauseVideo()}change(e){let t=!0;if(e.hasOwnProperty("autoplay")&&(t=e.autoplay),this._playerApi)e.hasOwnProperty("poster")&&this._plyr&&(this._plyr.poster="",setTimeout(()=>{this._plyr.poster=e.poster},100)),e.hasOwnProperty("id")&&(t?this._playerApi.loadVideoById&&this._playerApi.loadVideoById(e.id):this._playerApi.cueVideoById&&this._playerApi.cueVideoById(e.id));else{if(e.hasOwnProperty("id")){let i=new URL(this.src);i.pathname=`/embed/${e.id}`;let s=i.searchParams;s.set("autoplay",t?1:0),i.search=s.toString(),this.src=i.toString(),this._isPlayerAdded&&this.iframeEl.setAttribute("src",this.src)}e.hasOwnProperty("poster")&&(this.poster=e.poster,this._isPosterImageAdded&&(this._isPlayerAdded?this.rootEl.style.backgroundImage="none":this.rootEl.style.backgroundImage=`url("${e.poster}")`)),this._isPlayerAdded||this._hasCookieConsent||this._addPlayer(!0)}e.hasOwnProperty("title")&&(this.title=e.title)}stop(){this._playerApi&&this._playerApi.stopVideo&&this._playerApi.stopVideo()}}o.plyrCssText=null;class a extends HTMLElement{constructor(){super(),this._isRendered=!1,this._showMoreButtonLabel=ayg_config.i18n.show_more,this._showLessButtonLabel=ayg_config.i18n.show_less}connectedCallback(){if(this._isRendered)return!1;this._isRendered=!0,e(this).on("click",".ayg-player-description-toggle-btn",e=>this._toggle(e))}disconnectedCallback(){if(!this._isRendered)return!1;e(this).off("click",".ayg-player-description-toggle-btn",e=>this._toggle(e))}_toggle(t){t.preventDefault();let i=e(this).find(".ayg-player-description-dots"),s=e(this).find(".ayg-player-description-more");i.is(":visible")?(t.currentTarget.innerHTML=this._showLessButtonLabel,i.hide(),s.fadeIn()):s.fadeOut(()=>{t.currentTarget.innerHTML=this._showMoreButtonLabel,i.show()})}}class r 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._isRendered=!1,this._formData={},this._ajaxUrl=ayg_config.ajax_url,this._ajaxNonce=ayg_config.ajax_nonce,this._searchTerm="",this._isLoading=!1}connectedCallback(){if(this._isRendered)return!1;this._isRendered=!0,this.$el=e(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",e=>this._search(e)),this.$searchInput.on("blur",e=>this._search(e)),this.$searchBtn.on("click",e=>this._search(e)),this.$resetBtn.on("click",e=>this._reset(e))}disconnectedCallback(){if(!this._isRendered)return!1;this.$searchForm.off("submit",e=>this._search(e)),this.$searchInput.off("blur",e=>this._search(e)),this.$searchBtn.off("click",e=>this._search(e)),this.$resetBtn.off("click",e=>this._reset(e))}set loading(e){if(this._isLoading==e)return!1;this._isLoading=e,this.$searchBtn.hide(),this.$resetBtn.hide(),e?(this.$el.find(".ayg-status-message").remove(),this.$searchBtn.show(),this.$searchBtn.find("svg").hide(),this.$searchBtn.append('<span class="ayg-loading"></span>')):(this._searchTerm.length>0?this.$resetBtn.show():this.$searchBtn.show(),this.$searchBtn.find(".ayg-loading").remove(),this.$searchBtn.find("svg").show())}set message(e){this.$el.find(".ayg-status-message").remove(),e.data.message&&(e.success?this.$el.append('<div class="ayg-status-message"><svg xmlns="http://www.w3.org/2000/svg" fill="none" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75 11.25 15 15 9.75M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /></svg>'+e.data.message+"</div>"):this.$el.append('<div class="ayg-status-message ayg-error"><svg xmlns="http://www.w3.org/2000/svg" fill="none" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m9-.75a9 9 0 1 1-18 0 9 9 0 0 1 18 0Zm-9 3.75h.008v.008H12v-.008Z" /></svg>'+e.data.message+"</div>"))}_search(e){if(e&&e.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,e=>{e.success&&(this.$videos.html(e.data.html),this._updatePlayer(e),this._updatePagination(e),this.$el.trigger("videos.updated")),this._searchTerm.length>0&&(this.message=e),this.loading=!1})}_reset(e){this.$searchInput.val(""),this._search(e)}_updatePlayer(e){if(0==this.$player.length)return!1;let t=this.$videos.find(".ayg-video").eq(0),i=t.find(".ayg-thumbnail").data("id"),s=t.find(".ayg-thumbnail").data("title"),o=t.find(".ayg-thumbnail-description").html(),a=t.find(".ayg-thumbnail-image").attr("src"),r=this.$player.find("ayg-player").get(0),n=this.$root.find(".ayg-theme").data("params");r.change({id:i,title:s,poster:a,autoplay:!1}),1==n.player_title&&this.$player.find(".ayg-player-title").html(s),1==n.player_description&&this.$player.find(".ayg-player-description").html(o)}_updatePagination(e){if(0==this.$pagination.length)return!1;let t=parseInt(e.data.total_pages||1),i=this.$pagination.find(".ayg-pagination-prev-btn");i.length>0&&i.hide();let s=this.$pagination.find(".ayg-pagination-next-btn");s.length>0&&(1==t?s.hide():s.show());let o=this.$pagination.find(".ayg-pagination-current-page-number");o.length>0&&o.html(1);let a=this.$pagination.find(".ayg-pagination-total-pages");a.length>0&&a.html(t);let r=this.$pagination.get(0),n=r.formData;n.searchTerm=this._searchTerm,n.total_pages=t,n.next_page_token=e.data.next_page_token,r.update(n)}_fetch(t,i){e.post(this._ajaxUrl,t,i,"json")}}class n extends HTMLElement{constructor(){super(),this.$el=null,this.$videos=null,this.$nextButton=null,this.$previousButton=null,this._isRendered=!1,this._formData={},this._ajaxUrl=ayg_config.ajax_url,this._ajaxNonce=ayg_config.ajax_nonce,this._totalPages=1,this._paged=1,this._pageTokens=[""]}connectedCallback(){if(this._isRendered)return!1;this._isRendered=!0,this.$el=e(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",e=>this._next(e)),this.$el.on("click",".ayg-pagination-prev-btn",e=>this._previous(e))}disconnectedCallback(){if(!this._isRendered)return!1;this.$el.off("click",".ayg-pagination-next-btn",e=>this._next(e)),this.$el.off("click",".ayg-pagination-prev-btn",e=>this._previous(e))}get formData(){return this._formData}_next(t){this.$el.addClass("ayg-loading"),this.$nextButton=e(t.currentTarget);let i=this.$nextButton.data("type");this._formData.pageToken=this._formData.next_page_token,this._pageTokens[this._paged]=this._formData.pageToken,this._fetch(this._formData,e=>{if(e.success){switch(this._paged=Math.min(this._paged+1,this._totalPages),this._formData.next_page_token="",this._paged<this._totalPages&&e.data.next_page_token&&(this._formData.next_page_token=e.data.next_page_token),i){case"more":this.$videos.append(e.data.html);break;case"next":this.$el.find(".ayg-pagination-prev-btn").show(),this.$el.find(".ayg-pagination-current-page-number").html(this._paged),this.$videos.html(e.data.html)}""==this._formData.next_page_token&&this.$nextButton.hide(),this.$el.trigger("videos.updated")}this.$el.removeClass("ayg-loading")})}_previous(t){this.$el.addClass("ayg-loading"),this.$previousButton=e(t.currentTarget),this._paged=Math.max(this._paged-1,1),this._formData.pageToken=this._pageTokens[this._paged-1],this._fetch(this._formData,e=>{e.success&&(this._formData.next_page_token="",e.data.next_page_token&&(this._formData.next_page_token=e.data.next_page_token),this.$videos.html(e.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(t,i){e.post(this._ajaxUrl,t,i,"json")}update(e){this._formData=e,this._totalPages=parseInt(this._formData.total_pages),this._paged=1,this._pageTokens=[""]}}e(function(){customElements.get("ayg-player")||customElements.define("ayg-player",o),customElements.get("ayg-description")||customElements.define("ayg-description",a),customElements.get("ayg-search-form")||customElements.define("ayg-search-form",r),customElements.get("ayg-pagination")||customElements.define("ayg-pagination",n);let t=ayg_config.current_gallery_id,i=parseInt(ayg_config.top_offset);if(i>=0&&t){let s=e("#ayg-"+t);s.length>0&&(history.scrollRestoration?history.scrollRestoration="manual":window.onbeforeunload=function(){window.scrollTo(0,0)},e("html, body").animate({scrollTop:s.offset().top-i},500))}let l=ayg_config.plugin_url,h=ayg_config.plugin_version,d=[{selector:"ayg-theme-classic",script:{id:"automatic-youtube-gallery-theme-classic-js",src:l+"public/assets/js/theme-classic.min.js?ver="+h}},{selector:"ayg-theme-inline",script:{id:"automatic-youtube-gallery-theme-inline-js",src:l+"premium/public/assets/js/theme-inline.min.js?ver="+h}},{selector:"ayg-theme-playlist",script:{id:"automatic-youtube-gallery-theme-playlist-js",src:l+"premium/public/assets/js/theme-playlist.min.js?ver="+h}},{selector:"ayg-theme-popup, .ayg-theme-single-popup",script:{id:"automatic-youtube-gallery-theme-popup-js",src:l+"premium/public/assets/js/theme-popup.min.js?ver="+h}},{selector:"ayg-theme-slider, ayg-theme-slider-popup, ayg-theme-slider-inline",script:{id:"automatic-youtube-gallery-theme-slider-js",src:l+"premium/public/assets/js/theme-slider.min.js?ver="+h}}],c=(e=document)=>{if(e&&(1===e.nodeType||e===document))for(let t of d)(e.matches?.(t.selector)||e.querySelector(t.selector))&&(t.style&&window.AYGLoadStyle(t.style),t.script&&window.AYGLoadScript(t.script))};c(document);let p=new MutationObserver(e=>{for(let t of e)for(let i of t.addedNodes)c(i)});p.observe(document.body,{childList:!0,subtree:!0})})}(jQuery);
!function(e){"use strict";class i extends HTMLElement{constructor(){super(),this.$el=null,this.$selectedVideo=null,this.$searchForm=null,this.$pagination=null,this.$nextButton=null,this.player=null,this._params={},this._selectedVideoId="",this._paginationType="none",this._pageTopOffset=parseInt(ayg_config.top_offset)}connectedCallback(){this.$el=e(this),this.$selectedVideo=this.$el.find(".ayg-video").eq(0),this.$searchForm=this.$el.find("ayg-search-form"),this.$pagination=this.$el.find(".ayg-pagination"),this.player=this.$el.find("ayg-player").get(0),this._params=this.$el.data("params"),this._selectedVideoId=this.$selectedVideo.find(".ayg-thumbnail").data("id"),this.$pagination.length>0&&(this.$nextButton=this.$pagination.find(".ayg-pagination-next-btn"),this._paginationType=this.$nextButton.data("type")),this.$el.on("click",".ayg-video",e=>this._onThumbnailClicked(e)),this.$searchForm.on("videos.updated",e=>this._onSearch(e)),this.$pagination.on("videos.updated",e=>this._onVideosUpdated(e)),this.player.addEventListener("ended",()=>this._onVideoEnded())}disconnectedCallback(){this.$el.off("click",".ayg-video",e=>this._onThumbnailClicked(e)),this.$searchForm.off("videos.updated",e=>this._onSearch(e)),this.$pagination.off("videos.updated",e=>this._onVideosUpdated(e)),this.player.removeEventListener("ended",()=>this._onVideoEnded())}_onThumbnailClicked(i){if(this.$selectedVideo=e(i.currentTarget),this.$selectedVideo.hasClass("ayg-active"))return!1;this.$el.find(".ayg-active").removeClass("ayg-active"),this.$selectedVideo.addClass("ayg-active"),this._selectedVideoId=this.$selectedVideo.find(".ayg-thumbnail").data("id");let t=this.$selectedVideo.find(".ayg-thumbnail").data("title"),s=this.$selectedVideo.find(".ayg-thumbnail-description").html(),a=this.$selectedVideo.find(".ayg-thumbnail-image").attr("src");this.player.play({id:this._selectedVideoId,title:t,poster:a}),1==this._params.player_title&&this.$el.find(".ayg-player-title").html(t),1==this._params.player_description&&this.$el.find(".ayg-player-description").html(s),this._pageTopOffset>=0&&e("html, body").animate({scrollTop:this.$el.offset().top-this._pageTopOffset},500);let d=this.$selectedVideo.find(".ayg-thumbnail").data("url");""!=d&&window.history.replaceState(null,null,d),1==this._params.autoadvance&&"more"==this._paginationType&&this.$selectedVideo.is(":last-child")&&this.$nextButton.is(":visible")&&this.$nextButton.trigger("click")}_onSearch(e){this.$selectedVideo=this.$el.find(".ayg-video").eq(0).addClass("ayg-active")}_onVideosUpdated(e){if(this.$el.find(".ayg-active").length>0)return!1;this.$el.find(".ayg-video-"+this._selectedVideoId).length>0&&(this.$selectedVideo=this.$el.find(".ayg-video-"+this._selectedVideoId).addClass("ayg-active"))}_onVideoEnded(){if(1==this._params.autoadvance){if(this.player.stop(),this.$selectedVideo.is(":visible")){if(this.$selectedVideo.is(":last-child")){if("more"==this._paginationType||"none"==this._paginationType)1==this._params.loop&&this.$el.find(".ayg-video").eq(0).trigger("click");else if(this.$nextButton.is(":visible")){this.$nextButton.trigger("click");let e=setInterval(()=>{0==this.$el.find(".ayg-pagination.ayg-loading").length&&(clearInterval(e),this.$el.find(".ayg-video").eq(0).trigger("click"))},1e3)}}else this.$selectedVideo.next(".ayg-video").trigger("click")}else this.$el.find(".ayg-video").eq(0).trigger("click")}else 1==this._params.loop?this.player.play():this.player.stop()}}e(function(){customElements.get("ayg-theme-classic")||customElements.define("ayg-theme-classic",i)})}(jQuery);