const debounceUnlokkIframe = (func) => { let timer; return function (event) { if (timer) clearTimeout(timer); timer = setTimeout(func, 200, event); }; }; // LEGACY - some eshops use this const debounce = (func) => { let timer; return function (event) { if (timer) clearTimeout(timer); timer = setTimeout(func, 200, event); }; }; const removeSymbolsFromString = (str) => str.replace(/[`~!@#$%^&*()€_|+\-=?;:'"<>\{\}\[\]\\\/]/gi, ""); const reinitIframe = (wrapper, settings) => { const iframe = wrapper.querySelector("#unlokk-iframe"); // Remove symbols from amount str settings.amount = settings.amount ? removeSymbolsFromString(settings.amount.toString()) : null; // Replace comma with dot if (settings.amount?.includes(",")) { settings.amount = settings.amount.replace(",", "."); } // Convert to number settings.amount = +settings.amount; settings.amount = settings.amount.toFixed(2); // Replace dot with comma settings.amount = settings.amount.replace(".", ","); settings.screenSize = window.innerWidth; // Wrapper height depending on screen size // and wrapper's width if (window.innerWidth < 768) { // Mobile if (wrapper.offsetWidth <= 400) { wrapper.style.height = "170px"; } else if (wrapper.offsetWidth <= 550) { wrapper.style.height = "150px"; } else { wrapper.style.height = "135px"; } } else { // Desktop if (wrapper.offsetWidth <= 249) { // Vertical wrapper.style.height = "300px"; } else if (wrapper.offsetWidth <= 352) { wrapper.style.height = "280px"; } else if (wrapper.offsetWidth <= 400) { wrapper.style.height = "270px"; } else if (wrapper.offsetWidth <= 449) { wrapper.style.height = "250px"; } else { // Horizontal wrapper.style.height = "115px"; } } iframe.src = `https://unlokk.lt/qr-code/iframe?amount=${settings.amount}¤cy=${settings.currency}&screenSize=${settings.screenSize}&theme=${settings.theme}&borderRadius=${settings.borderRadius}&months=${settings.months}#unlokk-referrer-${document.domain}`; };