(function(window, document) {//"use strict"; /* Wrap code in an IIFE */ // Localize jQuery variables window.feEdQ = window.jQuery; var jQuery, $ = window.jQuery; var app_url=getDsmAppUrl(); //var Cookies = window.Cookies; var dotCookies; var enaCookies = "1"; var yesCookies = 30; var noCookies = 1; // load css var strL = name(Shopify.shop, ".", '_'); //loadCssFile(app_url + "inner/css/featherlight.min.css"); //loadCssFile(app_url + "inner/css/widget.css"); loadCssFile(app_url + "inner/css/sites/"+strL+".css"); function name(str,replaceWhat,replaceTo){ replaceWhat = replaceWhat.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); var re = new RegExp(replaceWhat, 'g'); return str.replace(re,replaceTo); } /******** Load jQuery if not present *********/ if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) { loadjsData(); } else { document.addEventListener("DOMContentLoaded", loadjsData); } function loadjsData() { if(typeof window.jQuery == 'undefined') { var script_tag = document.createElement('script'); script_tag.type = 'text/javascript'; script_tag.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'; script_tag.onload = setJqData; (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag); } else { setJqData(); } } function setJqData() { window.feEdQ = window.jQuery; loadcoockiesData(); } /******** Called once jQuery has loaded ******/ function loadmodalData(set,loc) { if(typeof window.feEdQ.featherlight === 'undefined'){ window.feEdQ.getScript(app_url + "inner/js/jquery.featherlight.min.js", function( data, textStatus, jqxhr ) { if(jqxhr.status == 200){ // loadcoockiesData(); modalSettings(loc); } }); } else { modalSettings(loc); } } function loadcoockiesData(){ if(typeof Cookies === "undefined"){ window.feEdQ.getScript(app_url + "inner/js/feeds.js", function( datac, textStatusc, jqxhrc ) { if(jqxhrc.status == 200){ dotCookies = Cookies.noConflict(); // Call our main function CoockiesSettings(); } }); } else { dotCookies = Cookies.noConflict(); CoockiesSettings(); } } function CoockiesSettings(){ window.feEdQ.getJSON(app_url+'ajax/getCoockiesdata.php?store='+Shopify.shop, function(data,textStatusc, jqxhrc ){ if(jqxhrc.status == 200){ if(data.hasOwnProperty('enable_coockies')){ enaCookies = data.enable_coockies; if(data.enable_coockies == "1"){ if(data.hasOwnProperty('yes_coockies_day') && parseInt(data.yes_coockies_day) > 0){ yesCookies = parseInt(data.yes_coockies_day); } if(data.hasOwnProperty('no_coockies_day') && parseInt(data.no_coockies_day) > 0){ noCookies = parseInt(data.no_coockies_day); } if( data.force_coockies_update == "0" ){ dotCookies.set('__dot_CookiesUpdated', 'n', { expires: 365, path: '/', SameSite:'None', secure: true }); } if(typeof dotCookies.get('__dot_CookiesUpdated') === "undefined" || dotCookies.get('__dot_CookiesUpdated') == "n"){ if( data.force_coockies_update == "1" ){ dotCookies.set('__dot_yesButtonCookies', 'y', { expires: -1, path: '/', SameSite:'None', secure: true}); dotCookies.set('__dot_countryRelativeCookies', 'y', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_countryURLCookies', 'y', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_nobuttonCookies', '', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_sameUrlBase', 'noSame', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_CookiesUpdated', 'y', { expires: 365, path: '/', SameSite:'None', secure: true }); } } main(); } else{ main(); } } else { main(); } } else { main(); } }); } // load css file function loadCssFile(filename){ var fileref=document.createElement("link"); fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", filename); if(typeof fileref!="undefined"){ document.getElementsByTagName("head")[0].appendChild(fileref) } } // main function function main(){ if(dotCookies.get('__dot_nobuttonCookies') == "yes" && enaCookies =="1"){ dotCookies.set('__dot_yesButtonCookies', 'y', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_countryRelativeCookies', 'y', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_countryURLCookies', 'y', { expires: -1, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_sameUrlBase', 'noSame', { expires: -1, path: '/', SameSite:'None', secure: true }); return false; } if(dotCookies.get('__dot_yesButtonCookies') == "yesData" && enaCookies =="1"){ dotCookies.set('__dot_nobuttonCookies', '', { expires: -1, path: '/', SameSite:'None', secure: true }); var countryURL = dotCookies.get('__dot_countryURLCookies'); var getPardot = getUrlParameter("dotred"), encodedstrL = hashCode(strL); if(getPardot == encodedstrL){ // console.log("same url"); dotCookies.set('__dot_sameUrlBase', 'yesSame', { expires: yesCookies, path: '/', SameSite:'None', secure: true }); return false; } if(dotCookies.get('__dot_countryRelativeCookies') == "1") { countryURL = countryURL + RelativeURL(); } //window.location.href = countryURL; addOrUpdateUrlParam("dotred",encodedstrL,countryURL); return false; } var jsonObj = {}; window.feEdQ.getJSON(app_url+'ajax/getlocation.php', function(cont) { window.feEdQ.getJSON(app_url+'ajax/getsettings.php?store='+Shopify.shop+'&lid='+cont.countryCode, function(data){ var set = data.settings, loc = data.location, cname = cont.country; var ip_text = '', exIp = set.excluded_ip, chIP = false; if(set.hasOwnProperty('excluded_ip') && exIp.indexOf(cont.IPv4) != -1){ ip_text = '

Redirect will not work because your IP is excluded form it.

'; chIP = true; } if(loc.hasOwnProperty('countr')){ if(loc.live == "0") { return false; } var str = decodeURIComponent(set.banner_text); if(set.redirect_type == "2"){ str = decodeURIComponent(set.modal_text); } if(set.show_flag == "1"){ cname = " "+ cont.country; } str = str.replace("[country_name]",cname); str = str.replace("[store_name]",loc.newstore); var htmltext = ""; if(set.redirect_type == "1"){ htmltext += '
'; htmltext += '
'; htmltext += '
'; htmltext += ''; htmltext += '
'; htmltext += ''; htmltext += '
'; htmltext += set.yes_button_text; htmltext += '
'; htmltext += '
'; htmltext += '
'; if(set.enable_no_button == "1"){ htmltext += '
'; htmltext += ''; htmltext += '
'; } htmltext += '
'; } else if(set.redirect_type == "2"){ htmltext += '
' +'
' +' ' +' '; if(set.enable_no_button == "1"){ htmltext +='
'+set.no_button_text+'
'; } htmltext +='
' +'
'; } window.feEdQ("body").prepend(htmltext); if(chIP === true){ window.feEdQ(".dot-cta.dot-cta-button, .dot-icon-close, #dot-modal-popup .dot-popup-submit-button").on("click", function (e) { e.preventDefault(); window.feEdQ('#dot-geo-topbar').fadeOut(); }); } else { redirectaction(set,loc); } } }); }); } function redirectaction(s,l){ if(s.redirect_type == "2"){ loadmodalData(s,l); } else if(s.redirect_type == "1"){ window.feEdQ(".dot-close-wrapper .dot-icon-close").on("click", function (e) { e.preventDefault(); dotCookies.set('__dot_nobuttonCookies', 'yes', { expires: 1, path: '/', SameSite:'None', secure: true }); window.feEdQ('#dot-geo-topbar').fadeOut(); }); window.feEdQ(".dot-cta.dot-cta-button").on("click", function (e) { e.preventDefault(); dotCookies.set('__dot_yesButtonCookies', 'yesData', { expires: yesCookies, path: '/', SameSite:'None', secure: true }); redirect(l); }); } else { dotCookies.set('__dot_yesButtonCookies', 'yesData', { expires: yesCookies, path: '/', SameSite:'None', secure: true }); redirect(l); } } function modalSettings(loc){ window.feEdQ.featherlight('#dot-modal-popup', {namespace:'dot-popup-light',closeOnClick:false, closeIcon:'', afterClose: function(){ dotCookies.set('__dot_nobuttonCookies', 'yes', { expires: noCookies, path: '/', SameSite:'None', secure: true }); } }); window.feEdQ("#dot-modal-popup .dot-popup-submit-button").on("click", function (e) { e.preventDefault(); dotCookies.set('__dot_yesButtonCookies', 'yesData', { expires: yesCookies, path: '/', SameSite:'None', secure: true }); redirect(loc); }); } function redirect(l) { var countryURL = l.newurl; var countryURLF = (countryURL.indexOf('://') == -1) ? 'http://' + countryURL : countryURL; var arrUrl = countryURLF.split("/"); countryURL = arrUrl[0] + "//" + arrUrl[2]; dotCookies.set('__dot_countryURLCookies', countryURL, { expires: yesCookies, path: '/', SameSite:'None', secure: true }); dotCookies.set('__dot_sameUrlBase', 'noSame', { expires: -1, path: '/', SameSite:'None', secure: true }); if(l.relaive == "1") { dotCookies.set('__dot_countryRelativeCookies', l.relaive, { expires: yesCookies, path: '/', SameSite:'None', secure: true }); countryURL = countryURL + RelativeURL(); } else { dotCookies.remove('__dot_countryRelativeCookies', { path: '/' }); } var encodedstrL = hashCode(strL); addOrUpdateUrlParam("dotred",encodedstrL,countryURL); //window.location.href = countryURL; } function RelativeURL() { var $page = window.location; return $page.pathname + $page.search + $page.hash; } function addOrUpdateUrlParam(name, value, finurl) { var href = finurl; if(dotCookies.get('__dot_sameUrlBase') == "yesSame"){ return false; } var regex = new RegExp("[&\\?]" + name + "="); if(regex.test(href)) { regex = new RegExp("([&\\?])" + name + "=\\d+"); window.location.href = href.replace(regex, "$1" + name + "=" + value); } else { if(href.indexOf("?") > -1) window.location.href = href + "&" + name + "=" + value; else window.location.href = href + "?" + name + "=" + value; } } function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } } function hashCode(str){ var hash = 0; if (str.length == 0) return hash; for (i = 0; i < str.length; i++) { char = str.charCodeAt(i); hash = ((hash<<5)-hash)+char; hash = hash & hash; // Convert to 32bit integer } return hash; } function getDsmAppUrl(){ // auto detect live and dev version var scripts = document.getElementsByTagName("script"); var scripts_length=scripts.length; var search_result=-1; // not app-dev var app_dev=false; for(var i=0; i=1){ app_dev=true; } } } // app url var app_url="https://geo.dealsontips.com/"; if(app_dev==true){ app_url="https://geo.dealsontips.com/"; } return app_url; } }(window, document)); // We call our anonymous function immediately