{"version":3,"sources":["ageGate.js"],"names":["yearElement","document","getElementById","monthElement","dayElement","injectError","message","targetClass","errorTemplate","elementListRemove","getElementsByClassName","item","remove","elementList","insertAdjacentHTML","checkAge","error","countryDD","country","value","countryName","options","selectedIndex","text","isEmptyOrSpaces","pleaseCompleteCountry","day","month","year","date","Date","pleaseCompleteDate","checkAgeWithAPI","then","result","success","allowed","JSON","parse","resultJson","dateYear","getFullYear","alcoholPurchaseProhibited","googleDataLayer","failedAgeGate","notAllowedByCountry","replace","ageCheckResult","passedAgeGate","SetAgeGateCookieAndRedirect","notOldEnoughError","alcoholPurchaseAge","parameters","URLSearchParams","dateOfBirth","toISOString","console","log","Promise","resolve","reject","fetch","ageGateUrl","method","headers","Accept","response","json","catch","AgeGateSet","classList","add","querySelector","daysInMonth","parseInt","days","getDate","first","option","querySelectorAll","d","createElement","appendChild","addEventListener","event"],"mappings":"AAAA,IAAIA,YAAcC,SAASC,eAAe,UACtCC,aAAeF,SAASC,eAAe,WACvCE,WAAaH,SAASC,eAAe,SAEzC,SAASG,YAAYC,EAASC,GAC1B,IAAIC,EAAgB,sCAAsCF,UAG1D,IAAIG,EAAoBR,SAASS,uBAAuB,mBACxD,IAAK,IAAIC,KAAQF,EACbE,EAAKC,SAGT,IAAIC,EAAcZ,SAASS,uBAAuBH,GAClD,IAAK,IAAII,KAAQE,EAEbF,EAAKG,mBAAmB,cAAeN,GAI/C,SAASO,WACL,IAAIC,GAAQ,EAKRC,EAAYhB,SAASC,eAAe,aACpCgB,EAAUD,EAAUE,MACpBC,EAAcH,EAAUI,QAAQJ,EAAUK,eAAeC,KAEzDC,gBAAgBN,KAChBb,YAAYoB,sBAAuB,aACnCT,GAAQ,GAGZ,IAAIU,EAAMzB,SAASC,eAAe,SAASiB,MACvCQ,EAAQ1B,SAASC,eAAe,WAAWiB,MAC3CS,EAAO3B,SAASC,eAAe,UAAUiB,MAEzCU,EAAO,IAAIC,KAAKF,EAAMD,EAAQ,EAAGD,GAUrC,IARIF,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+C,SAASvE,aAAagB,OAC9BS,EAAO8C,SAAS1E,YAAYmB,OAEhC,GAAc,IAAVQ,GAAwB,IAATC,EAqBf,OAAO,EApBP,IAAI+C,EAAO,IAAI7C,KAAKF,EAAMD,EAAO,GAAGiD,UAGhCC,GAAQ,EACZ,IAAK,MAAMC,KAAU7E,SAAS8E,iBAAiB,mBACtCF,EAGDA,GAAQ,EAFRC,EAAOlE,SAKf,IAAK,IAAIoE,EAAI,EAAGA,GAAKL,EAAMK,IACvBF,OAAS7E,SAASgF,cAAc,UAChCH,OAAOvD,KAAOyD,EACdF,OAAO3D,MAAQ6D,EACf5E,WAAW8E,YAAYJ,QAG3B7E,SAASC,eAAe,SAASoB,cAAgB,EAxCzDtB,YAAYmF,iBAAiB,UAAU,SAAUC,GAE7CX,iBAEJtE,aAAagF,iBAAiB,UAAU,SAAUC,GAE9CX","file":"../ageGate.js","sourcesContent":["var yearElement = document.getElementById('AGYear');\r\nvar monthElement = document.getElementById('AGMonth');\r\nvar dayElement = document.getElementById('AGDay');\r\n\r\nfunction injectError(message, targetClass) {\r\n var errorTemplate = `
${message}
`;\r\n\r\n // remove old errors\r\n let elementListRemove = document.getElementsByClassName('validationError');\r\n for (let item of elementListRemove) {\r\n item.remove();\r\n }\r\n\r\n let elementList = document.getElementsByClassName(targetClass);\r\n for (let item of elementList) {\r\n //console.log(item);\r\n item.insertAdjacentHTML('beforeBegin', errorTemplate);\r\n }\r\n}\r\n\r\nfunction checkAge() {\r\n let error = false;\r\n\r\n // VALIDATION\r\n // --------------------\r\n\r\n let countryDD = document.getElementById('Countries');\r\n let country = countryDD.value;\r\n let countryName = countryDD.options[countryDD.selectedIndex].text;\r\n\r\n if (isEmptyOrSpaces(country)) {\r\n injectError(pleaseCompleteCountry, 'Countries');\r\n error = true;\r\n }\r\n\r\n let day = document.getElementById('AGDay').value;\r\n let month = document.getElementById('AGMonth').value;\r\n let year = document.getElementById('AGYear').value;\r\n\r\n let date = new Date(year, month - 1, day);\r\n\r\n if (isEmptyOrSpaces(day) || isEmptyOrSpaces(month) || isEmptyOrSpaces(year) || date == null) {\r\n injectError(pleaseCompleteDate, 'select-container-date');\r\n error = true;\r\n }\r\n\r\n // API CALL\r\n // --------------------\r\n\r\n if (!error) {\r\n let prom = checkAgeWithAPI(country, date);\r\n prom.then(\r\n function (result) {\r\n if (result.success) {\r\n \r\n var allowed = JSON.parse(result.resultJson);\r\n var dateYear = date.getFullYear();\r\n if (allowed.alcoholPurchaseProhibited) {\r\n if (typeof googleDataLayer !== 'undefined') {\r\n googleDataLayer.failedAgeGate(countryName, dateYear, \"Blocked by country\");\r\n }\r\n injectError(notAllowedByCountry.replace('%%country%%', countryName), 'select-container-date')\r\n return;\r\n }\r\n if (allowed.ageCheckResult) {\r\n if (typeof googleDataLayer !== 'undefined') {\r\n googleDataLayer.passedAgeGate(countryName, dateYear);\r\n }\r\n SetAgeGateCookieAndRedirect(countryName);\r\n } else {\r\n if (typeof googleDataLayer !== 'undefined') {\r\n googleDataLayer.failedAgeGate(countryName, dateYear, \"Not old enough\");\r\n }\r\n injectError(notOldEnoughError.replace('%%country%%', countryName).replace('%%purchaseAge%%', allowed.alcoholPurchaseAge), 'select-container-date')\r\n }\r\n }\r\n else\r\n {\r\n if (typeof googleDataLayer !== 'undefined') {\r\n googleDataLayer.failedAgeGate(countryName, dateYear, \"API Error\");\r\n }\r\n injectError('Non-success from API', 'select-container-date');\r\n }\r\n }\r\n );\r\n }\r\n}\r\n\r\n// API / Query\r\n// ===========\r\n\r\nfunction checkAgeWithAPI(country, date) {\r\n //https://dalmore-local.factory73.com/umbraco/surface/API/CheckAgeGate/?country=GB&dateOfBirth=2000-03-02T12:01:19.289Z&brand=Dalmore\r\n\r\n let parameters = new URLSearchParams({\r\n country: country,\r\n dateOfBirth: date.toISOString()\r\n });\r\n\r\n console.log('Parameters : %o', parameters);\r\n\r\n return new Promise(function (resolve, reject) {\r\n fetch(ageGateUrl + '?' + parameters, {\r\n method: 'get', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },\r\n })\r\n .then(function (response) {\r\n resolve(response.json());\r\n })\r\n .catch(error => {\r\n console.log('Failed', error);\r\n reject(error);\r\n });\r\n });\r\n}\r\n\r\nyearElement.addEventListener('change', function (event) {\r\n //console.log(event.target); // The clicked element\r\n daysInMonth();\r\n});\r\nmonthElement.addEventListener('change', function (event) {\r\n //console.log(event.target); // The clicked element\r\n daysInMonth();\r\n});\r\n\r\nfunction SetAgeGateCookieAndRedirect(country) {\r\n AgeGateSet(country); // Scripts.js\r\n //console.log('Allowed');\r\n\r\n document.getElementById(\"modal_id\").classList.add('hidden');\r\n document.querySelector(\"body\").classList.remove('overflow--hidden');\r\n}\r\n\r\nfunction daysInMonth() {\r\n var month = parseInt(monthElement.value);\r\n var year = parseInt(yearElement.value);\r\n\r\n if (month !== 0 && year !== 0) {\r\n var days = new Date(year, month, 0).getDate();\r\n\r\n // Remove all\r\n var first = true;\r\n for (const option of document.querySelectorAll('#AGDay > option')) {\r\n if (!first) {\t// Leave the day label\r\n option.remove();\r\n } else {\r\n first = false;\r\n }\r\n }\r\n for (let d = 1; d <= days; d++) {\r\n option = document.createElement(\"option\");\r\n option.text = d;\r\n option.value = d;\r\n dayElement.appendChild(option)\r\n }\r\n\r\n document.getElementById(\"AGDay\").selectedIndex = 1; \r\n } else {\r\n return 0;\r\n }\r\n}"]}