{"version":3,"sources":["assets/src/js/Services/CountryLocatorService.js"],"names":["$","document","ready","let","countryLocatorService","CountryLocatorService","initializeDOMEvents","changeCountry","is","css","top","countryList","CountryList","get","on","cookie","expires","hide","proxy","selectedTLD","this","filterByName","val","url","host","window","location","href","getUrlParam","existingSites","uriLocation","filterCountryNames","hostname","split","getJSON","data","ip","done","userIpData","jsonParse","JSON","parse","ErrorMessage","includes","Country","show","fail","always","needle","filter","el","name","filterByTwoIsoCode","twoLetterIsoCode","countryNames","each","index","country","push","results","RegExp","exec","search"],"mappings":"AAYAA,EAAEC,UAAUC,MAAM,WACdC,IAAIC,EAAwB,IAAIC,sBAChCD,EAAsBE,sBACtBF,EAAsBG,gBAElBP,EAAE,8BAA8BQ,GAAG,aACnCR,EAAE,4CAA4CS,IAAI,CAAEC,IAAK,YAKjE,IAAIL,sBAAwB,WAExB,IAAIM,GAAc,IAAIC,aAAcC,MAEpC,MAAO,CACHP,oBAAqB,WACjBN,EAAE,wBAAwBc,GAAG,QAAS,WAClCd,EAAEe,OAAO,cAAe,WAAY,CAChCC,QAAS,KAEbhB,EAAE,8BAA8BiB,OAC/BjB,EAAE,4CAA4CS,IAAI,CAAEC,IAAK,YAG9DV,EAAE,kBAAkBc,GAAG,QAASd,EAAEkB,MAAM,WAEpC,IAAIC,EAAcC,KAAKC,cAAa,IAAIT,aAAcC,MAAOb,EAAE,eAAesB,OAAO,GAAGC,IAGvEH,KAAKC,cAAa,IAAIT,aAAcC,MAAOb,EAAE,eAAesB,OAAO,GAAGE,KAUvF,OARAxB,EAAEe,OAAO,cAAe,cAAe,CACnCC,QAAS,KAGbS,OAAOC,SAASC,KAAQP,KAAKQ,YAAY,WAErC,aAAe5B,EAAE,eAAesB,MADhCH,GAGG,GACRC,QAIPb,cAAe,WACX,IAIQsB,EAIAC,EARuB,YAA3B9B,EAAEe,OAAO,gBAA2D,eAA3Bf,EAAEe,OAAO,eAClDf,EAAE,8BAA8BiB,QAG5BY,EAAgBT,KAAKW,mBAAmBpB,GAIxCmB,EAAeV,KAAKQ,YAAY,WAEhCH,OAAOC,SAASM,SAASC,MAAM,KAAK,GADpCb,KAAKQ,YAAY,WAIrB5B,EAAEkC,QAAQ,oCAAqC,SAAUC,GACrDnC,EAAEkC,QAAQ,2DAA6DC,EAAKC,GAAI,cAE3EC,KAAK,SAAUC,GAERC,EAAYC,KAAKC,MAAMH,IAEvBC,EAAUG,cAGHb,EAAcc,SAASJ,EAAUK,UAEpCL,EAAUK,SAAWd,GACrB9B,EAAE,8BAA8B6C,OAChC7C,EAAE,eAAesB,IAAIiB,EAAUK,UALnC5C,EAAE,8BAA8BiB,SAevC6B,KAAK,cAGLC,OAAO,kBAOxB1B,aAAc,SAAUV,EAAaqC,GACjC,OAAOrC,EAAYsC,OAAO,SAAUC,GAChC,OAAOA,EAAGC,MAAQH,KAI1BI,mBAAoB,SAAUzC,EAAaqC,GACvC,OAAOrC,EAAYsC,OAAO,SAAUC,GAChC,OAAOA,EAAGG,kBAAoBL,KAItCjB,mBAAoB,SAAUpB,GAC1B,IAAI2C,EAAe,GAInB,OAHAtD,EAAEuD,KAAK5C,EAAa,SAAU6C,EAAOC,GACjCH,EAAaI,KAAKD,EAAQN,QAEvBG,GAGX1B,YAAa,SAAUuB,GACfQ,EAAU,IAAIC,OAAO,OAAUT,EAAO,aACrCU,KAAKpC,OAAOC,SAASoC,QAE1B,OAAoB,OAAZH,IAAoBA,EAAQ,IAAM","file":"CountryLocatorService.js","sourcesContent":["/*\r\nBussiness rules:\r\n\r\nBR1: If the user's IP geolocalization differs from the site's country (e.g. if a swiss user goes on fr.markem-imaje.com or markem-imaje.com instead of ch.markem-imaje.com), then a banner is displayed above the header inviting the user to\r\n\t\t- Change to predefined region (user’s region, e.g. \"Switzerland\")\r\n\t\t- Go to the region selection page (\"Choose another region...\")\r\n\t\t- Dismiss and stay on current region (\"X\" button)\r\nBR2: If the user dismiss the above mentioned banner (by closing it through a \"X\" button\"), then he stays on the current site. If dismissed, the choice is saved in a cookie in order to prevent to display the banner again.\r\nBR3: The above mentioned banner is only displayed if the IP geolocalization corresponds to an existing site (e.g. If a user is based in Egypt but no eg.markem-imaje.com is existing, no banner is displayed.)\r\n\r\n*/\r\n\r\n$(document).ready(function () {\r\n let countryLocatorService = new CountryLocatorService();\r\n countryLocatorService.initializeDOMEvents();\r\n countryLocatorService.changeCountry();\r\n\r\n if ($(\"#mi-countrySelector-banner\").is(\":visible\")) {\r\n $('.mi-corpo-header-homepagehero-cta-button').css({ top: '290px' });\r\n }\r\n\r\n});\r\n\r\nvar CountryLocatorService = function () {\r\n\r\n var countryList = new CountryList().get();\r\n\r\n return {\r\n initializeDOMEvents: function () {\r\n $('#close-banner-button').on('click', function () {\r\n $.cookie(\"countrySite\", \"REJECTED\", {\r\n expires: 10\r\n });\r\n $('#mi-countrySelector-banner').hide();\r\n $('.mi-corpo-header-homepagehero-cta-button').css({ top: '400px' });\r\n });\r\n\r\n $('.banner-submit').on('click', $.proxy(function () {\r\n\r\n var selectedTLD = this.filterByName(new CountryList().get(), $(\"#Dropdown-1\").val())[0].url;\r\n\r\n //ToDo: Set the cookie for all the domain and subdomains\r\n var cookieHost = this.filterByName(new CountryList().get(), $(\"#Dropdown-1\").val())[0].host;\r\n\r\n $.cookie(\"countrySite\", \"ALREADY_SET\", {\r\n expires: 10,\r\n });\r\n\r\n window.location.href = !this.getUrlParam('country') ?\r\n selectedTLD :\r\n '/?country=' + $(\"#Dropdown-1\").val();\r\n\r\n return false;\r\n }, this));\r\n\r\n },\r\n\r\n changeCountry: function () {\r\n if ($.cookie(\"countrySite\") == \"REJECTED\" || $.cookie(\"countrySite\") == \"ALREADY_SET\") {\r\n $('#mi-countrySelector-banner').hide();\r\n } else {\r\n\r\n var existingSites = this.filterCountryNames(countryList);\r\n // URL should be like 'en.markem-image.com'\r\n // var uriLocation = window.location.hostname.split(\".\")[0];\r\n // in the meantime we can simulate adding ?country=CH to the URI\r\n var uriLocation = !this.getUrlParam('country') ?\r\n this.getUrlParam('country') :\r\n window.location.hostname.split('.')[0];\r\n\r\n // using get request to api.ipify to get public ip of this machine\r\n $.getJSON(\"https://api.ipify.org?format=json\", function (data) {\r\n $.getJSON(\"/Sitefinity/Public/Services/GeoLocation/GeoLocation.svc/\" + data.ip, function () {\r\n })\r\n .done(function (userIpData) {\r\n // BR3\r\n var jsonParse = JSON.parse(userIpData);\r\n\r\n if (jsonParse.ErrorMessage) {\r\n //alert(\"ErrorMessage is not null\");\r\n $('#mi-countrySelector-banner').hide();\r\n } else if (existingSites.includes(jsonParse.Country)) {\r\n // BR1\r\n if (jsonParse.Country != uriLocation) {\r\n $('#mi-countrySelector-banner').show();\r\n $(\"#Dropdown-1\").val(jsonParse.Country);\r\n } else {\r\n // locations are the same\r\n // do not need to do anything\r\n $('#mi-countrySelector-banner').hide();\r\n }\r\n } else {\r\n $('#mi-countrySelector-banner').hide();\r\n }\r\n })\r\n .fail(function () {\r\n //alert('fail=' + data);\r\n })\r\n .always(function () {\r\n //console.log( \"complete\" );\r\n });\r\n });\r\n }\r\n },\r\n\r\n filterByName: function (countryList, needle) {\r\n return countryList.filter(function (el) {\r\n return el.name == needle;\r\n });\r\n },\r\n\r\n filterByTwoIsoCode: function (countryList, needle) {\r\n return countryList.filter(function (el) {\r\n return el.twoLetterIsoCode == needle;\r\n });\r\n },\r\n\r\n filterCountryNames: function (countryList) {\r\n var countryNames = [];\r\n $.each(countryList, function (index, country) {\r\n countryNames.push(country.name);\r\n });\r\n return countryNames;\r\n },\r\n\r\n getUrlParam: function (name) {\r\n var results = new RegExp('[\\?&]' + name + '=([^&#]*)')\r\n .exec(window.location.search);\r\n\r\n return (results !== null) ? results[1] || 0 : false;\r\n\r\n }\r\n }\r\n};"]}