(function ($){
("use strict");
$(document).ready(function (){
initYouTubeGallery();
});
function initYouTubeGallery(){
function parseMaybeJSON(val, fallback){
if(typeof val==="string"){
try {
return JSON.parse(val);
} catch (e){
return fallback;
}}
return typeof val==="object"&&val!==null ? val:fallback;
}
function truncateText(text, length){
if(!text) return "";
const width=$(window).width();
let maxLength;
if(width < 600){
maxLength=length.sm||length.lg;
}else if(width < 900){
maxLength=length.md||length.lg;
}else{
maxLength=length.lg;
}
return text.length > maxLength
? text.substring(0, maxLength) + "..."
: text;
}
function sortVideos(videos, sortBy){
const sorted=[...videos];
switch (sortBy){
case "title":
return sorted.sort((a, b)=>
a.title.localeCompare(b.title, undefined, {
sensitivity: "base",
})
);
case "latest":
return sorted.sort((a, b)=>
new Date(b.publishedAt).getTime() -
new Date(a.publishedAt).getTime()
);
case "date":
return sorted.sort((a, b)=>
new Date(a.publishedAt).getTime() -
new Date(b.publishedAt).getTime()
);
case "popular":
return sorted.sort((a, b)=> (b.viewCount||0) - (a.viewCount||0));
default:
return videos;
}}
function getPlaylistId(input){
if(!input) return "";
try {
const url=new URL(input);
if(url.hostname==="www.youtube.com"){
if(url.pathname.startsWith("/channel/")){
return url.pathname.split("/channel/")[1];
}else if(url.pathname.startsWith("/@")){
return url.pathname.substring(2);
}else if(url.searchParams.get("list")){
return url.searchParams.get("list");
}}
return input;
} catch (e){
return input;
}}
function resolveHandleToChannelId(handle, apiKey, callback){
$.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(
handle
)}&type=channel&key=${apiKey}`
)
.done(function (data){
if(data.items&&data.items.length > 0){
callback(data.items[0].snippet.channelId);
}else{
callback(null);
}})
.fail(function (){
callback(null);
});
}
function generatePlayerIframe(videoId, config){
const params=[
`autoplay=${config.autoplay ? "1":"0"}`,
`loop=${config.loop ? "1":"0"}`,
`mute=${config.mute ? "1":"0"}`,
`controls=${config.showPlayerControl ? "1":"0"}`,
`modestbranding=${config.hideYoutubeLogo ? "1":"0"}`,
config.loop ? `playlist=${videoId}`:null,
]
.filter(Boolean)
.join("&");
return `
<div class="ultp-ytg-video-wrapper">
<iframe
src="https://www.youtube.com/embed/${videoId}?${params}"
title="YouTube Video"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
</div>
`;
}
function getYoutubeTextContent(
enableTitle,
title,
titleLength,
enableDesc,
description,
descriptionLength,
videoId
){
let html='<div class="ultp-ytg-content">';
if(enableTitle){
html +=`<div class="ultp-ytg-title"><a href="https://www.youtube.com/watch?v=${videoId}" target="_blank" rel="noopener noreferrer">${truncateText(
title,
titleLength
)}</a></div>`;
}
if(enableDesc){
html +=`<div class="ultp-ytg-description">${truncateText(
description,
descriptionLength
)}</div>`;
}
html +="</div>";
return html;
}
$(".wp-block-ultimate-post-youtube-gallery").each(function (){
const $block=$(this);
const $wrapper=$block.find(".ultp-block-wrapper");
let $container=$block.find(".ultp-ytg-view-grid, .ultp-ytg-container");
const $loadMoreBtn=$block.find(".ultp-ytg-loadmore-btn");
const config={
playlistIdOrUrl: $block.data("playlist")||"",
apiKey: $block.data("api-key")||"",
cacheDuration: parseInt($block.data("cache-duration"))||0,
sortBy: $block.data("sort-by")||"date",
galleryLayout: $block.data("gallery-layout")||"grid",
videosPerPage: parseMaybeJSON($block.data("videos-per-page"), {
lg: 9,
md: 6,
sm: 3,
}),
showVideoTitle: $block.data("show-video-title")=="1",
videoTitleLength: parseMaybeJSON($block.data("video-title-length"), {
lg: 50,
md: 50,
sm: 50,
}),
loadMoreEnable: $block.data("load-more-enable")=="1",
moreButtonLabel: $block.data("more-button-label")||"More Videos",
autoplay: $block.data("autoplay")=="1",
loop: $block.data("loop")=="1",
mute: $block.data("mute")=="1",
showPlayerControl: $block.data("show-player-control")=="1",
hideYoutubeLogo: $block.data("hide-youtube-logo")=="1",
showDescription: $block.data("show-description")=="1",
videoDescriptionLength: parseMaybeJSON(
$block.data("video-description-length"),
{
lg: 100,
md: 100,
sm: 100,
}
),
imageHeightRatio: $block.data("image-height-ratio")||"16-9",
galleryColumn: parseMaybeJSON($block.data("gallery-column"), {
lg: 3,
md: 2,
sm: 1,
}),
displayType: $block.data("display-type")||"grid",
enableListView: $block.data("enable-list-view")=="1",
enableIconAnimation: $block.data("enable-icon-animation")=="1",
defaultYoutubeIcon: $block.data("enable-youtube-icon")=="1",
imgHeight: $block.data("img-height"),
};
let playlistId=getPlaylistId(config.playlistIdOrUrl);
if(playlistId.startsWith("@")){
const handle=playlistId.substring(1);
resolveHandleToChannelId(handle, config.apiKey, function (channelId){
if(channelId){
playlistId=channelId;
proceedWithPlaylist(playlistId);
}else{
$wrapper.html('<p style="color:#888">Invalid handle or API key.</p>'
);
}});
}else{
proceedWithPlaylist(playlistId);
}
function proceedWithPlaylist(playlistId){
if(playlistId.startsWith("UC")){
playlistId="UU" + playlistId.substring(2);
}
if(!playlistId||!config.apiKey){
$wrapper.html('<p style="color:#888">Please provide both YouTube playlist ID/URL and API key.</p>'
);
return;
}
let allVideos=[];
let shownCount=config.videosPerPage.lg||9;
let activeVideo=null;
let playingId=null;
function updateResponsiveCounts(){
const width=$(window).width();
if(width < 600){
shownCount=Math.max(shownCount, config.videosPerPage.sm||3);
}else if(width < 900){
shownCount=Math.max(shownCount, config.videosPerPage.md||6);
}else{
shownCount=Math.max(shownCount, config.videosPerPage.lg||9);
}}
function renderPlaylistLayout(videos){
if(!videos.length){
$container.html("<p>No videos found in this playlist.</p>");
return;
}
if(!activeVideo){
activeVideo=videos[0];
}
let html='<div class="ultp-ytg-main">';
const playerWrapper=`
<div class="ultp-ytg-video-wrapper">
<iframe
src="https://www.youtube.com/embed/${activeVideo.videoId}?${[
`autoplay=${config.autoplay ? "1":"0"}`,
`loop=${config.loop ? "1":"0"}`,
`mute=${config.mute ? "1":"0"}`,
`controls=${config.showPlayerControl ? "1":"0"}`,
`modestbranding=${config.hideYoutubeLogo ? "1":"0"}`,
config.loop ? `playlist=${activeVideo.videoId}`:null,
]
.filter(Boolean)
.join("&")}"
title="YouTube Video"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
></iframe>
${getYoutubeTextContent(
config.showVideoTitle,
activeVideo.title,
config.videoTitleLength,
config.showDescription,
activeVideo.description,
config.videoDescriptionLength,
activeVideo.videoId
)}
</div>
`;
html +=playerWrapper;
html +="</div>";
html +='<div class="ultp-ytg-playlist-sidebar">';
html +='<div class="ultp-ytg-playlist-items">';
videos.forEach(function (video){
const isActive=video.videoId===activeVideo.videoId;
html +=`
<div class="ultp-ytg-playlist-item ${
isActive ? "active":""
}" data-video-id="${video.videoId}">
<img src="${video.thumbnail}" alt="${video.title}" loading="lazy" />
<div class="ultp-ytg-playlist-item-content">
<div class="ultp-ytg-playlist-item-title">
${truncateText(video.title, config.videoTitleLength)}
</div>
</div>
</div>
`;
});
html +="</div></div>";
$container.html(html);
}
function renderGridLayout(videos, count){
if(!videos.length){
$container.html("<p>No videos found in this playlist.</p>");
return;
}
const displayedVideos=videos.slice(0, count);
let html="";
displayedVideos.forEach(function (video){
const isPlaying=playingId===video.videoId;
html +=`<div class="ultp-ytg-item${isPlaying ? " active":""}">`;
html +=`<div class="ultp-ytg-video">`;
if(isPlaying){
html +=generatePlayerIframe(video.videoId, config);
}else{
const getSvgIcon=$(".ultp-ytg-play__icon").html();
html +=`
<img src="${video.thumbnail}" alt="${
video.title
}" loading="lazy" data-video-id="${
video.videoId
}" style="cursor:pointer;" />
<div class="ultp-ytg-play__icon${
config.enableIconAnimation ? " ytg-icon-animation":""
}">
${getSvgIcon}
</div>
`;
}
html +=`</div>`;
html +=`<div class="ultp-ytg-inside">`;
html +=getYoutubeTextContent(
config.showVideoTitle,
video.title,
config.videoTitleLength,
config.showDescription,
video.description,
config.videoDescriptionLength,
video.videoId
);
html +=`</div></div>`;
});
$container.html(html);
if(config.loadMoreEnable&&count < videos.length){
$loadMoreBtn.show();
}else{
$loadMoreBtn.hide();
}}
function renderVideos(videos, count){
if(config.galleryLayout==="playlist"){
renderPlaylistLayout(videos);
}else{
renderGridLayout(videos, count);
}}
const cacheKey=`ultp_youtube_gallery_${playlistId}_${config.apiKey}_${config.sortBy}_${config.imgHeight}`;
const duration=config.cacheDuration;
let cached=null;
try {
cached=JSON.parse(localStorage.getItem(cacheKey));
} catch (e){
cached=null;
}
const now=Date.now();
if(cached &&
cached.data &&
cached.timestamp &&
duration > 0 &&
now - cached.timestamp < duration * 1000
){
allVideos=sortVideos(cached.data, config.sortBy);
renderVideos(allVideos, shownCount);
}else{
if(config.galleryLayout!=="playlist"){
$container.html(`
<div class="ultp-ytg-loading gallery-postx gallery-active">
<div class="skeleton-box"></div>
<div class="skeleton-box"></div>
<div class="skeleton-box"></div>
<div class="skeleton-box"></div>
<div class="skeleton-box"></div>
<div class="skeleton-box"></div>
</div>
`);
}else{
$container.html(`
<div class="ultp-ytg-loading ultp-ytg-playlist-loading">
<div class="ytg-loader"></div>
</div>`);
}
$.get("https://www.googleapis.com/youtube/v3/playlistItems", {
part: "snippet",
maxResults: 50,
playlistId: playlistId,
key: config.apiKey,
})
.done(function (data){
setTimeout(function (){
$container.empty();
if(data.error){
$container.html(`<div class="ultp-ytg-error">${
data.error.message||"Failed to fetch playlist."
}</div>`
);
return;
}
const videos=(data.items||[])
.filter(function (item){
return (
item.snippet.title!=="Private video" &&
item.snippet.title!=="Deleted video"
);
})
.map(function (item){
return {
videoId: item.snippet.resourceId.videoId,
title: item.snippet.title,
thumbnail:
(item.snippet.thumbnails &&
item.snippet.thumbnails[config.imgHeight] &&
item.snippet.thumbnails[config.imgHeight].url) ||
item.snippet.thumbnails[config.imgHeight].url ||
item.snippet.thumbnails?.medium?.url ||
"",
publishedAt: item.snippet.publishedAt||"",
description: item.snippet.description||"",
viewCount: 0,
};});
if(config.sortBy==="popular"){
const videoIds=videos.map((v)=> v.videoId).join(",");
$.get(`https://www.googleapis.com/youtube/v3/videos?part=statistics&id=${videoIds}&key=${config.apiKey}`
)
.done(function (statsData){
if(statsData.items){
const statsMap={};
statsData.items.forEach(function (item){
statsMap[item.id]=item.statistics.viewCount;
});
videos.forEach(function (v){
v.viewCount=parseInt(statsMap[v.videoId]||0);
});
}
allVideos=sortVideos(videos, config.sortBy);
if(duration > 0){
try {
localStorage.setItem(cacheKey,
JSON.stringify({
data: videos,
timestamp: now,
})
);
} catch (e){
console.warn("Failed to cache videos:", e);
}}
renderVideos(allVideos, shownCount);
})
.fail(function (){
console.warn("Failed to fetch video statistics for popular sorting."
);
allVideos=sortVideos(videos, config.sortBy);
renderVideos(allVideos, shownCount);
});
}else{
allVideos=sortVideos(videos, config.sortBy);
if(duration > 0){
try {
localStorage.setItem(cacheKey,
JSON.stringify({
data: videos,
timestamp: now,
})
);
} catch (e){
console.warn("Failed to cache videos:", e);
}}
renderVideos(allVideos, shownCount);
}}, 2000);
})
.fail(function (){
setTimeout(function (){
$container.empty();
$container.html('<div class="ultp-ytg-error">Failed to fetch videos. Please try again.</div>'
);
}, 3000);
});
}
$block.on("click", ".ultp-ytg-playlist-item", function (){
const videoId=$(this).data("video-id");
if(!videoId) return;
activeVideo=allVideos.find(function (v){
return v.videoId===videoId;
});
if(activeVideo){
renderPlaylistLayout(allVideos);
}});
$block.on("click", ".ultp-ytg-play__icon", function (){
const $img=$(this).siblings("img[data-video-id]");
const videoId=$img.data("video-id");
if(!videoId) return;
const $item=$(this).closest(".ultp-ytg-item");
const $videoDiv=$item.find(".ultp-ytg-video");
$videoDiv.html('<div class="ultp-ytg-loading"><div class="ytg-loader"></div></div>'
);
$item
.addClass("active")
.siblings(".ultp-ytg-item")
.removeClass("active");
setTimeout(function (){
playingId=videoId;
renderGridLayout(allVideos, shownCount);
}, 1000);
});
$block.on("click", ".ultp-ytg-video img[data-video-id]", function (){
const videoId=$(this).data("video-id");
if(!videoId) return;
playingId=videoId;
renderGridLayout(allVideos, shownCount);
});
$loadMoreBtn.on("click", function (){
shownCount +=config.videosPerPage.lg;
renderGridLayout(allVideos, shownCount);
});
$(window).on("resize", function (){
if(allVideos.length){
updateResponsiveCounts();
renderVideos(allVideos, shownCount);
}});
}});
}})(jQuery);
function wpae_add_honeypot_field(){
jQuery('form.mc4wp-form').append(wpa_hidden_field);
jQuery('form.quform-form').append(wpa_hidden_field);
jQuery(wpa_hidden_field).insertAfter('input.wpae_initiator'); // For All using initiator // EED/ BuddyPress/ HTML FORMS
jQuery('form.avia_ajax_form').append(wpa_hidden_field);
jQuery('.nf-form-layout form').append(wpa_hidden_field);
jQuery('#edd-blocks-form__register').append(wpa_hidden_field);
jQuery('form.brxe-form').append(wpa_hidden_field);
jQuery('form.forminator-custom-form').append(wpa_hidden_field);
jQuery('form.wpmtst-submission-form').append(wpa_hidden_field);
jQuery('form.fc-form').append(wpa_hidden_field);
jQuery('form#order_review').append(wpa_hidden_field);
jQuery('form.mailpoet_form').append(wpa_hidden_field);
jQuery('form.wsf-form').append(wpa_hidden_field);
jQuery('form.jet-form-builder').append(wpa_hidden_field);
jQuery('form.brxe-brf-pro-forms').append(wpa_hidden_field);
jQuery('form.sib_signup_form').append(wpa_hidden_field);
jQuery('form.youzify-membership-login-form').append(wpa_hidden_field);
jQuery('form.fl-contact-form').append(wpa_hidden_field);
jQuery('form.srfm-form').append(wpa_hidden_field);
jQuery('form.everest-form').append(wpa_hidden_field);
jQuery('.bit-form form').append(wpa_hidden_field);
if(jQuery('form.woocommerce-checkout input#wpae_initiator').length===0){
jQuery('form.woocommerce-checkout').append(wpa_hidden_field);
}}
jQuery(document).ready(function(){
jQuery(document).on('gform_post_render', function(event, form_id, current_page){
wpae_reinitalize_after_form_load();
});
jQuery(document).on('edd_gateway_loaded', function (gateway){
wpae_reinitalize_after_form_load();
});
jQuery(document).on('nfFormReady', function(){
wpae_reinitalize_after_form_load();
});
if(typeof nfRadio!=='undefined'){
nfRadio.channel("forms").on("before:submit", function(e){
$honeypotLen=jQuery('input[name='+wpa_field_name+']').length;
if(parseInt($honeypotLen) > 0){
var extra=e.get('extra');
extra.wpa_field_name=wpa_field_name
extra.wpa_field_value=jQuery('input[name='+wpa_field_name+']').val();
extra.alt_s=jQuery('input[name=alt_s]').val();
e.set('extra', extra);
}});
}
if(typeof MailPoet!=='undefined'&&typeof MailPoet.Ajax!=='undefined'&&typeof MailPoet.Ajax.getParams==='function'){
(function(wapeMailpoetGetParams){
MailPoet.Ajax.getParams=function(){
const wapeMailpoetParams=wapeMailpoetGetParams.call(this);
wapeMailpoetParams[wpa_field_name]=jQuery('input[name='+wpa_field_name+']').val();
wapeMailpoetParams.alt_s=jQuery('input[name=alt_s]').val();
return wapeMailpoetParams;
};})(MailPoet.Ajax.getParams);
}
jQuery(document).on('wsf-rendered', function(e, form, form_id, instance_id){
wpae_reinitalize_after_form_load();
});
jQuery(document).on('yith_welrp_popup_template_loaded', function(event, popup, context){
jQuery('form.yith-welrp-form').append(wpa_hidden_field);
});
jQuery.ajaxSetup({
beforeSend: function(jqXHR, settings){
if(typeof settings.data==='string'&&settings.data.includes('action=fl_builder_email')){
var wpaFieldName=wpa_field_name;
var wpaFieldValue=jQuery('input[name=' + wpaFieldName + ']').val();
var altSValue=jQuery('input[name=alt_s]').val();
settings.data +='&' + encodeURIComponent(wpaFieldName) + '=' + encodeURIComponent(wpaFieldValue);
settings.data +='&alt_s=' + encodeURIComponent(altSValue);
}}
});
});
jQuery(document).ajaxComplete(function(event, xhr, settings){
wpae_reinitalize_after_form_load();
});
function wpae_reinitalize_after_form_load(){
jQuery('.wpa_hidden_field').remove();
jQuery('#altEmail_container, .altEmail_container').remove();
wpa_add_honeypot_field();
wpae_add_honeypot_field();
if(wpa_add_test=='yes'){
wpa_add_test_block();
}};
(function(){"use strict";window.kadence={initOutlineToggle:function(){document.body.addEventListener("keydown",function(){document.body.classList.remove("hide-focus-outline")}),document.body.addEventListener("mousedown",function(){document.body.classList.add("hide-focus-outline")})},getOffset:function(a){if(a instanceof HTMLElement){var b=a.getBoundingClientRect();return{top:b.top+window.pageYOffset,left:b.left+window.pageXOffset}}return{top:null,left:null}},findParents:function(a,b){function c(a){var e=a.parentNode;e instanceof HTMLElement&&(e.matches(b)&&d.push(e),c(e))}var d=[];return c(a),d},toggleAttribute:function(a,b,c,d){c===void 0&&(c=!0),d===void 0&&(d=!1),a.getAttribute(b)===c?a.setAttribute(b,d):a.setAttribute(b,c)},initNavToggleSubmenus:function(){var a=document.querySelectorAll(".nav--toggle-sub");if(a.length)for(let b=0;b<a.length;b++)window.kadence.initEachNavToggleSubmenu(a[b]),window.kadence.initEachNavToggleSubmenuInside(a[b])},initEachNavToggleSubmenu:function(a){var b=a.querySelectorAll(".menu ul");if(b.length)for(let f=0;f<b.length;f++){var c=b[f].parentNode;let g=c.querySelector(".dropdown-nav-toggle");if(g){var d=c.querySelector(".nav-drop-title-wrap").firstChild.textContent.trim(),e=document.createElement("BUTTON");e.setAttribute("aria-label",d?kadenceConfig.screenReader.expandOf+" "+d:kadenceConfig.screenReader.expand),e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded","false"),e.setAttribute("aria-label",d?kadenceConfig.screenReader.expandOf+" "+d:kadenceConfig.screenReader.expand),e.classList.add("dropdown-nav-special-toggle"),c.insertBefore(e,c.childNodes[1]),e.addEventListener("click",function(a){a.preventDefault(),window.kadence.toggleSubMenu(a.target.closest("li"))}),a.classList.contains("click-to-open")||c.addEventListener("mouseleave",function(a){var b=a.relatedTarget;b&&c.contains(b)||window.kadence.toggleSubMenu(c,!1)}),c.querySelector("a").addEventListener("focus",function(a){var b=a.target.parentNode.parentNode.querySelectorAll("li.menu-item--toggled-on");for(let d=0;d<b.length;d++)c!==b[d]&&window.kadence.toggleSubMenu(b[d],!1)}),b[f].addEventListener("keydown",function(a){var c="ul.toggle-show > li > a, ul.toggle-show > li > .dropdown-nav-special-toggle";if(9===a.keyCode){var c="ul.toggle-show > li > a, ul.toggle-show > li > .dropdown-nav-special-toggle";b[f].parentNode.classList.contains("kadence-menu-mega-enabled")&&(c="a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex=\"0\"], [contenteditable]"),a.shiftKey?window.kadence.isfirstFocusableElement(b[f],document.activeElement,c)&&window.kadence.toggleSubMenu(b[f].parentNode,!1):window.kadence.islastFocusableElement(b[f],document.activeElement,c)&&window.kadence.toggleSubMenu(b[f].parentNode,!1)}27===a.keyCode&&(window.kadence.toggleSubMenu(b[f].parentNode,!1),b[f].parentNode.querySelector(".dropdown-nav-special-toggle").focus())}),b[f].parentNode.classList.add("menu-item--has-toggle")}}},initEachNavToggleSubmenuInside:function(a){var b=a.querySelectorAll(".menu-item-has-children");if(b.length)for(let a=0;a<b.length;a++)b[a].addEventListener("mouseenter",function(){if(b[a].querySelector("ul.sub-menu")){var c=b[a].querySelector("ul.sub-menu"),d=window.kadence.getOffset(c),e=d.left,f=c.offsetWidth,g=window.innerWidth;e+f<=g||c.classList.add("sub-menu-edge")}})},toggleSubMenu:function(a,b){if(!a||"LI"!==a.tagName||!a.querySelector("ul"))return;var c=a.querySelector(".dropdown-nav-special-toggle"),d=a.querySelector("ul"),e=a.querySelector(".nav-drop-title-wrap").firstChild.textContent.trim();let f=a.classList.contains("menu-item--toggled-on")||d&&d.classList.contains("opened");void 0!==b&&"boolean"==typeof b&&(f=!b);var g=(!f).toString();if(c&&c.setAttribute("aria-expanded",g),f){setTimeout(function(){a.classList.remove("menu-item--toggled-on"),d&&(d.classList.remove("toggle-show"),d.classList.remove("opened")),c&&c.setAttribute("aria-label",e?kadenceConfig.screenReader.expandOf+" "+e:kadenceConfig.screenReader.expand)},5);var h=a.querySelectorAll(".menu-item--toggled-on");for(let a=0;a<h.length;a++)window.kadence.toggleSubMenu(h[a],!1)}else{var j=a.parentNode.querySelectorAll("li");for(let b=0;b<j.length;b++)if(j[b]!==a){var k=j[b].querySelector("ul");k&&(j[b].classList.contains("menu-item--toggled-on")||k.classList.contains("opened"))&&window.kadence.toggleSubMenu(j[b],!1)}a.classList.add("menu-item--toggled-on"),d&&(d.classList.add("toggle-show"),d.classList.add("opened")),c&&c.setAttribute("aria-label",e?kadenceConfig.screenReader.collapseOf+" "+e:kadenceConfig.screenReader.collapse)}},isfirstFocusableElement:function(a,b,c){var d=a.querySelectorAll(c);return!!(0<d.length)&&b===d[0]},islastFocusableElement:function(a,b,c){var d=a.querySelectorAll(c);return!!(0<d.length)&&b===d[d.length-1]},toggleDrawer:function(a,b){b="undefined"==typeof b||b;var c=a,d=document.querySelector(c.dataset.toggleTarget);if(d){var e=window.innerWidth-document.documentElement.clientWidth,f=c.dataset.toggleDuration?c.dataset.toggleDuration:250;if(c.hasAttribute("aria-expanded")&&window.kadence.toggleAttribute(c,"aria-expanded","true","false"),d.classList.contains("show-drawer"))c.dataset.toggleBodyClass&&document.body.classList.remove(c.dataset.toggleBodyClass),d.classList.remove("active"),d.classList.remove("pop-animated"),document.body.classList.remove("kadence-scrollbar-fixer"),setTimeout(function(){d.classList.remove("show-drawer");var a=new Event("kadence-drawer-closed");if(window.dispatchEvent(a),c.dataset.setFocus&&b){var e=document.querySelector(c.dataset.setFocus);e&&(e.focus(),e.hasAttribute("aria-expanded")&&window.kadence.toggleAttribute(e,"aria-expanded","true","false"))}},f);else if(d.classList.add("show-drawer"),c.dataset.toggleBodyClass&&(document.body.classList.toggle(c.dataset.toggleBodyClass),c.dataset.toggleBodyClass.includes("showing-popup-drawer-")&&(document.body.style.setProperty("--scrollbar-offset",e+"px"),document.body.classList.add("kadence-scrollbar-fixer"))),setTimeout(function(){d.classList.add("active");var a=new Event("kadence-drawer-opened");if(window.dispatchEvent(a),c.dataset.setFocus&&b){var e=document.querySelector(c.dataset.setFocus);if(e){e.hasAttribute("aria-expanded")&&window.kadence.toggleAttribute(e,"aria-expanded","true","false");var f=e.value;e.value="",e.focus(),e.value=f}}},10),setTimeout(function(){d.classList.add("pop-animated")},f),d.classList.contains("popup-drawer")){var g=d.querySelectorAll("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])"),h=g[0],i=g[g.length-1];document.addEventListener("keydown",function(a){let b="Tab"===a.key||9===a.keyCode;b&&(a.shiftKey?document.activeElement===h&&(i.focus(),a.preventDefault()):document.activeElement===i&&(h.focus(),a.preventDefault()))})}}},initToggleDrawer:function(){var a=document.querySelectorAll(".drawer-toggle");if(a.length){for(let b=0;b<a.length;b++)a[b].addEventListener("click",function(c){c.preventDefault(),window.kadence.toggleDrawer(a[b])});document.addEventListener("keyup",function(a){27===a.keyCode&&document.querySelectorAll(".popup-drawer.show-drawer.active")&&(a.preventDefault(),document.querySelectorAll(".popup-drawer.show-drawer.active").forEach(function(a){a.querySelector(".drawer-toggle")?window.kadence.toggleDrawer(a.querySelector(".drawer-toggle")):window.kadence.toggleDrawer(document.querySelector("*[data-toggle-target=\""+a.dataset.drawerTargetString+"\"]"))}))}),document.addEventListener("click",function(a){var b=a.target,c=document.querySelector(".show-drawer.active .drawer-overlay");b===c&&window.kadence.toggleDrawer(document.querySelector("*[data-toggle-target=\""+c.dataset.drawerTargetString+"\"]"));var d=document.querySelector("#search-drawer.show-drawer.active .drawer-content"),c=document.querySelector("#search-drawer.show-drawer.active .drawer-overlay");b===d&&window.kadence.toggleDrawer(document.querySelector("*[data-toggle-target=\""+c.dataset.drawerTargetString+"\"]"))})}},initMobileToggleSub:function(){var a=document.querySelectorAll(".has-collapse-sub-nav");a.forEach(function(a){var b=a.querySelector(".current-menu-item");b&&window.kadence.findParents(b,"li").forEach(function(a){var b=a.querySelector(".drawer-sub-toggle");b&&window.kadence.toggleDrawer(b,!0)})});var b=document.querySelectorAll(".drawer-sub-toggle");if(b.length)for(let a=0;a<b.length;a++)b[a].addEventListener("click",function(c){c.preventDefault(),window.kadence.toggleDrawer(b[a])})},initMobileToggleAnchor:function(){var a=document.getElementById("mobile-drawer");if(a){var b=a.querySelectorAll("a:not(.kt-tab-title)");if(b.length)for(let c=0;c<b.length;c++)b[c].addEventListener("click",function(){window.kadence.toggleDrawer(a.querySelector(".menu-toggle-close"),!1)})}},initTransHeaderPadding:function(){if(!document.body.classList.contains("no-header")&&document.body.classList.contains("transparent-header")&&document.body.classList.contains("mobile-transparent-header")){var a=document.querySelector(".entry-hero-container-inner"),b=document.querySelector("#masthead"),c=function(){b,a.style.paddingTop=kadenceConfig.breakPoints.desktop<=window.innerWidth?document.body.classList.contains("transparent-header")?b.offsetHeight+"px":0:document.body.classList.contains("mobile-transparent-header")?b.offsetHeight+"px":0};a&&(window.addEventListener("resize",c,!1),window.addEventListener("scroll",c,!1),window.addEventListener("load",c,!1),c())}},initStickyHeader:function(){var a=document.querySelector("#main-header .kadence-sticky-header"),b=document.querySelector("#mobile-header .kadence-sticky-header"),c=document.getElementById("wrapper"),d=document.querySelectorAll(".kadence-pro-fixed-above"),f=document.querySelectorAll(".kadence-before-wrapper-item"),g="mobile",h=0,i=0;parseInt(kadenceConfig.breakPoints.desktop)<window.innerWidth?(g="desktop",a&&(a.style.position="static",i=window.kadence.getOffset(a).top,a.style.position=null)):b&&(b.style.position="static",i=window.kadence.getOffset(b).top,b.style.position=null);var j=function(j){var e,k=window.kadence.getOffset(c).top;if(document.body.classList.toString().includes("boom_bar-static-top")){var l=document.querySelector(".boom_bar");k=window.kadence.getOffset(c).top-l.offsetHeight}if(f.length){var m=0;for(let a=0;a<f.length;a++)m+=f[a].offsetHeight;k=window.kadence.getOffset(c).top-m}if(d.length){var n=0;for(let a=0;a<d.length;a++)n+=d[a].offsetHeight;k=window.kadence.getOffset(c).top+n}if(document.body.classList.contains("woocommerce-demo-store")&&document.body.classList.contains("kadence-store-notice-placement-above")){var o=document.querySelector(".woocommerce-store-notice");o&&0<o.offsetHeight&&(k-=o.offsetHeight)}if(e=kadenceConfig.breakPoints.desktop<=window.innerWidth?a:b,!!e){kadenceConfig.breakPoints.desktop<=window.innerWidth?"mobile"===g?(i=window.kadence.getOffset(e).top,g="desktop"):j&&"updateActive"===j&&(e.style.top="auto",i=window.kadence.getOffset(e).top,g="desktop"):"desktop"===g?(i=window.kadence.getOffset(e).top,g="mobile"):j&&"updateActive"===j&&(e.style.top="auto",i=window.kadence.getOffset(e).top,g="mobile");var p=e.parentNode,q=e.getAttribute("data-shrink"),r=e.getAttribute("data-reveal-scroll-up"),s=parseInt(e.getAttribute("data-start-height"));if((!s||j&&void 0!==j.type&&"orientationchange"===j.type)&&(e.setAttribute("data-start-height",e.offsetHeight),s=e.offsetHeight,p.classList.contains("site-header-upper-inner-wrap")?(p.style.height=null,j&&void 0!==j.type&&"orientationchange"===j.type?e.classList.contains("item-is-fixed")?setTimeout(function(){p.style.height=Math.floor(p.offsetHeight+e.offsetHeight)+"px"},21):setTimeout(function(){p.style.height=p.offsetHeight+"px"},21):p.style.height=p.offsetHeight+"px"):p.classList.contains("site-header-inner-wrap")?(p.style.height=null,p.style.height=p.offsetHeight+"px"):p.style.height=e.offsetHeight+"px"),"true"===q){var t=e.getAttribute("data-shrink-height");if(t){if("true"!==r)var u=Math.floor(i-k);else if(window.scrollY>h)var u=Math.floor(Math.floor(i)-Math.floor(k)+Math.floor(s));else var u=Math.floor(i-k);var v=e.querySelectorAll(".custom-logo"),w=e.querySelector(".site-main-header-inner-wrap"),x=parseInt(w.getAttribute("data-start-height"));if(x||(w.setAttribute("data-start-height",w.offsetHeight),x=w.offsetHeight),window.scrollY<=u){if(w.style.height=x+"px",w.style.minHeight=x+"px",w.style.maxHeight=x+"px",v)for(let a,b=0;b<v.length;b++)a=v[b],a.style.maxHeight="100%";}else if(window.scrollY>u){var y=Math.max(t,x-(window.scrollY-(i-k)));if(w.style.height=y+"px",w.style.minHeight=y+"px",w.style.maxHeight=y+"px",v)for(let a,b=0;b<v.length;b++)a=v[b],a.style.maxHeight=y+"px"}}}if("true"===r){var z=Math.floor(i-k),A=window.scrollY,B=e.offsetHeight,C=h-A,D=window.getComputedStyle(e).getPropertyValue("transform").match(/(-?[0-9\.]+)/g);if(D&&void 0!==D[5]&&D[5])var E=parseInt(D[5])+C;else var E=0;var F=A>h;if(A<=z)e.style.transform="translateY(0px)";else if(F)e.classList.add("item-hidden-above"),e.style.transform="translateY("+(Math.abs(E)>B?-B:E)+"px)";else{var z=Math.floor(i-k);e.style.transform="translateY("+(0<E?0:E)+"px)",e.classList.remove("item-hidden-above")}h=A}else var z=Math.floor(i-k);window.scrollY==z?(e.style.top=k+"px",e.classList.add("item-is-fixed"),e.classList.add("item-at-start"),e.classList.remove("item-is-stuck"),p.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):window.scrollY>z?"true"===r?window.scrollY<B+60&&e.classList.contains("item-at-start")?(e.style.height=null,e.style.top=k+"px",e.classList.add("item-is-fixed"),e.classList.add("item-is-stuck"),p.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):(e.style.top=k+"px",e.classList.add("item-is-fixed"),e.classList.add("item-is-stuck"),e.classList.remove("item-at-start"),p.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):(e.style.top=k+"px",e.classList.add("item-is-fixed"),e.classList.remove("item-at-start"),e.classList.add("item-is-stuck"),p.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):e.classList.contains("item-is-fixed")&&(e.classList.remove("item-is-fixed"),e.classList.remove("item-at-start"),e.classList.remove("item-is-stuck"),e.style.height=null,e.style.top=null,p.classList.remove("child-is-fixed"),document.body.classList.remove("header-is-fixed"))}};if((a||b)&&(window.addEventListener("resize",j,!1),window.addEventListener("scroll",j,!1),window.addEventListener("load",j,!1),window.addEventListener("orientationchange",j),"complete"===document.readyState&&j("updateActive"),document.body.classList.contains("woocommerce-demo-store")&&document.body.classList.contains("kadence-store-notice-placement-above"))){var k=function(a,b){var c={root:document.documentElement},d=new IntersectionObserver(a=>{a.forEach(a=>{b(0<a.intersectionRatio)})},c);d.observe(a)};k(document.querySelector(".woocommerce-store-notice"),()=>{j("updateActive")})}},getTopOffset:function(a="scroll"){if("load"===a)var b=document.querySelector("#main-header .kadence-sticky-header"),c=document.querySelector("#mobile-header .kadence-sticky-header");else var b=document.querySelector("#main-header .kadence-sticky-header:not([data-reveal-scroll-up=\"true\"])"),c=document.querySelector("#mobile-header .kadence-sticky-header:not([data-reveal-scroll-up=\"true\"])");var d=0,e=0;if(kadenceConfig.breakPoints.desktop<=window.innerWidth){if(b){var f=b.getAttribute("data-shrink");d="true"!==f||b.classList.contains("site-header-inner-wrap")?Math.floor(b.offsetHeight):Math.floor(b.getAttribute("data-shrink-height"))}else d=0;document.body.classList.contains("admin-bar")&&(e=32)}else{if(c){var f=c.getAttribute("data-shrink");d="true"===f?Math.floor(c.getAttribute("data-shrink-height")):Math.floor(c.offsetHeight)}else d=0;document.body.classList.contains("admin-bar")&&(e=46)}let g=0,h=!1;const i=document.querySelector(".wp-block-kadence-header");i&&(h=kadenceConfig.breakPoints.desktop<=window.innerWidth?i.classList.contains("header-desktop-sticky"):i.classList.contains("header-mobile-sticky"),h&&(g=i.offsetHeight));const j=i&&h?g:d;return Math.floor(j+e+Math.floor(kadenceConfig.scrollOffset))},scrollToElement:function(a,b,c="scroll"){b=!("undefined"!=typeof b)||b;var d=window.kadence.getTopOffset(c),e=Math.floor(a.getBoundingClientRect().top)-d;window.scrollBy({top:e,left:0,behavior:"smooth"}),a.tabIndex="-1",a.focus({preventScroll:!0}),a.classList.contains("kt-title-item")&&a.firstElementChild.click(),b&&window.history.pushState("","","#"+a.id)},anchorScrollToCheck:function(a,b){if(b="undefined"==typeof b?null:b,a.target.getAttribute("href"))var c=a.target;else{var c=a.target.closest("a");if(!c)return;if(!c.getAttribute("href"))return}if(!(c.parentNode&&c.parentNode.hasAttribute("role")&&"tab"===c.parentNode.getAttribute("role"))&&!c.closest(".woocommerce-tabs ul.tabs")&&!(c.classList.contains("comment-reply-link")||"#respond"===c.getAttribute("href")||c.getAttribute("href").includes("#respond"))){var d=b?b.getAttribute("href").substring(b.getAttribute("href").indexOf("#")):c.getAttribute("href").substring(c.getAttribute("href").indexOf("#"));var e=document.getElementById(d.replace("#",""));e&&(e?.classList?.contains("kt-accordion-pane")||(a.preventDefault(),window.kadence.scrollToElement(e),window.kadence.updateActiveAnchors()))}},initStickySidebarWidget:function(){if(document.body.classList.contains("has-sticky-sidebar-widget")){var a=window.kadence.getTopOffset(),b=document.querySelector("#secondary .sidebar-inner-wrap .widget:last-child");b&&(b.style.top=Math.floor(a+20)+"px",b.style.maxHeight="calc(100vh - "+Math.floor(a+20)+"px)")}},initStickySidebar:function(){if(document.body.classList.contains("has-sticky-sidebar")){var a=window.kadence.getTopOffset(),b=document.querySelector("#secondary .sidebar-inner-wrap");b&&(b.style.top=Math.floor(a+20)+"px",b.style.maxHeight="calc(100vh - "+Math.floor(a+20)+"px)")}},initActiveAnchors:function(){""!=window.location.hash&&window.kadence.updateActiveAnchors(),window.onhashchange=function(){window.kadence.updateActiveAnchors()}},updateActiveAnchors:function(){const a=document.querySelectorAll(".menu-item");a.forEach(function(a){const b=a.querySelector("a");b?.href&&b.href.includes("#")&&(window.location.href==b.href?a.classList.add("current-menu-item"):a.classList.remove("current-menu-item"))})},initAnchorScrollTo:function(){if(!document.body.classList.contains("no-anchor-scroll")){if(window.onhashchange=function(){""===window.location.hash&&(window.scrollTo({top:0,behavior:"smooth"}),document.activeElement.blur())},""!=window.location.hash){var a,b=location.hash.substring(1);if(!/^[A-z0-9_-]+$/.test(b))return;a=document.getElementById(b),a&&window.setTimeout(function(){window.kadence.scrollToElement(a,!1,"load")},100)}var c=document.querySelectorAll("a[href*=\\#]:not([href=\\#]):not(.scroll-ignore):not([data-tab]):not([data-toggle]):not(.woocommerce-tabs a):not(.tabs a)");c.length&&c.forEach(function(a){try{var b=new URL(a.href);b.pathname===window.location.pathname&&a.addEventListener("click",function(a){window.kadence.anchorScrollToCheck(a)})}catch(b){console.log("ClassList: "+a.classList,"Invalid URL")}})}},initScrollToTop:function(){var a=document.getElementById("kt-scroll-up");if(a){var b=function(){100<window.scrollY?(a.classList.add("scroll-visible"),a.setAttribute("aria-hidden",!1)):(a.classList.remove("scroll-visible"),a.setAttribute("aria-hidden",!0))};window.addEventListener("scroll",b),b(),a.addEventListener("click",function(a){a.preventDefault(),window.scrollTo({top:0,behavior:"smooth"}),document.querySelector(".skip-link").focus({preventScroll:!0}),document.activeElement.blur()})}var c=document.getElementById("kt-scroll-up-reader");c&&c.addEventListener("click",function(a){a.preventDefault(),window.scrollTo({top:0,behavior:"smooth"}),document.querySelector(".skip-link").focus()})},initHoverSubmenuAria:function(){var a=document.querySelectorAll(".header-navigation.nav--toggle-sub:not(.click-to-open)");a.forEach(function(a){var b=a.querySelectorAll(".menu-item-has-children");b.forEach(function(a){var b=a.querySelector(".dropdown-nav-special-toggle");b&&(a.addEventListener("mouseenter",function(){b.setAttribute("aria-expanded","true")}),a.addEventListener("mouseleave",function(c){var d=c.relatedTarget;d&&a.contains(d)||b.setAttribute("aria-expanded","false")}))})})},initClickToOpen:function(){const a=document.querySelectorAll(".header-navigation.click-to-open li.menu-item--has-toggle");a.forEach(function(a){const b=a.querySelector("a"),c=a.querySelector("button[class=\"dropdown-nav*\"]");[b,c].forEach(function(b){b&&b.addEventListener("click",function(b){b.preventDefault();const c=a.querySelector("ul.sub-menu");if(c){const b=c.classList.contains("opened");c.classList.toggle("opened",!b),a.classList.toggle("menu-item--toggled-on",!b),c.classList.toggle("toggle-show",!b);var d=a.querySelector(".dropdown-nav-special-toggle");d&&d.setAttribute("aria-expanded",(!b).toString());const e=Array.from(a.parentNode.children).filter(b=>b!==a);if(e.forEach(function(a){const b=a.querySelector(":scope > ul.sub-menu");if(b){b.classList.remove("opened"),a.classList.remove("menu-item--toggled-on"),b.classList.remove("toggle-show");var c=a.querySelector(".dropdown-nav-special-toggle");c&&c.setAttribute("aria-expanded","false")}}),!b){const b=d=>{if(!a.contains(d.target)){c.classList.remove("opened"),a.classList.remove("menu-item--toggled-on"),c.classList.remove("toggle-show");var e=a.querySelector(".dropdown-nav-special-toggle");e&&e.setAttribute("aria-expanded","false"),document.removeEventListener("click",b)}};document.addEventListener("click",b)}}})})})},init:function(){window.kadence.initNavToggleSubmenus(),window.kadence.initToggleDrawer(),window.kadence.initMobileToggleAnchor(),window.kadence.initMobileToggleSub(),window.kadence.initOutlineToggle(),window.kadence.initStickyHeader(),window.kadence.initStickySidebar(),window.kadence.initStickySidebarWidget(),window.kadence.initTransHeaderPadding(),window.kadence.initAnchorScrollTo(),window.kadence.initScrollToTop(),window.kadence.initActiveAnchors(),window.kadence.initHoverSubmenuAria(),window.kadence.initClickToOpen()}},"loading"===document.readyState?document.addEventListener("DOMContentLoaded",window.kadence.init):window.kadence.init()})();