File "kb-header-block.min.js"

Full Path: /home/magiggjm/magistvandroids.com/wp-content/plugins/kadence-blocks/includes/assets/js/kb-header-block.min.js
File size: 12.76 KB
MIME-type: text/plain
Charset: utf-8

class KBHeader{components={};_state;root;rootID;autoTransparentSpacing;sticky;stickyTablet;stickyMobile;transparent;transparentTablet;transparentMobile;stickySection;stickySectionTablet;stickySectionMobile;activeSize="mobile";lastScrollTop=0;activeOffsetTop=0;shrinkMain=!1;shrinkMainHeight=0;shrinkMainHeightTablet=0;shrinkMainHeightMobile=0;shrinkStartHeight=0;mobileBreakpoint=0;currentTopPosition=0;anchorOffset=0;placeholderWrapper;stickyWrapper;isSticking=!1;isTransparent=!1;activeHeaderContainer;constructor(a,b={}){this.root="string"==typeof a?document.querySelector(a):a,this.activeHeaderContainer=this.root.querySelector(".wp-block-kadence-header-desktop"),this.rootID="aaa",this.autoTransparentSpacing="1"===this.root.dataset?.autoTransparentSpacing,this.sticky="1"==this.root.dataset?.sticky,this.stickyTablet="1"==this.root.dataset?.stickyTablet,this.stickyMobile="1"==this.root.dataset?.stickyMobile,this.transparent="1"==this.root.dataset?.transparent,this.transparentTablet="1"==this.root.dataset?.transparentTablet,this.transparentMobile="1"==this.root.dataset?.transparentMobile,this.stickySection=this.root.dataset?.stickySection,this.stickySectionTablet=this.root.dataset?.stickySectionTablet,this.stickySectionMobile=this.root.dataset?.stickySectionMobile,this.shrinkMain="1"===this.root.dataset?.shrinkMain,this.shrinkMainHeight=this.root.dataset?.shrinkMainHeight,this.shrinkMainHeightTablet=this.root.dataset?.shrinkMainHeightTablet,this.shrinkMainHeightMobile=this.root.dataset?.shrinkMainHeightMobile,this.revealScrollUp="1"===this.root.dataset?.revealScrollUp,this.mobileBreakpoint=this.root.dataset?.mobileBreakpoint,this._state="CREATED",(this.sticky||this.stickyTablet||this.stickyMobile)&&this.initStickyHeader(),this.mobileBreakpoint&&0!==this.mobileBreakpoint&&this.initMobileBreakpoint();var c=new Event("MOUNTED",{bubbles:!0});c.ID=this.rootID,this.root.dispatchEvent(c),this._state="IDLE"}initMobileBreakpoint(){this.mobileBreakpoint&&0!==this.mobileBreakpoint&&(window.addEventListener("resize",this.updateMobileBreakpoint.bind(this),!1),window.addEventListener("hashchange",this.updateMobileBreakpoint.bind(this),!1),window.addEventListener("scroll",this.updateMobileBreakpoint.bind(this),!1),window.addEventListener("load",this.updateMobileBreakpoint.bind(this),!1),window.addEventListener("orientationchange",this.updateMobileBreakpoint.bind(this)))}updateMobileBreakpoint(){this.setActiveSize(),"desktop"==this.activeSize?(this.root.querySelector(".wp-block-kadence-header-tablet").style.display="none",this.root.querySelector(".wp-block-kadence-header-desktop").style.display="block"):(this.root.querySelector(".wp-block-kadence-header-desktop").style.display="none",this.root.querySelector(".wp-block-kadence-header-tablet").style.display="block")}initStickyHeader(){this.sticky&&this.createAndSetPlaceholderAndStickyWrappers("desktop"),(this.stickyTablet||this.stickyMobile)&&this.createAndSetPlaceholderAndStickyWrappers("tablet"),this.placeholderWrapper&&this.stickyWrapper&&(this.setActiveSize(),this.updatePlaceholderAndStickyWrappers(),"desktop"==this.activeSize?this.sticky&&(this.activeOffsetTop=this.getOffset(this.placeholderWrapper).top):"tablet"==this.activeSize?this.stickyTablet&&(this.activeOffsetTop=this.getOffset(this.placeholderWrapper).top):this.stickyMobile&&(this.activeOffsetTop=this.getOffset(this.placeholderWrapper).top),window.addEventListener("resize",this.updateSticky.bind(this),!1),window.addEventListener("hashchange",this.updateSticky.bind(this),!1),window.addEventListener("scroll",this.updateSticky.bind(this),!1),window.addEventListener("load",this.updateSticky.bind(this),!1),window.addEventListener("orientationchange",this.updateSticky.bind(this)),"complete"===document.readyState&&this.updateSticky("updateActive"),document.body.classList.contains("woocommerce-demo-store")&&document.body.classList.contains("kadence-store-notice-placement-above")&&this.respondToVisibility(document.querySelector(".woocommerce-store-notice"),()=>{this.updateSticky("updateActive").bind(this)}))}setActiveSize(){const a=this.mobileBreakpoint&&0!==this.mobileBreakpoint?this.mobileBreakpoint:kadenceHeaderConfig.breakPoints.desktop;this.activeSize=parseInt(a)<window.innerWidth?"desktop":parseInt(kadenceHeaderConfig.breakPoints.tablet)<window.innerWidth?"tablet":"mobile";const b="desktop"==this.activeSize?".wp-block-kadence-header-desktop":".wp-block-kadence-header-tablet";this.activeHeaderContainer=this.root.querySelector(b)}createAndSetPlaceholderAndStickyWrappers(a){const b="desktop"==a?".wp-block-kadence-header-desktop":".wp-block-kadence-header-tablet",c=this["stickySection"+this.activeSizeCased(a)];if("top"==c||"bottom"==c||"main"==c){var d="";d="top"==c?".wp-block-kadence-header-row-top":"bottom"==c?".wp-block-kadence-header-row-bottom":".wp-block-kadence-header-row-center",this.stickyWrapper=this.root.querySelector(b+" "+d),this.placeholderWrapper=this.wrap([this.stickyWrapper])}else if("top_main"==c||"bottom_main"==c){var e=[];"top_main"==c&&(e.push(this.root.querySelector(b+" .wp-block-kadence-header-row-top")),e.push(this.root.querySelector(b+" .wp-block-kadence-header-row-center"))),"bottom_main"==c&&(e.push(this.root.querySelector(b+" .wp-block-kadence-header-row-center")),e.push(this.root.querySelector(b+" .wp-block-kadence-header-row-bottom"))),this.stickyWrapper=this.wrap(e),this.placeholderWrapper=this.wrap([this.stickyWrapper])}else this.stickyWrapper=this.root.querySelector(b),this.placeholderWrapper=this.root;this.stickyWrapper&&this.placeholderWrapper&&(this.stickyWrapper.classList.add("kb-header-sticky-wrapper"),this.placeholderWrapper.classList.add("kb-header-placeholder-wrapper"))}updatePlaceholderAndStickyWrappers(){const a=this["stickySection"+this.activeSizeCased()];a?(this.stickyWrapper=this.activeHeaderContainer.querySelector(".kb-header-sticky-wrapper"),this.placeholderWrapper=this.activeHeaderContainer.querySelector(".kb-header-placeholder-wrapper")):(this.stickyWrapper=this.activeHeaderContainer,this.placeholderWrapper=this.root)}wrap(a,b){return b=b||document.createElement("div"),a&&a[0]&&(a[0].parentNode.insertBefore(b,a[0]),a.forEach(a=>{b.appendChild(a)})),b}respondToVisibility(a,b){var c={root:document.documentElement},d=new IntersectionObserver(a=>{a.forEach(a=>{b(0<a.intersectionRatio)})},c);d.observe(a)}updateSticky(a){if(!this.stickyWrapper)return;const b=document.getElementsByClassName("wp-site-blocks")?.[0];var c=this.getOffset(b).top;this.anchorOffset=this.getOffset(this.placeholderWrapper).top;var d=window.scrollY;if(this.setActiveSize(),this.activeOffsetTop=this.getOffset(this.stickyWrapper).top,!("desktop"===this.activeSize&&this.sticky||"tablet"===this.activeSize&&this.stickyTablet||"mobile"===this.activeSize&&this.stickyMobile))return this.stickyWrapper.classList.remove("item-is-fixed"),this.stickyWrapper.classList.remove("item-at-start"),this.stickyWrapper.classList.remove("item-is-stuck"),this.stickyWrapper.style.height=null,this.stickyWrapper.style.top=null,this.stickyWrapper.style.position="initial",(void 0).classList.remove("child-is-fixed"),void document.body.classList.remove("header-is-fixed");this.updatePlaceholderAndStickyWrappers(),a&&"updateActive"===a&&(this.stickyWrapper.style.top="auto");var e=this.stickyWrapper.offsetHeight,f=this.placeholderWrapper.offsetWidth,g=this.getOffset(this.placeholderWrapper).left;if(this["transparent"+this.activeSizeCased()]||(this.placeholderWrapper.style.height=e+"px"),""!==this["stickySection"+this.activeSizeCased()]&&this["transparent"+this.activeSizeCased()]&&(this.placeholderWrapper.style.height=e+"px"),document.body.classList.toString().includes("boom_bar-static-top")){var h=document.querySelector(".boom_bar");c=this.getOffset(b).top-h.offsetHeight}var j=document.querySelectorAll(".kadence-before-wrapper-item");if(j.length){var k=0;for(let a=0;a<j.length;a++)k+=j[a].offsetHeight;c=this.getOffset(b).top-k}var l=document.querySelectorAll(".kadence-pro-fixed-above");if(l.length){var m=0;for(let a=0;a<l.length;a++)m+=l[a].offsetHeight;c=this.getOffset(b).top+m}var n=this.stickyWrapper.querySelectorAll(".kadence-menu-mega-enabled > .kb-nav-sub-menu");if(n.length){var o=this.getOffset(n[0]).top;this.stickyWrapper.style.setProperty("--kb-sticky-mega-overflow-header-offset",o-d+"px")}const p=c,q=c-e,r=this.currentTopPosition+e;var s=this.stickyWrapper.parentNode;if(this.shrinkMain){const b="mobile"===this.activeSize?this.shrinkMainHeightMobile:"tablet"===this.activeSize?this.shrinkMainHeightTablet:this.shrinkMainHeight;if(b){const c=this.activeHeaderContainer.querySelectorAll(".kb-img, .wp-block-kadence-identity img, .wp-block-image img"),d=this.activeHeaderContainer.querySelector(".wp-block-kadence-header-row-center .kadence-header-row-inner");(!this.shrinkStartHeight||a&&void 0!==a.type&&"orientationchange"===a.type)&&(this.shrinkStartHeight=d.offsetHeight);const e=Math.max(b,this.shrinkStartHeight-window.scrollY);if(d.style.height=e+"px",d.style.minHeight=e+"px",d.style.maxHeight=e+"px",0==window.scrollY){if(c)for(let a=0;a<c.length;a++){const b=c[a];b.style.maxHeight="100%"}}else if(c)for(let a=0;a<c.length;a++){const b=c[a];b.closest(".mega-menu")||(b.style.maxHeight=e+"px")}}}if(this.isSticking?(this.stickyWrapper.style.position="fixed",this.stickyWrapper.style.width=f+"px",this.stickyWrapper.style.left=g+"px",this.stickyWrapper.style.top=c+"px"):(this.stickyWrapper.style.position="initial",this.stickyWrapper.style.width="initial",this.stickyWrapper.style.left="initial",this.stickyWrapper.style.top="initial"),this.revealScrollUp){var t=d>this.lastScrollTop,u=Math.floor(this.anchorOffset+e);d<=this.anchorOffset-c?(this.currentTopPosition=0,this.setStickyChanged(!1)):d<=u?t?(this.currentTopPosition=0,this.setStickyChanged(!1)):(this.stickyWrapper.classList.remove("item-hidden-above"),this.currentTopPosition=p,this.setStickyChanged(!0)):d>=this.currentTopPosition&&d<=r?this.setStickyChanged(!1):(t?(this.stickyWrapper.classList.add("item-hidden-above"),this.stickyWrapper.style.top=q+"px",this.currentTopPosition=q):(this.stickyWrapper.classList.remove("item-hidden-above"),this.currentTopPosition=p),this.setStickyChanged(!0))}else{var u=Math.floor(this.anchorOffset-c);d<=u?(this.currentTopPosition=0,this.setStickyChanged(!1)):(this.currentTopPosition=p,this.setStickyChanged(!0))}this.lastScrollTop=d,window.scrollY==u?(this.stickyWrapper.classList.add("item-is-fixed"),this.stickyWrapper.classList.add("item-at-start"),this.stickyWrapper.classList.remove("item-is-stuck"),s.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):window.scrollY>u?this.revealScrollUp?window.scrollY<e+60&&this.stickyWrapper.classList.contains("item-at-start")?(this.stickyWrapper.style.height=null,this.stickyWrapper.classList.add("item-is-fixed"),this.stickyWrapper.classList.add("item-is-stuck"),s.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):(this.stickyWrapper.classList.add("item-is-fixed"),this.stickyWrapper.classList.add("item-is-stuck"),this.stickyWrapper.classList.remove("item-at-start"),s.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):(this.stickyWrapper.classList.add("item-is-fixed"),this.stickyWrapper.classList.remove("item-at-start"),this.stickyWrapper.classList.add("item-is-stuck"),s.classList.add("child-is-fixed"),document.body.classList.add("header-is-fixed")):this.stickyWrapper.classList.contains("item-is-fixed")&&(this.stickyWrapper.classList.remove("item-is-fixed"),this.stickyWrapper.classList.remove("item-at-start"),this.stickyWrapper.classList.remove("item-is-stuck"),this.stickyWrapper.style.position="initial",this.stickyWrapper.style.width="initial",this.stickyWrapper.style.left="initial",this.stickyWrapper.style.top="initial",this.stickyWrapper.style.height=null,s.classList.remove("child-is-fixed"),document.body.classList.remove("header-is-fixed"))}activeSizeCased(a){const b=a?a:this.activeSize;return"desktop"===b?"":b.charAt(0).toUpperCase()+b.slice(1)}setStickyChanged(a){if(this.isSticking!=a){this.isSticking=a;var b=new Event("KADENCE_HEADER_STICKY_CHANGED",{bubbles:!0});b.isSticking=this.isSticking,this.root.dispatchEvent(b)}}setTransparentChanged(a){if(this.isTransparent!=a){this.isTransparent=a;var b=new Event("KADENCE_HEADER_STICKY_CHANGED",{bubbles:!0});b.isTransparent=this.isTransparent,this.root.dispatchEvent(b)}}getOffset(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}}get state(){return this._state}set state(a){this._state=a;var b=new Event("STATE");b.val=a,b.ID=this.rootID,this.root.dispatchEvent(b)}}window.KBHeader=KBHeader;const initKBHeader=()=>{window.KBHeaderBlocks=[];var a=document.querySelectorAll(".wp-block-kadence-header");for(let c=0;c<a.length;c++){var b=a[c];const d=new KBHeader(b);window.KBHeaderBlocks.push(d)}};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",initKBHeader):initKBHeader();