' var isIframeInserted = false; var iframe = iframeContainer.querySelector('#shopstar-iframe'); window.addEventListener('message', function (event) { if (event.source === iframe.contentWindow) { if (event.data.type === 'close-shopstar') { hideStopstar() } if (event.data.type === 'location-replace') { window.location.replace(event.data.payload) } } }) return iframeContainer; } var disabled = response.enabled != 'enabled' if (disabled) return; var isIframeInserted = false; var iframeContainer = createIframe({ floating: true }); function showShopstar() { emitEvent("activate_popup", { merchant_id: "22409521", merchant_name: "Toyster Singapore", referral: referral }); var landingPageData = response.widgetTemplate.landingPage; var isLandingPageEnabled = landingPageData.status == "enabled"; if (isLandingPageEnabled && landingPageData.page) { window.location.assign(window.location.origin + "/pages/" + landingPageData.page); return; } if (!isIframeInserted) { document.body.appendChild(iframeContainer); var distanceToTop = window.pageYOffset + iframeContainer.getBoundingClientRect().top; iframeContainer.style.height = "calc(100vh - " + distanceToTop + ")"; } iframeContainer.style.display = 'flex' document.body.style.overflow = 'hidden'; } function hideStopstar() { iframeContainer.style.display = 'none' document.body.style.overflow = ''; } if (window.location.search.includes('shopstar')) { showShopstar(); } window._shopstar = { mobile: mobile, showShopstar: showShopstar, hideStopstar: hideStopstar, widget: response, createIframe: createIframe } window._shopstarInitListeners.forEach(function (listener) { listener(window._shopstar) }) window._shopstarInitListeners = [] return window._shopstar }) } return new Promise(function (resolve) { window._shopstarInitListeners.push(resolve) }) } window._shopstarInit = initIframe initIframe() })()