if (_smid === '6573mzei81pb4cp6') { (function () { // GLOBALS START class Popup { constructor(height, width, urlFrame, closeBtnMessage = null, closeButton = false) { this.height = height; this.width = width; this.urlFrame = urlFrame; this.closeBtnMessage = closeBtnMessage; this.closeButton = closeButton; this.background = document.createElement('div'); this.popupBox = document.createElement('div'); this.iframeHTML = document.createElement('iframe'); this.styleCSS = document.createElement('style'); this.createStyleInHead(); } createStyleInHead() { document.head.appendChild(this.styleCSS); } actualizationStyleInHead(newStyle) { const actuallStyle = this.styleCSS.textContent; this.styleCSS.textContent = ''; this.styleCSS.textContent = actuallStyle + newStyle; } createPopup(delay = 2000, delayClose = 300, closeBackground = true) { this.background.style.cssText = 'position: fixed;width: 100%;height: 100vh;top: 0;left: 0;z-index: 99999;background-color: rgba(0, 0, 0, 0.400);overflow: hidden;display: flex;justify-content: center;align-items: center;' + this.background.style.cssText; this.background.addEventListener('click', (e) => { if (closeBackground === true) { this.destroyPopup(delayClose); } }); this.popupBox.style.height = this.height + 'px'; this.popupBox.style.maxWidth = this.width + 'px'; this.popupBox.style.cssText = 'width: 95%;position: relative;' + this.popupBox.style.cssText; this.iframeHTML.src = this.urlFrame; this.iframeHTML.style.cssText = 'height: 100%;width: 100%;border: none;overflow: hidden;' + this.iframeHTML.style.cssText; setTimeout(() => { document.body.appendChild(this.background); this.background.appendChild(this.popupBox); this.popupBox.appendChild(this.iframeHTML); }, delay); if (this.closeButton) { const clsButton = document.createElement('img'); clsButton.id = 'salesmanagoCloseButton'; clsButton.style.cssText = ' width: 24px;height: 24px;position: absolute;top: -12px;right: -12px;cursor: pointer;'; clsButton.src = 'https://s3-eu-west-1.amazonaws.com/salesmanagoimg/h4jsu6pc5txybj04/0zpqad8fbblhvnkt/1gewbaz3vklvnxr5.png'; this.popupBox.appendChild(clsButton); } else { window.addEventListener('message', (e) => { if (typeof e.data !== 'object' && e.data === this.closeBtnMessage) { this.destroyPopup(delayClose); } }); } } destroyPopup = (delayClose = 300) => { this.actualizationStyleInHead( `.sm-custom-delete {animation: sm-custom-delete ` + delayClose / 1000 + `s both !important;} @keyframes sm-custom-delete {0% {opacity: 1;}100% {opacity: 0;}};` ); this.background.classList.add('sm-custom-delete'); setTimeout(() => { this.background.remove(); }, parseInt(delayClose)); }; dynamicHeight(message) { window.addEventListener('message', (e) => { if (typeof e.data === 'object' && e.data.name === message) { if (this.popupBox) { this.popupBox.style.height = e.data.value + 'px'; } } }); } createCustomCloseBtn = (height, width, url, top, right) => { const clsButton = document.createElement('img'); clsButton.id = 'salesmanagoCloseButton'; clsButton.style.cssText = 'width: ' + width + 'px;height: ' + height + 'px;position: absolute;top: ' + top + 'px;right: ' + right + 'px;cursor: pointer;'; clsButton.src = url; this.popupBox.appendChild(clsButton); }; styleEdit(element, styleText) { switch (element) { case 'background': this.background.style.cssText = styleText; break; case 'popupBox': this.popupBox.style.cssText = styleText; break; case 'iframeHTML': this.iframeHTML.style.cssText = styleText; break; default: console.log('Wrong element'); break; } } defaultAnimation(element, animation, time, delay) { if (element === this.background || element === this.popupBox || element === this.iframeHTML) { switch (animation) { case 'sm-custom-display': this.actualizationStyleInHead( `.sm-custom-display {-webkit-animation: sm-custom-display ` + time + `s ` + delay + `s both;animation: sm-custom-display ` + time + `s ` + delay + `s both;} @-webkit-keyframes sm-custom-display {0% {opacity: 0%}100% {opacity: 100%}}@keyframes sm-custom-display {0% {opacity: 0%}100% {opacity: 100%}}` ); element.classList.add(animation); break; case 'sm-custom-scale-up': this.actualizationStyleInHead( `.sm-custom-scale-up {-webkit-animation: sm-custom-scale-up ` + time + `s ` + delay + `s both;animation: sm-custom-scale-up ` + time + `s ` + delay + `s both;} @-webkit-keyframes sm-custom-scale-up {0% {-webkit-transform: scale(0.4);transform: scale(0.4); opacity: 0%}100% {-webkit-transform: scale(1);transform: scale(1);opacity: 100%}}@keyframes sm-custom-scale-up {0% {-webkit-transform: scale(0.4);transform: scale(0.4);opacity: 0%}100% {-webkit-transform: scale(1);transform: scale(1);opacity: 100%}}` ); element.classList.add(animation); break; default: console.log('Wrong animation name'); break; } } else { console.log('Wrong element'); } } customAnimation(element, className, cssText) { if (element === this.background || element === this.popupBox || element === this.iframeHTML) { this.actualizationStyleInHead(cssText); element.classList.add(className); } else { console.log('Wrong element'); } } } function getCookie(cname) { const name = cname + '='; const cookieList = document.cookie.split(';'); for (const cookie of cookieList) { const cookieTrimed = cookie.trim(); if (cookieTrimed.startsWith(name)) return cookieTrimed.substring(name.length); } return ''; } function setCookieHours(cname, cvalue, exh) { const d = new Date(); d.setTime(d.getTime() + exh * 60 * 60 * 1000); const expires = 'expires=' + d.toUTCString(); document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; } // GLOBALS END (function (w) { const endpoint = 'https://i-vtex.salesmanago.com/api/salesmanago/6/front/'; const $ = w.$ || w.jQuery; const vtex = {}; const sm = {}; let eventTimeout; let bhrBasket = { cart: {}, email: '', firstName: '', lastName: '', contactId: '', eventId: null, subscriber: false, }; try { if (!w.SalesmanagoObject && !$) throw new Error('Front api not ready'); vtex.getProfileUser = function () { if (!bhrBasket.email || !bhrBasket.contactId) { if (w.smReadCookie('smclient')) { bhrBasket.contactId = w.smReadCookie('smclient'); sm.saveBasketInStorage(); } else { $.ajax({ url: '/no-cache/profileSystem/getProfile', success(user) { if (user.IsUserDefined) { bhrBasket.email = user.Email; bhrBasket.firstName = user.FirstName ? user.FirstName : ''; bhrBasket.lastName = user.LastName ? user.LastName : ''; sm.saveBasketInStorage(); sm.getUserContactId(user.Email); } }, }); } } }; vtex.fetchShopBasket = function () { $.ajax({ url: '/api/checkout/pub/orderForm', success(order) { sm.addOrderToBasket(order); }, }); }; vtex.watchValid = function (xhr, settings) { return ( xhr.responseText !== undefined && settings !== undefined && (settings.url.indexOf('/api/checkout/pub/orderForm') !== -1 || settings.url.split('/').pop() === 'orderForm' || settings.url.split('/').pop() === 'paymentData') ); }; vtex.watchAddToCart = function () { $(document).ajaxComplete(function (event, xhr, settings) { if (vtex.watchValid(xhr, settings)) { sm.addOrderToBasket(JSON.parse(xhr.responseText)); if (sm.checkExistUser()) { clearTimeout(eventTimeout); eventTimeout = setTimeout(sm.sendCartEvent, 750); } } }); }; vtex.orderAction = function () { if (w.location.pathname.indexOf('/checkout/orderPlaced') !== -1) { if (sm.checkExistUser()) { clearTimeout(eventTimeout); eventTimeout = setTimeout(function () { sm.sendCartEvent(false); sm.clearBasket(); }, 750); } return false; } return true; }; sm.addOrderToBasket = function (order) { const items = order.items.reduce( function (i, e) { i.products.push(e.productId); i.description.push(e.name); i.sku.push(e.id); i.quantity.push(e.quantity); i.detail.push(e.additionalInfo.brandName); return i; }, { products: [], description: [], sku: [], quantity: [], detail: [], } ); bhrBasket.cart = { products: items.products.join(','), description: items.description.join(','), detail1: items.description.join(','), detail2: items.detail.join(','), detail3: items.sku.join(','), detail4: items.quantity.join(','), detail5: order.storePreferencesData.currencyCode, value: order.value / 100, externalId: order.orderFormId, }; if (order.clientPreferencesData && order.clientPreferencesData.optinNewsLetter !== null) { bhrBasket.subscriber = order.clientPreferencesData.optinNewsLetter; } if (order.clientProfileData && order.clientProfileData.email !== null) { bhrBasket.email = order.clientProfileData.email; bhrBasket.firstName = order.clientProfileData.firstName; bhrBasket.lastName = order.clientProfileData.lastName; } sm.saveBasketInStorage(); }; sm.saveBasketInStorage = function () { localStorage.setItem('bhrBasket', JSON.stringify(bhrBasket)); }; sm.fetchStorageBasket = function () { const basket = localStorage.getItem('bhrBasket'); if (basket) { bhrBasket = JSON.parse(basket); } }; sm.clearBasket = function () { bhrBasket.eventId = null; bhrBasket.cart = {}; sm.saveBasketInStorage(); }; sm.sendCartEvent = function (save = true) { try { if (bhrBasket.cart.value > 0) { bhrBasket.cart.date = new Date().getTime(); $.ajax({ url: endpoint + 'basket', contentType: 'application/json', type: 'post', data: JSON.stringify(bhrBasket), dataType: 'json', success(data) { if (save && bhrBasket.eventId !== data.eventId && data.success) { bhrBasket.eventId = data.eventId; sm.saveBasketInStorage(); } }, }); } } catch (e) { } }; sm.getUserContactId = function (email) { $.ajax({ url: endpoint + 'contact', contentType: 'application/json', type: 'post', data: JSON.stringify({ email, clientId: w._smid }), dataType: 'json', success(data) { w.smCreateCookie('smclient', data.contactId, 30); bhrBasket.contactId = data.contactId; sm.saveBasketInStorage(); }, }); }; sm.checkExistUser = function () { if (bhrBasket.email || bhrBasket.contactId) { return true; } if (w.smReadCookie('smclient')) { bhrBasket.contactId = w.smReadCookie('smclient'); sm.saveBasketInStorage(); return true; } return false; }; sm.init = function () { sm.fetchStorageBasket(); if (vtex.orderAction()) { vtex.getProfileUser(); vtex.fetchShopBasket(); vtex.watchAddToCart(); } }; sm.init(); } catch (e) { } })(window); (function () { const build = (url) => { width = window.innerWidth > 816 ? 740 : 350; height = window.innerWidth > 816 ? 384 : 450; const div = document.createElement('div'); div.style.width = width + 'px'; div.style.height = height + 'px'; div.style.position = 'fixed'; div.style.transition = '1s'; div.style.marginLeft = '20px'; div.style.zIndex = '9999999'; div.style.backgroundColor = 'white'; const hoverable = document.createElement('img'); // DESKTOP here change image with arrow - show button hoverable.src = 'https://sm-cdn.eu/cmqlcdamf9feejdz.jpg'; hoverable.style.width = '40px'; hoverable.style.height = height + 'px'; hoverable.style.position = 'absolute'; hoverable.style.left = '-40px'; hoverable.style.transformOrigin = '0 0'; if (window.innerWidth > 816) { hoverable.style.top = '0px'; } else if (window.innerWidth < 816) { hoverable.style.top = '-110px'; hoverable.style.left = '0px'; // MOBILE here change image with arrow - show button hoverable.src = 'https://storage.googleapis.com/s-img/1vjtcvd0moxsxijx.jpg'; hoverable.style.width = '350px'; hoverable.style.height = '35px'; } div.appendChild(hoverable); const iframe = document.createElement('iframe'); iframe.src = url; iframe.style.border = 'none'; iframe.style.width = width + 'px'; iframe.style.height = height + 'px'; iframe.style.transition = '0.5s'; div.appendChild(iframe); if (window.innerWidth > 816) { div.style.bottom = '22%'; } else { div.style.bottom = '-450px'; div.style.left = '45%'; div.style.transform = 'translateX(-50%)'; } div.style.right = '-' + width + 'px'; document.body.appendChild(div); document.body.style.overflowX = 'hidden'; hoverable.addEventListener('click', function () { if (window.innerWidth > 816) { if (div.style.right != '0px') { div.style.right = '0px'; iframe.style.boxShadow = '-7px 0px 12px 5px rgba(0,0,0,0.25)'; // DESKTOP here change image with x - close button hoverable.src = 'https://sm-cdn.eu/cmqlcdamf9feejdz.jpg'; } else { div.style.right = '-' + width + 'px'; iframe.style.boxShadow = ''; // DESKTOP here change image with arrow - show button hoverable.src = 'https://sm-cdn.eu/cmqlcdamf9feejdz.jpg'; } } else if (div.style.bottom != '0px') { div.style.bottom = '0px'; hoverable.style.top = '-35px'; iframe.style.boxShadow = '-7px 0px 12px 5px rgba(0,0,0,0.25)'; // MOBILE here change image with x - close button hoverable.src = ' https://storage.googleapis.com/s-img/1vjtcvd0moxsxijx.jpg'; } else { div.style.bottom = '-450px'; iframe.style.boxShadow = ''; hoverable.style.top = '-110px'; // MOBILE here change image with arrow - show button hoverable.src = 'https://storage.googleapis.com/s-img/1vjtcvd0moxsxijx.jpg'; } }); }; if (window.innerWidth > 816) { build('https://app3.salesmanago.pl/ms/6573mzei81pb4cp6/default/sidebar_desktop_v02.htm'); } })(); // ADDING FRAMES START (function () { let cartProdUrl; setTimeout(function () { if (document.querySelector('.product-image')) { cartProdUrl = document.querySelector('.product-image').children[0].href; } const iframeArray = [ // TS-39986 - test { container: document.getElementById('ReferenceTagCheckout01'), url: 'https://app3.salesmanago.pl/ms/6573mzei81pb4cp6/default/FRAME_BESTSELLER_PRD.htm?prodUrl=' + cartProdUrl, message: 'sm_dynamic_height_39986', test: false, action: 'checkIfShouldDisplay', }, ]; function createIframe(src, container, id) { const sp = document.createElement('iframe'); sp.className = 'recommendation_salesmanago'; sp.id = id; sp.loading = 'lazy'; sp.src = src; window.addEventListener('message', function (e) { if (typeof e.data === 'object' && e.data.name !== undefined) { iframeArray.forEach((iframe) => { if (e.data.name === iframe.message && iframe.container) { sp.style.height = e.data.value + 'px'; } }); } }); sp.style.height = '100%'; if (window.innerWidth > 690) { sp.style.width = '100%'; } else if (window.innerWidth <= 690) { sp.style.width = 'calc(100% - 20px)'; } sp.style.maxWidth = '980px'; if (window.innerWidth > 690) { sp.style.margin = '0 20px'; } else if (window.innerWidth <= 690) { sp.style.margin = '0 10px'; } sp.scrolling = 'no'; sp.style.border = 'none'; sp.style.position = 'relative'; container.appendChild(sp); } if (iframeArray !== 0) { const checkIfShouldDisplay = async (src, action) => { const ifShouldDisplay = src + '&action=' + action; const responde = await fetch(ifShouldDisplay) .then((response) => response.text()) .then((data) => { if (data.includes('true')) { return true; } return false; }); return responde; }; window.addEventListener('message', function (e) { if (typeof e.data === 'object' && e.data.name !== undefined) { iframeArray.forEach((iframe) => { if (e.data.name === iframe.message && iframe.container) { iframe.container.style.height = e.data.value + 'px'; } }); } }); iframeArray.forEach((iframe) => { let shouldDisplay; if (iframe.action !== undefined) { if (checkIfShouldDisplay(iframe.url, iframe.action)) { shouldDisplay = true; } else { shouldDisplay = false; } } if (iframe.container && iframe.test === false && shouldDisplay) { iframe.container.style.height = '0'; createIframe(iframe.url, iframe.container, 'ramka_produktowa'); } else if ( iframe.container && iframe.test === true && window.location.href.includes('test=true') && (shouldDisplay || shouldDisplay === undefined) ) { iframe.container.style.height = '0'; createIframe(iframe.url, iframe.container, 'ramka_produktowa'); } }); } }, 1000); })(); // ADDING FRAMES END // TS-40161 start (function () { if (window.location.pathname === '/') { (async function () { const getClientId = getCookie('smclient'); const getUuid = getCookie('smuuid'); let urlParams = ''; if (getClientId && getUuid) { urlParams = '?contactId=' + getClientId + '&uuid=' + getUuid; } else if (getUuid) { urlParams = '?uuid=' + getUuid; } else { urlParams = '?contactId=' + getClientId; } const date = new Date(); const dateNow = date.getTime(); function setPopupData(cookieValue) { function changeVisitData() { this.currentVisit = dateNow + 10800000; this.visit3hour += 1; } return { currentVisit: cookieValue.currentVisit || dateNow, visit3hour: cookieValue.visit3hour || 0, changeVisitData, }; } let isOpen = false; function createPopup() { if (!isOpen) { const popupTS38258 = new Popup( 600, 600, 'https://app3.salesmanago.pl/ms/6573mzei81pb4cp6/default/POP_UP_CON_RECOMENDACION.htm' + urlParams, null, true ); popupTS38258.createPopup(0); popupTS38258.dynamicHeight('dynamic_height_sm_recomendation_frame_TS-40161'); isOpen = true; } } function checkDidMobileDevice() { const toMatch = [/Android/i, /webOS/i, /iPhone/i, /iPod/i, /BlackBerry/i, /Windows Phone/i]; return toMatch.some((toMatchItem) => navigator.userAgent.match(toMatchItem)) || window.innerWidth < 860; } const checkIfShouldDisplay = async (src, action) => { const response = await fetch(src + urlParams + `&action=` + action).then((res) => res.text()); return response.includes('true'); }; async function checkDidRenderPopup(dataObject) { dataObject.changeVisitData(); const shouldRunPopup = dataObject.visit3hour % 3 === 0; const src = 'https://app3.salesmanago.pl/ms/6573mzei81pb4cp6/default/POP_UP_CON_RECOMENDACION.htm'; const shouldDisplay = await checkIfShouldDisplay(src, 'checkIfShouldDisplay'); if (shouldRunPopup && shouldDisplay) { if (checkDidMobileDevice()) { createPopup(); } else { document.body.addEventListener('mouseleave', createPopup); window.history.pushState({ id: 1 }, null, null); window.onpopstate = () => setTimeout(createPopup, 0); } } localStorage.setItem('_sm_TS38258_cookie', JSON.stringify(dataObject), 9999); } async function renderPopup() { let cookieData = {}; const popupCookie = localStorage.getItem('_sm_TS38258_cookie'); if (popupCookie) { cookieData = JSON.parse(popupCookie); } const popupData = setPopupData(cookieData); if (popupData.currentVisit <= dateNow) checkDidRenderPopup(popupData); } renderPopup(); })(); } })(); // TS-40161 end })(); }