{"version":3,"sources":["src/scripts/modules/survey-dialog/survey-dialog.js","src/scripts/modules/survey-dialog/survey-dialog-init.js"],"names":["$","jQuery","fn","survey","config","selectors","acceptSurvey","rejectSurvey","classNames","cookie","pageCountCookie","surveyCookieParticipation","surveyCookie","minDuration","maxDuration","$surveyDialog","this","$rejectSurveyButtons","find","$acceptSurveyButtons","$cookieDurationMin","Number","attr","$cookieDurationMax","$cookieDuration","setCookie","cookieValue","dmin","Date","dmax","setTime","getTime","document","concat","toUTCString","expires","initSurvey","each","i","el","$rejectSurveyButton","on","e","preventDefault","surveyDialogHide","initRejectSurveyButton","$acceptSurveyButton","window","open","initAcceptSurveyButton","show","hide","cookies","split","surveyCookieParticipationExist","surveyCookieExist","pageCountCookieExist","page","location","pathname","pop","forEach","charAt","substring","indexOf","length","pages","pageExist","singlePage","init","surveyDialog","initSurveyDialog"],"mappings":"yBAGC,IAAUA,GAAAA,EA8JTC,QA7JIC,GAAGC,OAAS,WAEV,IAAMC,EAAS,CACXC,UAAW,CACPC,aAAc,8BACdC,aAAc,+BAElBC,WAAY,GACZC,OAAQ,CACJC,gBAAiB,iBACjBC,0BAA2B,2BAC3BC,aAAc,mBACdC,YAAa,EACbC,YAAa,KAIfC,EAAgBC,KAChBC,EAAuBF,EAAcG,KAAKd,EAAOC,UAAUE,cAC3DY,EAAuBJ,EAAcG,KAAKd,EAAOC,UAAUC,cAG3Dc,EAA8D,IAAzCC,OAAON,EAAcO,KAAK,aAAsB,GAAK,GAAK,IAAkC,IAA5BlB,EAAOK,OAAOI,YAAqB,GAAK,GAAK,GAClIU,EAA8D,IAAzCF,OAAON,EAAcO,KAAK,aAAsB,GAAK,GAAK,IAAkC,IAA5BlB,EAAOK,OAAOK,YAAqB,GAAK,GAAK,GACpIU,EAAkBJ,EAsEtB,SAASK,EAAUC,GACf,IAAMC,EAAO,IAAIC,KACXC,EAAO,IAAID,KACjBD,EAAKG,QAAQH,EAAKI,UAAYP,GAC9BK,EAAKC,QAAQD,EAAKE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sD,OAAS,EAAGxD,EAAOwD,SAG9D,IAA/CxD,EAAOuD,QAAQ5D,EAAOK,OAAOG,gBAC7B2C,EAAoB9C,EAAOsD,UAAU3D,EAAOK,OAAOG,aAAaqD,OAAS,EAAGxD,EAAOwD,WAIvFX,EACKC,IAED/B,EAAkBD,EAClBa,UAKJ,GAAIoB,EAAsB,CACtB,IAAMU,EAAQV,EAAqBH,MAAM,KACrCc,GAAY,EACK,IAAjBD,EAAMD,OAEN7B,KAGA8B,EAAML,QAAQ,SAACO,GACPA,IAAeX,IACfU,GAAY,KAGfA,IACoB,IAAjBD,EAAMD,QAEN7B,IAGJJ,SAASvB,OAAT,GAAAwB,OAAqB7B,EAAOK,OAAOC,gBAAnC,KAAAuB,OAAsDuB,EAAtD,KAAAvB,OAA8EwB,EAA9E,aAAAxB,OAA8F,IAAIL,KAAK,cAAmBM,cAA1H,kBAKRF,SAASvB,OAAT,GAAAwB,OAAqB7B,EAAOK,OAAOC,gBAAnC,KAAAuB,OAAsDwB,EAAtD,aAAAxB,OAAsE,IAAIL,KAAK,cAAmBM,cAAlG,WAmEZmC,ICvJJrE,EAPW,CACPsE,aAAc,kBAMCA,cAAcjC,KAAK,SAACC,EAAGC,IAM9C,SAA0BxB,GACtBA,EAAcZ,SALVoE,CADsBvE,EAAEuC","file":"survey-dialog.min.js","sourcesContent":["/* eslint-disable func-names */\r\n/* eslint-disable max-len */\r\n// eslint-disable-next-line func-names\r\n(function ($) {\r\n $.fn.survey = function () {\r\n // setup config data\r\n const config = {\r\n selectors: {\r\n acceptSurvey: '.survey-dialog__btn--accept',\r\n rejectSurvey: '.survey-dialog__btn--reject',\r\n },\r\n classNames: {},\r\n cookie: {\r\n pageCountCookie: 'mtk_page_count',\r\n surveyCookieParticipation: 'mtk_survey_participation',\r\n surveyCookie: 'mtk_survey_value',\r\n minDuration: 7,\r\n maxDuration: 30,\r\n },\r\n };\r\n // init dialog and buttons\r\n const $surveyDialog = this;\r\n const $rejectSurveyButtons = $surveyDialog.find(config.selectors.rejectSurvey);\r\n const $acceptSurveyButtons = $surveyDialog.find(config.selectors.acceptSurvey);\r\n\r\n // set cookie duration default values\r\n const $cookieDurationMin = Number($surveyDialog.attr('data-min')) * 1000 * 60 * 60 * 24 || config.cookie.minDuration * 1000 * 60 * 60 * 24;\r\n const $cookieDurationMax = Number($surveyDialog.attr('data-max')) * 1000 * 60 * 60 * 24 || config.cookie.maxDuration * 1000 * 60 * 60 * 24;\r\n let $cookieDuration = $cookieDurationMin;\r\n\r\n // init function\r\n function init() {\r\n // get cookie\r\n const cookies = document.cookie.split(';');\r\n let surveyCookieParticipationExist = false;\r\n let surveyCookieExist = false;\r\n let pageCountCookieExist = false;\r\n const path = window.location.pathname;\r\n const page = path.split('/').pop();\r\n\r\n cookies.forEach((cookie) => {\r\n while (cookie.charAt(0) === ' ') {\r\n // eslint-disable-next-line no-param-reassign\r\n cookie = cookie.substring(1);\r\n }\r\n // check if page count cookie exist\r\n if (cookie.indexOf(config.cookie.pageCountCookie) === 0) {\r\n pageCountCookieExist = cookie.substring(config.cookie.pageCountCookie.length + 1, cookie.length);\r\n }\r\n // check if main cookie exist\r\n if (cookie.indexOf(config.cookie.surveyCookieParticipation) === 0) {\r\n surveyCookieParticipationExist = cookie.substring(config.cookie.surveyCookieParticipation.length + 1, cookie.length);\r\n }\r\n // check if value cookie exist\r\n if (cookie.indexOf(config.cookie.surveyCookie) === 0) {\r\n surveyCookieExist = cookie.substring(config.cookie.surveyCookie.length + 1, cookie.length);\r\n }\r\n });\r\n // init survey dialog\r\n if (surveyCookieParticipationExist) {\r\n if (!surveyCookieExist) {\r\n // if main cookie exist and value cookie do not exist set expiration date to max and show dialog\r\n $cookieDuration = $cookieDurationMax;\r\n initSurvey();\r\n }\r\n } else {\r\n // if main cookie do not exist check if page count cookie exist\r\n // eslint-disable-next-line no-lonely-if\r\n if (pageCountCookieExist) {\r\n const pages = pageCountCookieExist.split('#');\r\n let pageExist = false;\r\n if (pages.length === 3) {\r\n // if 3 separate pages opened\r\n initSurvey();\r\n } else {\r\n // if 3 separate pages NOT opened compare if page exist in cookie\r\n pages.forEach((singlePage) => {\r\n if (singlePage === page) {\r\n pageExist = true;\r\n }\r\n });\r\n if (!pageExist) {\r\n if (pages.length === 2) {\r\n // if page is 3rd separate page init survey\r\n initSurvey();\r\n }\r\n // if page do not exist in cookie add page to cookie\r\n document.cookie = `${config.cookie.pageCountCookie}=${pageCountCookieExist}#${page};expires=${new Date(2147483647 * 1000).toUTCString()};path=/`;\r\n }\r\n }\r\n } else {\r\n // if main cookie do not exist and page count cookie do not exist create pagecount cookie\r\n document.cookie = `${config.cookie.pageCountCookie}=${page};expires=${new Date(2147483647 * 1000).toUTCString()};path=/`;\r\n }\r\n }\r\n }\r\n\r\n // set cookie\r\n function setCookie(cookieValue) {\r\n const dmin = new Date();\r\n const dmax = new Date();\r\n dmin.setTime(dmin.getTime() + $cookieDuration);\r\n dmax.setTime(dmax.getTime() + $cookieDurationMax);\r\n // if duration is min than show main cookie\r\n if ($cookieDuration === $cookieDurationMin) {\r\n document.cookie = `${config.cookie.surveyCookieParticipation}=${cookieValue};expires=${new Date(2147483647 * 1000).toUTCString()};path=/`;\r\n }\r\n // if value is accepted set value cookie duration to 'unlimited'\r\n const expires = cookieValue !== 'accept' ? `expires=${dmin.toUTCString()}` : `expires=${dmax.toUTCString()}`;\r\n document.cookie = `${config.cookie.surveyCookie}=${cookieValue};${expires};path=/`;\r\n }\r\n\r\n // init dialog\r\n function initSurvey() {\r\n // init dialog reject button\r\n $rejectSurveyButtons.each((i, el) => {\r\n const $rejectSurveyButton = $(el);\r\n initRejectSurveyButton($rejectSurveyButton);\r\n });\r\n\r\n // init dialog accept button\r\n $acceptSurveyButtons.each((i, el) => {\r\n const $acceptSurveyButton = $(el);\r\n initAcceptSurveyButton($acceptSurveyButton);\r\n });\r\n\r\n // show dialog\r\n surveyDialogShow();\r\n }\r\n\r\n function initRejectSurveyButton($rejectSurveyButton) {\r\n $rejectSurveyButton.on('click', (e) => {\r\n // on reject set the cookie and close dialog\r\n e.preventDefault();\r\n setCookie('reject');\r\n surveyDialogHide();\r\n });\r\n }\r\n\r\n function initAcceptSurveyButton($acceptSurveyButton) {\r\n $acceptSurveyButton.on('click', (e) => {\r\n // on accept set the cookie\r\n e.preventDefault();\r\n setCookie('accept');\r\n window.open($acceptSurveyButton.attr('href'), '_blank');\r\n surveyDialogHide();\r\n });\r\n }\r\n\r\n // hide survey\r\n function surveyDialogHide() {\r\n $surveyDialog.hide();\r\n }\r\n\r\n // show survey\r\n function surveyDialogShow() {\r\n $surveyDialog.show();\r\n }\r\n\r\n init();\r\n };\r\n}(jQuery));\r\n","const config = {\r\n selectors: {\r\n surveyDialog: '.survey-dialog',\r\n },\r\n classNames: {},\r\n};\r\n\r\nfunction init() {\r\n $(config.selectors.surveyDialog).each((i, el) => {\r\n const $surveyDialog = $(el);\r\n initSurveyDialog($surveyDialog);\r\n });\r\n}\r\n\r\nfunction initSurveyDialog($surveyDialog) {\r\n $surveyDialog.survey();\r\n}\r\n\r\ninit();\r\n"]}