-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.min.js
1 lines (1 loc) · 21.9 KB
/
configuration.min.js
1
function initializeConfiguration(){setupCart(),setupMegamenu(),setupMobileMenu(),setupExtraMessages(),setupSEOs(),setupItemCountModifiers(),setupSiteCartActionListeners(),setupViewSelectHandlers(),setupProductInfoPager(),setupProductMainImage(),changePhotoOnHover(),setupMenuExpander(),setIconsOnChildfulMenuItems(),handleSearchOnMobile(),handleLogoutOnClick(),handleMobileMenu(),handleBackgroundOnMobileMenuClick(),handleProductContainerPosition(),handleMobileFilterButton(),initProductHover(),appendProductCountOnFooterMenu(),renderProducts(),handleMobileItemsBackgroundClick(),setupPaymentIcons(),setupShippingIcons(),observeProductChanges(),handleAddOpinionOnTabs(),handleHideMenuOnBackgroundMousenter(),handleVerticalMenu(),onProductNameClicked()}function setupCart(){const e=templateConfiguration.cartType;switch(console.info(`Selected cart type: ${e}`),e){case"site-cart":$(".basket-contain").remove(),$(".delivery-cost").text(getCheapestShippingCost());break;case"short-cart":$(".basket-site-cart").hide(),$(".delivery-cost").text(getCheapestShippingCost());break;default:console.warn(`Invalid basket variant: "${e}". The variant was not applied.`)}}function getCheapestShippingCost(){const e=frontAPI.getBasketInfo({lang:templateConfiguration.lang,currency:templateConfiguration.currency}).shippings.filter((e=>e.cost_float>0));if(0==e.length)return templateConfiguration.translation.freeDelivery;return e.reduce(((e,t)=>t.cost_float<e.cost_float?t:e),e[0]).cost}function setupMegamenu(){const e=templateConfiguration.megamenuType;console.info(`Selected mega menu type: ${e}`);const t=["cascade","version-1","version-1-plus","version-2","version-2-plus","version-3"];switch($(".menu").removeClass(t.join(" ")),t.includes(e)?$(".menu").addClass(e):console.warn(`Invalid megamenu variant: "${e}". The variant was not applied.`),e){case"version-2":case"version-2-plus":injectMegamenuActionButton();case"version-1-plus":case"version-2-plus":addProductOfTheDaysToMegamenu()}}function injectMegamenuActionButton(){const e=templateConfiguration.numberOfVisibleCategoryItems;console.info(`Action button injected on menu on position: ${e}`),$(".submenu.level1 ul.level1 > li.parent").each((function(){const t=$(this).find(".submenu.level2 ul.level2 > li");if(t.length-e<=0)return;t.slice(e).hide();const n=createButton("expand-menu-button",templateConfiguration.translation.expandCategory,(()=>{n.hide(),o.show(),t.show()})),o=createButton("collapse-menu-button",templateConfiguration.translation.collapseCategory,(()=>{o.hide(),n.show(),t.slice(e).hide()}));$(this).append(n).append(o)}))}function addProductOfTheDaysToMegamenu(){}function populateProductBoxFromAPI(e){const t=$(".product-placeholder").prop("outerHTML");frontAPI.getPotdProducts((n=>{const{list:o}=n;$.each(o,((n,o)=>{const{id:i,main_image:s,category:{name:a},producer:{name:c},url:r,name:l,price:{gross:{base:u},net:{base:d}}}=o,p=replacePlaceholders(t,{STOCK_ID:i,MAIN_IMAGE:s,CATEGORY_NAME:a,PRODUCER_NAME:c,URL:r,NAME:l,PRICE_GROSS_BASE:u,PRICE_NET_BASE:d});e.append(p)}))}),{lang:templateConfiguration.lang,currency:templateConfiguration.currency})}function replacePlaceholders(e,t){for(const n in t)if(t.hasOwnProperty(n)){const o=new RegExp(`POTD_${n}`,"g");e=e.replace(o,t[n])}return e}function setupMobileMenu(){const e=templateConfiguration.mobileMenuType;switch(console.info(`Selected mobile menu type: ${e}`),e){case"horizontal":appendSwipeableMobileMenu(),$(".fa-align-justify").off(),$(".fa-align-justify").on("click",(function(e){e.preventDefault(),$(".swipeable-mobile-menu").toggle(),"none"===$(".swipeable-mobile-menu").css("display")?$(".mobile-items-background").hide():$(".mobile-items-background").show()}));break;case"vertical":break;default:console.warn(`Invalid mobile menu type variant: "${e}". The variant was not applied.`)}}function appendSwipeableMobileMenu(){var e=document.createElement("div");e.classList.add("swipeable-mobile-menu"),e.appendChild(createHTMLTree(frontAPI.getCategories(),0,templateConfiguration.translation.backToShop,templateConfiguration.translation.mobileMenuTitle,"")),document.body.appendChild(e);let t=0;const n=$(".swipeable-mobile-menu");$(".mobile-menu-back").on("click",(function(e){if(0===t){n.hide(),$(".mobile-items-background").hide();return void(document.querySelector("html").style.cssText="overflow-y: scroll !important;")}t--;const o=$(this).parent(),i=$(this).parent().parent().parent();n.css("transform",`translateX(${100*-t}%)`),o.css("display","none"),i.css("overflow","scroll")})),$(".mobile-menu-item").on("click",(function(e){if(e.clientX-$(this).offset().left>=$(this).width()-30&&$(this).siblings().length>0){t++,e.preventDefault();const o=$(this).parent().find(">ul"),i=$(this).parent().parent();o.css("display","block"),i.css("overflow","visible"),n.css("transform",`translateX(${100*-t}%)`)}}))}function createHTMLTree(e,t,n,o,i){var s=document.createElement("ul");s.classList.add(`mobile-level-${t}`);var a=document.createElement("a");a.classList="title-menu",a.href=i,a.textContent=o;var c=document.createElement("button");return c.classList="mobile-menu-back",c.textContent=n,s.appendChild(c),s.appendChild(a),e.forEach((e=>{var n=document.createElement("li"),i=document.createElement("a");if(i.href=`/pl/c/${e.name}/${e.id}`,i.textContent=e.name,i.classList="mobile-menu-item",n.appendChild(i),e.children.length>0){var a=createHTMLTree(e.children,t+1,o,e.name,`/pl/c/${e.name}/${e.id}`);n.appendChild(a)}s.appendChild(n)})),0==t&&"undefined"!=typeof customMobileMenuItems&&customMobileMenuItems.forEach((e=>{var t=document.createElement("li"),n=document.createElement("a");n.href=e.url,n.textContent=e.name,n.classList="mobile-menu-item",t.appendChild(n),s.appendChild(t)})),s}function setupExtraMessages(){let e=0;$(".next-message").on("click",(function(){e=(e+1)%$(".extra-message").length,$(".extra-message").css("display","none").eq(e).css("display","block")})),$(".prev-message").on("click",(function(){e=(e-1+$(".extra-message").length)%$(".extra-message").length,$(".extra-message").css("display","none").eq(e).css("display","block")})),setInterval((function(){e=(e+1)%$(".extra-message").length,$(".extra-message").css("display","none").eq(e).css("display","block")}),templateConfiguration.extraMessageAutoChangeAfter)}function setupSEOs(){setupSEO("#box-seo"),setupSEO(".shop_product_list .categorydesc.bottom")}function setupSEO(e){const t=$(".seo-invisible"),n=$(e);if(!t.length||!n.length)return;const o=$("<button>").attr("id","expand-button").text(templateConfiguration.translation.expandSEO).click((function(){o.hide(),i.show(),t.show()})),i=$("<button>").attr("id","collapse-button").text(templateConfiguration.translation.collapseSEO).click((function(){i.hide(),o.show(),t.hide()}));t.first().before(o),n.append(i)}function setupItemCountModifiers(){setupItemCountModifier(".quantity input"),setupItemCountModifier(".quantity_wrap input")}function setupItemCountModifier(e){const t=Array.from(document.querySelectorAll(e)),n=Array.from(document.querySelectorAll(".more-item")),o=Array.from(document.querySelectorAll(".less-item"));n.forEach(((e,n)=>{e.addEventListener("click",(()=>function(e){try{const t=Number(e.value);e.value=t+1;const n=new Event("change",{bubbles:!0});e.dispatchEvent(n)}catch(e){}}(t[n])))})),o.forEach(((e,n)=>{e.addEventListener("click",(()=>function(e){try{const t=Number(e.value);if(t>1){e.value=t-1;const n=new Event("change",{bubbles:!0});e.dispatchEvent(n)}}catch(e){}}(t[n])))}))}function setupSiteCartActionListeners(){const e=$(".basket-site-cart").get(0),t=$(".menu-background").get(0),n=$(".menu").get(0),o=$(".basket.right").get(0);if(!e||"site-cart"!=templateConfiguration.cartType)return;const i=window.getComputedStyle(e).getPropertyValue("right");$(e).on("mouseleave click",(function(){e.style.right=i,t.style.opacity=0,t.style.height=0,n.style.zIndex=24})),$(o).on("click",(function(o){o.preventDefault(),e.style.right=0,t.style.opacity=1,t.style.height="100%",n.style.zIndex=0}))}function setupViewSelectHandlers(){const e="select-tablet-active",t=document.querySelectorAll(".select-tablet");$(t).on("click",(function(){const n=this.getAttribute("select-id");t.forEach((function(t){t.classList.remove(e)})),this.classList.add(e),$("#"+n).prop("selectedIndex",$(this).index()+1)}))}function setupProductInfoPager(){const e="active-menu-item",t=document.querySelector(".product-additional-items-menu");if(!t)return;t.children[0].classList.add(e),Array.from(t.children).forEach((t=>{t.addEventListener("click",(function(){document.querySelectorAll("."+e).forEach((t=>{t.classList.remove(e)})),t.classList.add(e),Array.from(t.classList).forEach((e=>{switch(e){case"description-btn":document.querySelectorAll(".product-modules > div").forEach((e=>{e.style.cssText="display: none !important"})),document.querySelector("#box_description").style.cssText="display: block !important";break;case"shipping-btn":document.querySelectorAll(".product-modules > div").forEach((e=>{e.style.cssText="display: none !important"})),document.querySelector("#box_productdeliveries").style.cssText="display: block !important";break;case"attributes-btn":document.querySelectorAll(".product-modules > div").forEach((e=>{e.style.cssText="display: none !important"})),document.querySelector("#box_productdata").style.cssText="display: block !important";break;case"bundle-btn":document.querySelectorAll(".product-modules > div").forEach((e=>{e.style.cssText="display: none !important"})),document.querySelector("#box_bundle").style.cssText="display: block !important";break;case"comments-btn":const e=void 0!==templateConfiguration.commentsContainerId?templateConfiguration.commentsContainerId:"#box_productcomments";document.querySelectorAll(".product-modules > div").forEach((e=>{e.style.cssText="display: none !important"})),document.querySelector(e).style.cssText="display: block !important"}}))}))}))}function setupProductMainImage(){const e=$("#box_productfull")[0];if(!e)return;const t=Array.from(e.classList);t.includes("horizontal-miniatures")?setupCarouselProductPageHandler(4,4):t.includes("carousel")?setupCarouselProductPageHandler(1,1):setupCarouselProductPageHandler(2,3)}function setupCarouselProductPageHandler(e,t){const n=$(".prev-image")[0],o=$(".next-image")[0],i=$(".smallgallery a");let s=0;if(n&&o){if(i.length<=e)return n.style.display="none",void(o.style.display="none");$(n).on("click",(()=>{const n=window.innerWidth<980?t:e;s=Math.max(s-1,0),showLinks(i,s,n)})),$(o).on("click",(()=>{const n=window.innerWidth<980?t:e;s+n<=i.length-1&&s++,showLinks(i,s,n)}))}}function showLinks(e,t,n){e.each((function(e,o){e>=t&&e<t+n?$(o).css("display","inline"):$(o).css("display","none")}))}function changePhotoOnHover(){$(".smallgallery a img").on("mouseenter",(function(){$(".smallgallery a").removeClass("current"),$(this).parent().addClass("current");$(".mainimg .photo").attr("src",this.src)}))}function setupMenuExpander(){const e=$('[class^="level_"]>li:has(.current)>a, li:has(.current) >a, li.current:has(ul)>a');e.length&&e.on("click",(function(e){const t=$(this).next();if(!t.length)return;if(e.clientX-$(this).offset().left>=$(this).outerWidth()-24){e.preventDefault();"none"===t.css("display")?($(this).removeClass("collapsed"),t.css("display","block")):($(this).addClass("collapsed"),t.css("display","none"))}}))}function setIconsOnChildfulMenuItems(){const e=frontAPI.getCategoryList({lang:templateConfiguration.lang,urlParams:"?limit=50"});for(let t=1;t<=e.pages;t++){const e=frontAPI.getCategoryList({lang:templateConfiguration.lang,urlParams:"?limit=50&page="+t});$.each(e.list,(function(e,t){if(t.has_children){const e=$(`#category_${t.category_id} > a`);e.length&&e.addClass("expandable")}}))}}var isSearchOpened=!1;function handleSearchOnMobile(){const e=$(".open-search"),t=$(".search__container"),n=$(".contact-header-container");let o=!1;e.on("click",(()=>{o?(t.css("display","none"),n.css("display","flex")):(t.css("display","block"),n.css("display","none")),o=!o}))}function handleLogoutOnClick(){$(".logout-button").on("click",(()=>{frontAPI.logout(),window.location.reload()}))}function handleMobileMenu(){const e=document.querySelector(".footer-menu-contact"),t=document.querySelector(".footer-menu-search"),n=document.querySelector(".footer-menu-account"),o=document.querySelector(".footer-menu-basket"),i=document.querySelector(".mobile-menu-items"),s=document.querySelector(".mobile-menu-items > button"),a=document.querySelectorAll(".mobile-menu-items >div");s.addEventListener("click",(()=>{i.style.display="none";document.querySelector(".search__container").style.display="none",$(".mobile-items-background").hide();document.querySelector("html").style.cssText="overflow-y: scroll !important;",$(".search__container").hide()})),$(".basket-site-cart button").on("click",(function(){if(window.innerWidth>1300)return void $(".basket-site-cart").get(0).trigger("mouseleave");i.style.display="none";document.querySelector(".basket-site-cart").style.cssText="display: none !important;",$(".mobile-items-background").hide();document.querySelector("html").style.cssText="overflow-y: scroll !important;",$(".search__container").hide()})),e.addEventListener("click",(()=>onMobileItemClicked(i,a,".mobile-menu-contact",!1,!1))),t.addEventListener("click",(()=>{onMobileItemClicked(i,a,".mobile-menu-search",!0,!1),$(".search__container").show()})),n.addEventListener("click",(()=>onMobileItemClicked(i,a,".mobile-menu-profile",!1,!1))),o.addEventListener("click",(()=>onMobileItemClicked(i,a,".mobile-menu-basket",!1,!0)))}function onMobileItemClicked(e,t,n,o,i){$(".search__container").hide(),$(".mobile-items-background").show();document.querySelector("html").style.cssText="overflow-y: hidden !important;",$(".swipeable-mobile-menu").hide(),$("#box_filter").hide(),e.style.display="block",Array.from(t).forEach((e=>{e.style.display="none"})),document.querySelector(n).style.display="flex";document.querySelector(".search__container").style.display=o?"block":"none";document.querySelector(".basket-site-cart").style.cssText=i?"display: block !important;":"display: none !important;"}function handleBackgroundOnMobileMenuClick(){const e=document.querySelector(".fa-align-justify"),t=document.querySelector(".mobile-menu-items"),n=document.querySelector("#box_filter"),o=document.querySelector("html");e.addEventListener("click",(function(){const e="block"===window.getComputedStyle(t).display;n&&(document.querySelector("#box_filter").style.display="none"),e?(document.querySelector(".search__container").style.display="none",document.querySelector(".basket-site-cart").style.cssText="display: none !important;",t.style.display="none",o.style.overflowY="scroll"):o.style.overflowY="hidden"}))}function handleProductContainerPosition(){if(0==$(".shop_product").length||1==$(".with-tabs").length)return;let e=!1;const t=$(".product-container"),n=$(".product-additional-items-menu"),o=n.length>0?n:$(".product-modules"),i=t.parent();function s(){innerWidth<980&&!e?(e=!0,t.insertBefore(o)):innerWidth>=980&&e&&(e=!1,t.appendTo(i))}s(),window.onresize=function(e){s()}}function handleMobileFilterButton(){const e=$(".mobile-filter-button"),t=$(".mobile-filter-menu-back"),n=$(".mobile-items-background");0!=$(".shop_product_list").length&&(document.body.addEventListener("scroll",(()=>{const t=document.body.scrollTop;e.toggleClass("anchored",t>100)})),document.body.addEventListener("touchmove",(()=>{const t=document.body.scrollTop();e.toggleClass("anchored",t>100)})),e.on("click",(()=>{n.toggle(),$("#box_filter").toggle();const e=document.querySelector("html"),t=document.querySelector(".leftcol"),o=document.querySelector(".leftcol #box_filter");"block"==n.css("display")?(e.style.cssText="overflow-y: hidden !important;",o&&(t.style.cssText="display: block !important;")):(e.style.cssText="overflow-y: scroll !important;",o&&(t.style.cssText="display: none !important;"))})),t.on("click",(()=>{n.toggle(),$("#box_filter").toggle();const e=document.querySelector("html"),t=document.querySelector(".leftcol"),o=document.querySelector(".leftcol #box_filter");"block"==n.css("display")?(e.style.cssText="overflow-y: hidden !important;",o&&(t.style.cssText="display: block !important;")):(e.style.cssText="overflow-y: scroll !important;",o&&(t.style.cssText="display: none !important;"))})))}function initProductHover(){templateConfiguration.hoverableProduct&&($(".product-inner-wrapper .boximgsize img").each((function(){const e=$("<div class='hoverable-product-wrapper'></div>");$(this).parent().append(e)})),$(".product-inner-wrapper .boximgsize").on("mouseenter",(function(){const e=$(this).find(">div");if(0===e.children().length){const t=parseInt($(this).parent().parent().parent().attr("data-product-id"));if(!isNaN(t)){const n=frontAPI.getProduct({id:t}),o=$("<section></section>").attr("id",`hoverable-product-${t}`);n.options_configuration.forEach((e=>{const t=e.values;if(t.length>0){const n=$("<div class='hoverable-product-attr-"+e.id+"'></div>").addClass("option"),i=$("<h3></h3>").text(e.name+":");n.append(i),t.forEach((e=>{const t=$("<p class='hoverable-value-"+e.id+"'></p>").text(e.name);t.on("click",(function(e){e.preventDefault(),e.stopPropagation(),$(this).siblings().removeClass("selected"),$(this).toggleClass("selected")})),n.append(t)})),o.append(n)}})),e.append(o)}}e.show()})),$(".product-inner-wrapper .boximgsize").on("mouseleave",(function(){$(this).find(">div").hide()})))}function appendProductCountOnFooterMenu(){const e=templateConfiguration.maxCountVisible,t=frontAPI.getBasketInfo({}).products.reduce(((e,t)=>e+t.quantity),0),n=t>e?e+"+":t.toString();t>0&&($(".counts-product-footer").text(n),$(".counts-product-footer").show())}function createProductElement(e){const t=document.createElement("div");return t.className="product product-item row center",t.innerHTML=`\n <div class="product-inner-wrapper">\n <a href="${e.url}" title="${e.name}" class="row">\n <span class="boximgsize row">\n <img src="/environment/cache/images/300_300_productGfx_${e.main_image}/Mask-Group-25.png" data-src="/environment/cache/images/300_300_productGfx_${e.main_image}/Mask-Group-25.png">\n <noscript>\n <img src="/environment/cache/images/300_300_productGfx_${e.main_image}/Mask-Group-25.png" alt="${e.name}">\n </noscript>\n </span>\n <div class="manufacturer row">\n <span>${e.producer.name}</span>\n </div>\n <div class="productnamewrap row">\n <span class="productname">${e.name}</span>\n </div>\n </a>\n <div class="price price_extended row">\n <section>\n <p>\n <em>${e.price.gross.base}</em>\n </p>\n </section>\n <span class="hide price-netto">\n <p>\n <em>${e.price.net.base}</em>\n </p>\n </span>\n </div>\n <a href="${window.location.href}pl/fav/add/${e.stockId}">\n <img class="add-to-fav" src="${templateConfiguration.templatePath}/images/user/add-to-fav.svg">\n </a>\n <form class="basket basket-box " action="/pl/basket/add/post" method="post">\n <fieldset>\n <div class="shaded_inputwrap"><input name="quantity" value="1" type="text" class="short center"></div>\n <span class="unit">szt.</span>\n <input type="hidden" value="${e.stockId}" name="stock_id">\n <button class="addtobasket btn btn-red" type="submit">\n <img src="/libraries/images/1px.gif" alt="" class="px1">\n </button>\n </fieldset>\n </form>\n </div>\n </div>\n`,t}function renderProducts(){const e=document.querySelectorAll(".productoftheday_menu .slider-content"),t=frontAPI.getPotdProducts().list;e.forEach((e=>{t.forEach((t=>{const n=createProductElement(t);e.append(n)}))}))}function handleMobileItemsBackgroundClick(){$(".mobile-items-background").on("click",(function(){$(".swipeable-mobile-menu").hide(),$(".mobile-menu-items").hide(),$("#box_filter").hide(),$(this).hide();document.querySelector(".search__container").style.display="none";document.querySelector(".basket-site-cart").style.cssText="display: none !important;",$(".search__container").hide()}))}function setupPaymentIcons(){$(".shop_basket")&&templateConfiguration.paymentsConfiguration.forEach((e=>{const t=$(`#${e.name}`).parent().next();t.css("background-image",`url(${e.url})`),t.css("padding-left","48px")}))}function setupShippingIcons(){$(".shop_basket")&&templateConfiguration.shippingsConfiguration.forEach((e=>{const t=$(`#${e.name}`).parent().next();t.css("background-image",`url(${e.url})`),t.css("padding-left","48px")}))}function observeProductChanges(){document.querySelectorAll(".right.basket").forEach((e=>{new MutationObserver(observeProduct).observe(e,{attributes:!0,childList:!0,subtree:!0})}))}function observeProduct(e,t){e.forEach((e=>{$(".ajax-product-block .btn.left").click((()=>window.location.reload()))}))}function handleAddOpinionOnTabs(){$(".comment a").click((function(e){$(".with-tabs")&&(e.preventDefault(),$(".comments-btn").trigger("click"),$("body").animate({scrollTop:$(".comments-btn").position().top}))}))}function handleHideMenuOnBackgroundMousenter(){$(".menu-background").on("mouseenter",(function(){const e=$(this);e.addClass("menu-background-hidden"),setTimeout((()=>{e.removeClass("menu-background-hidden")}),400)}))}function handleVerticalMenu(){handleBehaviourVerticalMenu(),$(window).on("resize",handleBehaviourVerticalMenu)}function handleBehaviourVerticalMenu(){window.innerWidth<=1030?($(".group-filter > h5").next().hide(),$(".group-filter > h5").on("click",(function(){$(this).next().toggle(),$(this).hasClass("expanded")?$(this).removeClass("expanded"):$(this).addClass("expanded")}))):($(".group-filter > h5").off("click"),$(".group-filter > h5").next().show())}function onProductNameClicked(){$(".product-inner-wrapper .productnamewrap").click((function(){window.location=$(this).parent().find(">a:first-of-type").attr("href")}))}const createButton=(e,t,n)=>$("<button>",{class:e,text:t,click:n});