1class RecentSalePopup extends HTMLElement{constructor(){super(),this.productList=this.getAttribute("data-product-list"),this.timeToShow=parseInt(this.getAttribute("data-time-to-show"))||10,this.timeAppear=parseInt(this.getAttribute("data-time-appear"))||10,this.randomHours=this.getAttribute("data-random-hours"),this.customerList=this.getAttribute("data-customer-list"),this.locationList=this.getAttribute("data-location-list"),this.showOnMobile=this.getAttribute("data-show-on-mobile"),this.isVisible=!1,this.currentTimeout=null,this.progressInterval=null,this.init()}init(){this.products=this.parseProductList(),this.customers=this.parseArray(this.customerList),this.locations=this.parseArray(this.locationList),this.timeOptions=this.parseArray(this.randomHours),this.showNotification=this.showNotification.bind(this),this.hideNotification=this.hideNotification.bind(this),this.closePopup=this.closePopup.bind(this),this.addEventListener("click",this.closePopup),window.innerWidth>750&&this.startNotificationCycle(),window.innerWidth<=749&&this.showOnMobile&&this.startNotificationCycle()}parseProductList(){const productItems=this.querySelectorAll(".recent-sale-product-item");if(productItems.length>0)return Array.from(productItems).map(item=>({title:item.getAttribute("data-product-title")||"",url:item.getAttribute("data-product-url")||"#",image:item.getAttribute("data-product-image")||"",alt:item.getAttribute("data-product-alt")||""}));if(this.productList)try{return JSON.parse(this.productList).map(product=>({title:product.title||"",url:product.url||"#",image:product.featured_image||product.images?.[0]||"",alt:product.title||""}))}catch(e){console.warn("Could not parse product list:",e)}return[]}parseArray(str){if(!str)return[];let separator="|";return str.includes(",")&&(separator=","),str.includes(";")&&(separator=";"),str.split(separator).map(item=>item.trim()).filter(item=>item&&item.length>0)}getRandomItem(array){return!array||array.length===0?"":array[Math.floor(Math.random()*array.length)]}getRandomTime(){const timeOption=this.getRandomItem(this.timeOptions);if(!timeOption)return"2 minutes ago";const match=timeOption.match(/(\d+)\s*(minute|hour|second)s?/i);if(match){const value=parseInt(match[1]),unit=match[2].toLowerCase();return`${value} ${unit}${value>1?"s":""} ago`}return timeOption}updateNotificationContent(){const product=this.getRandomItem(this.products),customer=this.getRandomItem(this.customers),location=this.getRandomItem(this.locations),time=this.getRandomTime(),productImage=this.querySelector(".random-product-image");productImage&&product.image&&(productImage.src=product.image,productImage.alt=product.alt||product.title||"Product");const productName=this.querySelector(".random-product-name"),productLink=this.querySelector(".recent-sale-popup-content-view a");productName&&(productName.textContent=product.title||"Product"),productLink&&(productLink.href=product.url||"#");const customerElement=this.querySelector(".random-customer");if(customerElement){const customerName=customer||this.getDefaultCustomer();customerElement.textContent=customerName}const locationElement=this.querySelector(".random-location");if(locationElement){const locationText=location?`in ${location}`:"in Unknown Location";locationElement.textContent=locationText}const timeElement=this.querySelector(".random-time");timeElement&&(timeElement.textContent=time)}getDefaultCustomer(){const defaultCustomers=["Someone"];return defaultCustomers[Math.floor(Math.random()*defaultCustomers.length)]}showNotification(){this.updateNotificationContent(),this.classList.add("is-show"),this.isVisible=!0,this.startProgressBar(),this.currentTimeout=setTimeout(()=>{this.hideNotification()},this.timeAppear*1e3)}hideNotification(){this.classList.remove("is-show"),this.isVisible=!1,this.stopProgressBar(),this.currentTimeout&&(clearTimeout(this.currentTimeout),this.currentTimeout=null),this.currentTimeout=setTimeout(()=>{this.showNotification()},this.timeToShow*1e3)}startProgressBar(){const progressBar=this.querySelector(".recent-sale-popup-progress-bar");progressBar&&(progressBar.style.width="0%",progressBar.style.transition="none",setTimeout(()=>{progressBar.style.transition=`width ${this.timeAppear}s linear`,progressBar.style.width="100%"},10))}stopProgressBar(){const progressBar=this.querySelector(".recent-sale-popup-progress-bar");progressBar&&(progressBar.style.transition="none",progressBar.style.width="0%")}startNotificationCycle(){setTimeout(()=>{this.showNotification()},this.timeToShow*1e3)}
1closePopup(event){event.target.closest(".recent-sale-popup-close")&&(event.preventDefault(),this.hideNotification(),this.currentTimeout&&(clearTimeout(this.currentTimeout),this.currentTimeout=null))}disconnectedCallback(){this.currentTimeout&&clearTimeout(this.currentTimeout),this.progressInterval&&clearInterval(this.progressInterval)}}customElements.get("recent-sale-popup")||customElements.define("recent-sale-popup",RecentSalePopup); 2//# sourceMappingURL=/cdn/shop/t/8/assets/recent-sale-popup.js.map?v=3231831740473589911772453469
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.