(async function () { let shop = JSON.parse('{"_id":"66e9ece7a35e6f011ed87d85","origin":"45e972.myshopify.com","customTheme":{"productList":{"classControl":"notrequired","pathToPrice":"notrequired","pathToOnSalePrice":"notrequired"},"productDetail":{"classControl":"div.page-width","pathToPrice":"div.product-block.product-block--price > span.product__price , div.product-block.product-block--price > span.product__price.on-sale","after":"div.product-block.product-block--price"},"cart":{"classControl":"notrequired","pathToPrice":"notrequired","after":"notrequired"}},"theme":"Custom"}'); let flexitiAppServerUrl = 'https://ecomm-monthly-payment-widget.flexiti.com'; let themesConfig = JSON.parse('[{"theme_store_id":null,"name":"Tempest","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":"#product-loop","loopOn":".price","pathToPrice":".prod-price > .money","pathToOnSalePrice":".onsale > .money"},"productDetail":{"classControl":"#product-description","pathToPrice":".product-price > .money","appendTo":"#product-price"},"cart":{"classControl":"#shopping-cart","pathToPrice":"#basket-right > h4 > span.money","appendTo":"#basket-right > h4"}},"css":"tempest"},{"theme_store_id":796,"name":"Debut","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".grid--view-items","loopOn":".grid--view-items .grid__item","pathToPrice":"dl.price > div.price__regular > dd >span.price-item--regular","pathToOnSalePrice":".price > .price__sale > dd > .price-item--sale"},"productDetail":{"classControl":".product-single","pathToPrice":".price-item--sale","appendTo":"dl.price"},"cart":{"classControl":".template-cart","pathToPrice":".cart-subtotal__price","before":".cart__shipping"}},"css":"debut"},{"theme_store_id":730,"name":"Brooklyn","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".grid-collage","loopOn":".grid-product__wrapper","pathToPrice":".grid-product__price-wrap > .grid-product__price","pathToOnSalePrice":".grid-product__price-wrap > .grid-product__price"},"productDetail":{"classControl":".product-single","pathToPrice":".product-single__price","appendTo":"div[data-price-container]"},"cart":{"classControl":"#your-shopping-cart","pathToPrice":".cart__subtotal","after":".push--large--seven-twelfths > .grid--full.cart__row--table"}},"css":"brooklyn"},{"theme_store_id":679,"name":"Supply","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".grid-uniform","loopOn":".product-item--price","pathToPrice":".h1 > span:last","pathToOnSalePrice":".h1 > span:last"},"productDetail":{"classControl":"#ProductSection","pathToPrice":"#productPrice-product-template > span:last","after":".product-meta"},"cart":{"classControl":"#your-shopping-cart","pathToPrice":".cart-subtotal--price > span","after":".cart-subtotal"}},"css":"supply"},{"theme_store_id":380,"name":"Minimal","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".grid-uniform","loopOn":".grid-link","pathToPrice":".grid-link__meta","pathToOnSalePrice":".grid-link__meta"},"productDetail":{"classControl":"#shopify-section-product-template","pathToPrice":"#ProductPrice","after":".product-single__prices"},"cart":{"classControl":"#your-shopping-cart","pathToPrice":".cart__subtotal-price","before":".cart__policies"}},"css":"minimal"},{"theme_store_id":719,"name":"Pop","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".grid-uniform.product-grid","loopOn":".grid-uniform.product-grid .product-wrapper","pathToPrice":".product__price","pathToOnSalePrice":".grid-link__meta"},"productDetail":{"classControl":"#shopify-section-product-template","pathToPrice":"#shopify-section-product-template","after":".product-single__price"},"cart":{"classControl":"form.cart-wrapper","pathToPrice":"form.cart-wrapper .cart__subtotal","after":".cart__subtotal:parent"}},"css":"pop"},{"theme_store_id":829,"name":"Narrative","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".collection-template","loopOn":".collection-template .card__info","pathToPrice":".card__price","pathToOnSalePrice":".card__price > .card__price--sale"},"productDetail":{"classControl":"#shopify-section-product-template","pathToPrice":".product__current-price","after":".product__price"},"cart":{"classControl":"form.cart__form","pathToPrice":"form.cart__form .cart-footer__subtotal","after":".cart-footer__subtotal:parent"}},"css":"narrative"},{"theme_store_id":782,"name":"Jumpstart","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":"#shopify-section-collection-template","loopOn":"#shopify-section-collection-template .product","pathToPrice":".price"},"productDetail":{"classControl":".product-template","pathToPrice":"#ProductPrice-product-template","before":".form__row"},"cart":{"classControl":"#cart-form","pathToPrice":"#cart-form .cart__subtotal","after":"#cart-form .cart__subtotal"}},"css":"jumpstart"},{"theme_store_id":578,"name":"Simple","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":"#products","loopOn":".product__prices ","pathToPrice":".product__price","pathToOnSalePrice":".product__price--on-sale"},"productDetail":{"classControl":".template-product","pathToPrice":"#ProductPrice","after":".product-single__prices"},"cart":{"classControl":"#your-shopping-cart","pathToPrice":".cart__subtotal","before":".cart__policies"}},"css":"simple"},{"theme_store_id":775,"name":"Venture","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":".template-collection","loopOn":".template-collection .product-card__info","pathToPrice":".product-card__regular-price","pathToOnSalePrice":".product-card__price"},"productDetail":{"classControl":"#shopify-section-product-template","pathToPrice":"#ProductPrice-product-template","after":".product-single__meta-list"},"cart":{"classControl":".template-cart","pathToPrice":".cart__subtotal","before":".cart__taxes"}},"css":"venture"},{"theme_store_id":766,"name":"Boundless","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":"#products","loopOn":".product-item__meta","pathToPrice":".product-item__price-wrapper","pathToOnSalePrice":".product-item__price-wrapper > span .product-item__price--sale > span .js-price"},"productDetail":{"classControl":"#shopify-section-product-template","pathToPrice":".js-price","after":".product__price"},"cart":{"classControl":"#your-shopping-cart","pathToPrice":".cart__subtotal","before":".cart__policies"}},"css":"boundless"},{"theme_store_id":1368,"name":"Craft","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":"div.collection","loopOn":"div.card__information","pathToPrice":"div.price","pathToOnSalePrice":"span.price-item.price-item--sale.price-item--last"},"productDetail":{"classControl":"div.product__info-wrapper.grid__item","pathToPrice":"div.price__container","after":"div.price.price--large.price--show-badge"},"cart":{"classControl":"div.cart__footer","pathToPrice":".totals__total-value","after":".totals"}},"css":"craft"},{"theme_store_id":887,"name":"Dawn","script":"storefront-script-tempest.js.twig","config":{"productList":{"classControl":"div.collection","loopOn":"div.card-information","pathToPrice":"div.price__regular > span.price-item price-item--regular","pathToOnSalePrice":"div.price__sale > span.price-item.price-item--sale.price-item--last"},"productDetail":{"classControl":"div.product__info-wrapper.grid__item","pathToPrice":"div.price__sale > span.price-item.price-item--sale.price-item--last , div.price__regular > span.price-item price-item--regular","after":"div.price__container"},"cart":{"classControl":"div.cart__footer","pathToPrice":".totals__total-value","after":".totals"}},"css":"dawn"}]'); let selectedTheme = shop.theme; let shopOrigin = shop.origin; let regexpToGetProductPrice = /\d*\,?\d+.?\d*/; let config = null; let myEle = document.getElementById('flexitiModal'); let storeLanguage = document.documentElement.lang === 'fr' ? 'fr' : 'en'; console.log('Shop', shopOrigin); console.log('Flexiti App Server URL', flexitiAppServerUrl); await loadjQuery(); await loadEasyModal(); try { detectThemeAndFlexitiRender(); flexitiCode(); } catch (err) { console.log(err); } console.log('jQuery modal Loaded'); // 10 function flxCloseDeclinedWithMessage(message) { console.log(message); closeFlexitiModal(); } window.addEventListener('message', function (event) { switch (event.data) { case 'flx-close': flxCloseDeclinedWithMessage('flx-close'); break; case 'flx-apply:declined': flxCloseDeclinedWithMessage('flx-apply:declined'); break; case 'flx-apply:approved': console.log('flx-apply:approved'); $('.flexitiApplyNowLink').hide(); setCookie('flxHasApplied', true); closeFlexitiModal(); break; } }); function setCookie(cname, cvalue, exdays = null) { let expires = ''; if (exdays != null) { let d = new Date(); d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000); expires = 'expires=' + d.toUTCString(); } document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/'; } function getCookie(cname) { const name = cname + '='; const ca = document.cookie.split(';'); for (let c of ca) { if (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return null; } function ThemeException(message) { this.message = message; this.name = 'ThemeException'; } async function loadEasyModal() { return new Promise((resolve, reject) => { if (!myEle) { const urlStaticFlxAppServer = flexitiAppServerUrl + '/static'; let linkElementToAppendScript = document.createElement('script'); linkElementToAppendScript.src = urlStaticFlxAppServer + '/iziModal.js'; linkElementToAppendScript.addEventListener('load', function () { let modalDiv = document.createElement('div'); modalDiv.id = 'flexitiModal'; let body = document.getElementsByTagName('body')[0]; body.insertBefore(modalDiv, body.firstChild); }); document .getElementsByTagName('head')[0] .appendChild(linkElementToAppendScript); let linkElementToAppendCSS = document.createElement('link'); linkElementToAppendCSS.href = urlStaticFlxAppServer + '/iziModal.css'; linkElementToAppendCSS.type = 'text/css'; linkElementToAppendCSS.rel = 'stylesheet'; linkElementToAppendCSS.media = 'screen,print'; document .getElementsByTagName('head')[0] .appendChild(linkElementToAppendCSS); console.log('loading jQuery & css via the app .'); resolve(); } else { console.log('not loading jQuery & css via the app .'); reject(); } }); } function detectThemeAndFlexitiRender() { return new Promise((resolve) => { if (selectedTheme == 'Custom') { try { config = shop.customTheme; } catch (err) { console.log(err); } } else { themesConfig.forEach(function (allowedTheme) { if (selectedTheme == allowedTheme.name) { config = allowedTheme.config; config.css = allowedTheme.css; resolve(config); } }); } if (config == null) { let themeException = new ThemeException('Not allowed Theme.'); throw themeException; } }); } function flexitiCode() { loadThemeCss(); if ( document.readyState === 'complete' || (document.readyState !== 'loading' && !document.documentElement.doScroll) ) { insertPaymentCalculator(); } else { document.addEventListener( 'DOMContentLoaded', insertPaymentCalculator, false, ); } function insertPaymentCalculator() { getCalculatorForProductList(); getCalculatorForProductDetail(); getCalculatorForCart(); } } function getOnlyText($htmlObject) { return $htmlObject .clone() //clone the element .children() //select all the children .remove() //remove all the children .end() //again go back to selected element .text(); } function isGreaterThanZero(regexpMatch) { return ( regexpMatch !== null && regexpMatch[0] !== '0,00' && regexpMatch[0] !== '0.00' && regexpMatch[0] !== '0' ); } function getPaymentCalculatorSnippet(productPrice) { let productPriceAsFloat = getPriceAsFloat(productPrice[0]); return getPaymentCalculatorData(productPriceAsFloat).then(function ( calculator, ) { let strCalculator = calculator || ''; let hasApplied = getCookie('flxHasApplied'); let enabledStyle = hasApplied == 'true' ? "style='display: none;'" : ''; strCalculator = strCalculator .replace('
', '') .replace('
', '') .replace('apply_anonymous flx_apply_now_link', 'flexitiApplyNowLink') .replace('javascript:;"', 'javascript:;"' + enabledStyle); return ( "