PageSourceSearch

https://viamaja.dk/cdn/shop/t/60/assets/sticky-add-to-cart.js?v=155755642970355254701790533514

js viamaja.dk collected 2026-10-08 18:35:25 UTC 3,471 bytes, 2 lines download raw bytes

1class StickyAddToCart extends HTMLElement{static BOTTOM_THRESHOLD=200;static VISIBILITY_CLASS="is-visible";constructor(){super(),this.state={isVisible:!1,mainButton:null,headerHeight:0},this.observers={mainButton:null},this.scrollHandler=null}connectedCallback(){this.initialize()}disconnectedCallback(){this.cleanup()}initialize(){if(this.findElements(),!this.state.mainButton){console.warn("StickyAddToCart: Main button not found");return}this.updateHeaderHeight(),this.setupObservers(),this.attachEventListeners()}findElements(){const mainButtonId=this.querySelector("[data-main-button-id]")?.dataset.mainButtonId;mainButtonId&&(this.state.mainButton=document.getElementById(mainButtonId))}updateHeaderHeight(){const cssValue=getComputedStyle(document.documentElement).getPropertyValue("--header-height");this.state.headerHeight=parseInt(cssValue)||0}setupObservers(){this.setupMainButtonObserver()}setupMainButtonObserver(){this.state.mainButton&&(this.observers.mainButton=new IntersectionObserver(entries=>this.handleMainButtonIntersection(entries),{rootMargin:`-${this.state.headerHeight}px 0px 0px 0px`,threshold:0}),this.observers.mainButton.observe(this.state.mainButton))}handleMainButtonIntersection(entries){entries.forEach(entry=>{const buttonRect=entry.boundingClientRect,isButtonHidden=this.isButtonHidden(entry,buttonRect);isButtonHidden&&!this.isNearPageBottom()?this.show():isButtonHidden||this.hide()})}isButtonHidden(entry,buttonRect){return!entry.isIntersecting||buttonRect.top<this.state.headerHeight||buttonRect.bottom<this.state.headerHeight}attachEventListeners(){const button=this.querySelector(".sticky-add-to-cart__button");button&&button.addEventListener("click",e=>this.handleButtonClick(e)),this.scrollHandler=()=>this.handleScroll(),window.addEventListener("scroll",this.scrollHandler,{passive:!0})}handleScroll(){if(!this.state.mainButton)return;if(this.isNearPageBottom()){this.hide();return}const mainButtonRect=this.state.mainButton.getBoundingClientRect();this.isButtonOutOfView(mainButtonRect)?this.show():this.isButtonFullyVisible(mainButtonRect)&&this.hide()}isButtonOutOfView(buttonRect){return buttonRect.top<this.state.headerHeight||buttonRect.bottom<this.state.headerHeight||buttonRect.top<0}isButtonFullyVisible(buttonRect){return buttonRect.top>=this.state.headerHeight&&buttonRect.bottom<=window.innerHeight}isNearPageBottom(){const scrollTop=window.pageYOffset||document.documentElement.scrollTop,documentHeight=document.documentElement.scrollHeight,windowHeight=window.innerHeight;return documentHeight-(scrollTop+windowHeight)<StickyAddToCart.BOTTOM_THRESHOLD}handleButtonClick(event){event.preventDefault(),this.state.mainButton&&!this.state.mainButton.disabled&&this.state.mainButton.click()}show(){if(!this.state.isVisible&&!this.isNearPageBottom()){if(this.state.mainButton){const mainButtonRect=this.state.mainButton.getBoundingClientRect();if(this.isButtonFullyVisible(mainButtonRect))return}this.state.isVisible=!0,this.classList.add(StickyAddToCart.VISIBILITY_CLASS)}}hide(){this.state.isVisible&&(this.state.isVisible=!1,this.classList.remove(StickyAddToCart.VISIBILITY_CLASS))}cleanup(){Object.values(this.observers).forEach(observer=>{observer&&observer.disconnect()}),this.scrollHandler&&window.removeEventListener("scroll",this.scrollHandler)}}customElements.define("sticky-add-to-cart",StickyAddToCart);
2//# sourceMappingURL=/cdn/shop/t/60/assets/sticky-add-to-cart.js.map?v=155755642970355254701790533514

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.