console.log('Glow initiated.'); var launchLoyalty; var kb_ref = false; var launchLedger; var embedSpruli; if (typeof ledgerLaunched === 'undefined') { var ledgerLaunched = 0; } if (typeof embedLaunched === 'undefined') { var embedLaunched = 0; } (function () { var getCookie = function (cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return false; } var getParameterByName = function (name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url); if (!results) return false; if (!results[2]) return false; return decodeURIComponent(results[2].replace(/\+/g, " ")); } launchPixel = function () { var cid = __st.cid; var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; var widgetUrl = "https://www.glowloyalty.com/pixel?cid=" + cid + "&shop=trendout.myshopify.com&baseUrl=https://www.trendout.pt/"; var ref_id = localStorage.getItem("kb_ref"); if (ref_id) { widgetUrl = widgetUrl + "&ref_id=" + ref_id; } var xhr = new XMLHttpRequest(); xhr.open('GET', widgetUrl); xhr.responseType = 'text'; xhr.onload = function() { if (xhr.status === 200) { } }; xhr.send(); } launchLoyalty = function () { var cid = __st.cid; var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; var widgetUrl = "https://www.glowloyalty.com/widget?cid=" + cid + "&shop=trendout.myshopify.com&baseUrl=https://www.trendout.pt/"; if (getParameterByName('loyaltyTab') != false) { widgetUrl = widgetUrl + "&loyaltyTab=" + getParameterByName('loyaltyTab'); } if (window.location.href.indexOf("thank_you") > -1 && window.location.href.indexOf("checkouts") > -1) { widgetUrl = widgetUrl + "&loyaltyTab=/widget/referral/code"; } var ref_id = localStorage.getItem("kb_ref"); if (ref_id) { widgetUrl = widgetUrl + "&ref_id=" + ref_id; } var spruliFrame = document.createElement('iframe'); spruliFrame.style.cssText = 'animation: fadeInAnimation 0.5s; position:fixed;width:100%;height:100%;z-index:9999999999; top:0; left:0; right:0; bottom:0; border:0;'; spruliFrame.src = widgetUrl; spruliFrame.id = "spruliFrame" document.body.appendChild(spruliFrame); } getPoints = function(){ var cid = __st.cid; if (cid == null){ //no customer, do nothing } else { //customer found, get points console.log(cid); var xhr = new XMLHttpRequest(); xhr.open('GET', "https://www.glowloyalty.com/customer-points/"+cid); xhr.responseType = 'text'; xhr.onload = function() { if (xhr.status === 200) { var container = document.getElementById('loyalty_callout_container'); if(xhr.responseText != ''){ container.innerHTML = xhr.responseText; } } }; xhr.send(); } } launchLedger = function () { var cid = __st.cid; var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; var widgetUrl = "https://www.glowloyalty.com/ledger?cid=" + cid + "&id=258&shop=trendout.myshopify.com&baseUrl=https://www.trendout.pt/"; if (ledgerLaunched == 0) { var loyaltyLedgerFrame = document.createElement('iframe'); loyaltyLedgerFrame.style.cssText = 'width:100%;height:1500px;z-index:9999999999; border:0;'; loyaltyLedgerFrame.src = widgetUrl; loyaltyLedgerFrame.id = "loyaltyLedgerFrame" var ledger = document.getElementById("loyalty_ledger"); if (ledger) { ledger.appendChild(loyaltyLedgerFrame); ledgerLaunched = 1; } } } embedSpruli = function () { var cid = __st.cid; var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; var height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; var widgetUrl = "https://www.glowloyalty.com/embed-widget?cid=" + cid + "&id=258&shop=trendout.myshopify.com&baseUrl=https://www.trendout.pt/"; if (ledgerLaunched == 0) { var loyaltyEmbedFrame = document.createElement('iframe'); loyaltyEmbedFrame.style.cssText = 'width:100%;height:1500px;z-index:9999999999; border:0;'; loyaltyEmbedFrame.src = widgetUrl; loyaltyEmbedFrame.id = "loyaltyEmbedFrame" var embed = document.getElementById("loyalty_rewards_embed"); if (embed) { embed.appendChild(loyaltyEmbedFrame); embedLaunched = 1; } } } kb_ref = getParameterByName('kb_ref'); if (kb_ref != false) { localStorage.setItem("kb_ref", kb_ref); } if (getParameterByName('launchLoyalty') != false) { launchLoyalty(); } if (window.location.href.indexOf("thank_you") > -1 && window.location.href.indexOf("checkouts") > -1) { launchLoyalty(); } if (ledgerLaunched == 0) { launchLedger(); } if (embedLaunched == 0) { embedSpruli(); } var calloutContainer = document.createElement('div'); calloutContainer.style.cssText = 'opacity:1; animation: scaleIn .4s; position:fixed; left:83px; bottom:35px; border:0; padding:5px 10px; width:auto; z-index:2147483648; background:#fff; color: #000000; border-radius:5px; font-size:12px; box-shadow:2px 2px 10px rgba(0,0,0,0.2);'; calloutContainer.innerHTML = "Recompensas"; document.body.appendChild(calloutContainer); calloutContainer.id="loyalty_callout_container"; var styleContainer = document.createElement('style'); styleContainer.innerHTML="@keyframes fadeInAnimation {0% {opacity:0;} 20%{ opacity:0; } 100% {opacity:1;}} @keyframes scaleFromCenter {0% {transform: scale(0);}100% {transform: scale(1);}} @keyframes scaleIn {0% {transform: scale(0);} 30% {transform: scale(0);} 100% {transform: scale(1);}}"; document.body.appendChild(styleContainer); var loyaltyLauncher = document.createElement('button'); loyaltyLauncher.style.cssText = 'animation: scaleFromCenter .25s; position:fixed; left:20px; bottom:20px; border:0; padding:10px; width:60px; height:60px; z-index:2147483648; background:#000000; color: #ffffff; border-radius:300px;'; loyaltyLauncher.innerHTML = ""; loyaltyLauncher.setAttribute('onClick', 'launchLoyalty(); loyaltyLauncher.blur()'); loyaltyLauncher.id = "loyaltyLauncher" document.body.appendChild(loyaltyLauncher); })(); function receiveSpruliMessage(event) { if (event.data == "removetheiframe") { var element = document.getElementById('spruliFrame'); element.parentNode.removeChild(element); } } window.addEventListener("message", receiveSpruliMessage, false); launchPixel(); setTimeout(function(){ getPoints(); },0);