From 564ebd52e55d55fca7c3a74b0a005114834735dc Mon Sep 17 00:00:00 2001 From: Mark Woodard Date: Mon, 25 Nov 2024 00:45:27 -0600 Subject: [PATCH] adding site identity images to sticky shrinking. Also making sure the image to shring is not in a mega menu --- includes/assets/js/kb-header-block.min.js | 2 +- src/assets/js/kb-header-block.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/includes/assets/js/kb-header-block.min.js b/includes/assets/js/kb-header-block.min.js index d119bd18d..0cd319181 100644 --- a/includes/assets/js/kb-header-block.min.js +++ b/includes/assets/js/kb-header-block.min.js @@ -1 +1 @@ -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;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._state="CREATED",(this.sticky||this.stickyTablet||this.stickyMobile)&&this.initStickyHeader();var c=new Event("MOUNTED",{bubbles:!0});c.ID=this.rootID,this.root.dispatchEvent(c),this._state="IDLE"}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("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(){this.activeSize=parseInt(kadenceHeaderConfig.breakPoints.desktop){b.appendChild(a)})),b}respondToVisibility(a,b){var c={root:document.documentElement},d=new IntersectionObserver(a=>{a.forEach(a=>{b(0 .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"),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;athis.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{window.KBHeaderBlocks=[];var a=document.querySelectorAll(".wp-block-kadence-header");for(let c=0;c{this.updateSticky("updateActive").bind(this)}))}setActiveSize(){this.activeSize=parseInt(kadenceHeaderConfig.breakPoints.desktop){b.appendChild(a)})),b}respondToVisibility(a,b){var c={root:document.documentElement},d=new IntersectionObserver(a=>{a.forEach(a=>{b(0 .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"),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;athis.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{window.KBHeaderBlocks=[];var a=document.querySelectorAll(".wp-block-kadence-header");for(let c=0;c