{"version":3,"names":["$","window","jQuery","isSpanish","document","documentElement","lang","questions","nextLabel","ProgressBar","constructor","_ref","progressBarEl","levelCount","this","$progressBarEl","_levelCount","$bar","find","init","setLevel","level","addClass","percentage","css","concat","complete","ViewSwitch","_ref2","viewSwitchEl","views","$switchEl","Object","keys","reduce","acc","key","_setZindex","firstViewKey","$mounted","values","forEach","el","i","mount","view","RADIO_QUESTION_TEMPLATE","querySelector","content","firstElementChild","RADIO_OPTION_TEMPLATE","CHECKBOX_OPTION_TEMPLATE","RADIO_BUTTON_QUESTION_TEMPLATE","CHECKBOX_BUTTON_QUESTION_TEMPLATE","Question","_ref3","id","type","question","options","color","helperText","subtype","_id","_type","_subtype","_question","_helperText","_options","_color","_inputsName","$element","_arrowKeyPressed","getHeight","outerHeight","hide","removeClass","focusFirstInput","first","focus","appear","setTimeout","removeAttr","getElement","pass","unpass","IMAGES_BASE_URI","_window","LASIK_QUIZ_IMAGES_BASE_URI","ChoiceQuestion","onSelect","fn","_onSelect","_getOptionTemplate","isRadio","isButtonLayout","getView","$questionEl","clone","html","$subheadingEl","remove","$optionListEl","length","$nextBtn","$nextBtnWrapper","append","on","nextButton","optionTemplate","_ref4","text","image","$optionEl","_mapIndexToHex","$inputEl","attr","$imageEl","src","style","_attachEvents","event","$backBtn","activeElement","is","preventDefault","stopPropagation","startsWith","e","target","checked","anyChecked","toArray","some","chk","prop","index","QuizController","_ref5","container","questionObjs","$questionTrackEl","_questions","_currentQuestionIndex","_currentQuestion","currentQuestion","q","forward","isFirstQuestion","isLastQuestion","getCurrentQuestionIndex","getNextIndex","getPreviousIndex","_syncIndexToQuestion","_adjustHeight","nextQuestionIndex","back","prevQuestionIndex","EventEmitter","events","eventName","listener","push","emit","listeners","_len","arguments","args","Array","_key","apply","off","filter","l","ready","ee","$prevBtnEl","$startBtnEl","$submitButton","$viewSwitchEl","$quizView","$welcomeView","$leadView","$formEl","$loadScreen","progressBar","viewController","welcome","quiz","lead","map","qData","qObj","qType","qSubtype","console","log","quizController","hideButton","$button","showLoadingScreen","_quizController$curre","mask","$emailInput","$firstNameInput","$lastNameInput","errors","emailVal","val","test","firstName","lastName","phone","email","optIn","finalResultsPath","fetch","method","cache","headers","body","JSON","stringify","then","r","json","resp","finally","location","href","$formContainer","$focusable","currentIndex","eq"],"sources":["index.js"],"sourcesContent":["/*************************************************************\n * Imports\n *************************************************************/\n// 1. Import both question files\nimport questionsEn from \"../data/questions.json\";\nimport questionsEs from \"../data/questions-es.json\";\n\n// jQuery from window\nconst $ = window.jQuery;\n\n/*************************************************************\n * Detect Language & Define Globals\n *************************************************************/\n// Check if \nconst isSpanish = document.documentElement.lang === \"es-ES\";\n// Use Spanish or English questions\nconst questions = isSpanish ? questionsEs : questionsEn;\n// Where to redirect after submission\nconst resultsPath = isSpanish ? \"/es/cuestionario/resultados\" : \"/quiz/results\";\n// Next button label\nconst nextLabel = isSpanish ? \"Siguiente\" : \"Next\";\n\n/*************************************************************\n * ProgressBar\n *************************************************************/\nexport class ProgressBar {\n constructor({ progressBarEl, levelCount }) {\n this.$progressBarEl = progressBarEl instanceof jQuery ? progressBarEl : $(progressBarEl);\n this._levelCount = levelCount;\n this.$bar = this.$progressBarEl.find('.progress-bar__bar');\n }\n\n init() {\n this.setLevel(0);\n }\n\n setLevel(level) {\n if (level === this._levelCount) {\n this.$bar.addClass('progress-bar__bar--complete');\n }\n const percentage = (level / this._levelCount) * 100;\n this.$bar.css('width', `${percentage}%`);\n }\n\n complete() {\n this.setLevel(this._levelCount);\n }\n}\n\n/*************************************************************\n * ViewSwitch\n *************************************************************/\nexport class ViewSwitch {\n constructor({ viewSwitchEl, views = {} }) {\n this.$switchEl = viewSwitchEl instanceof jQuery ? viewSwitchEl : $(viewSwitchEl);\n this.views = Object.keys(views).reduce((acc, key) => {\n acc[key] = views[key] instanceof jQuery ? views[key] : $(views[key]);\n return acc;\n }, {});\n this._setZindex();\n const firstViewKey = Object.keys(this.views)[0];\n this.$mounted = this.views[firstViewKey];\n }\n\n _setZindex() {\n const viewValues = Object.values(this.views);\n viewValues.forEach((el, i) => {\n el.css('zIndex', i + 1);\n });\n }\n\n mount(view) {\n this.$mounted.addClass('view--exit');\n this.views[view].addClass('view--enter');\n this.$mounted = this.views[view];\n }\n}\n\n/*************************************************************\n * Template References\n *************************************************************/\nexport const RADIO_QUESTION_TEMPLATE = document.querySelector('#radio-question').content.firstElementChild;\nexport const RADIO_OPTION_TEMPLATE = document.querySelector('#radio-question-option').content.firstElementChild;\nexport const CHECKBOX_OPTION_TEMPLATE = document.querySelector('#checkbox-question-option').content.firstElementChild;\nexport const RADIO_BUTTON_QUESTION_TEMPLATE = document.querySelector('#radio-button-question-option').content.firstElementChild;\nexport const CHECKBOX_BUTTON_QUESTION_TEMPLATE = document.querySelector('#checkbox-button-question-option').content.firstElementChild;\n\n/*************************************************************\n * Base Question\n *************************************************************/\nexport class Question {\n constructor({ id, type, question, options, color, helperText, subtype }) {\n this._id = id;\n this._type = type; \n this._subtype = subtype; \n this._question = question;\n this._helperText = helperText;\n this._options = options || [];\n this._color = color;\n this._inputsName = `question-${this._id}`;\n\n this.$element = null;\n this._arrowKeyPressed = false;\n }\n\n getHeight() {\n return this.$element ? this.$element.outerHeight() : 0;\n }\n\n hide() {\n if (this.$element) {\n this.$element.removeClass('question--appear');\n }\n }\n\n focusFirstInput() {\n if (this.$element) {\n this.$element.find('input').first().focus();\n }\n }\n\n appear() {\n if (this.$element) {\n this.$element.addClass('question--appear');\n setTimeout(() => {\n this.$element.find('input').removeAttr('disabled');\n }, 300);\n }\n }\n\n getElement() {\n return this.$element;\n }\n\n pass() {\n if (this.$element) {\n this.$element.addClass('question--pass');\n }\n }\n\n unpass() {\n if (this.$element) {\n this.$element.removeClass('question--pass');\n }\n }\n}\n\n/*************************************************************\n * Constants\n *************************************************************/\nexport const DOB_REGEX = \"^\\\\d{2}\\\\/\\\\d{2}\\\\/\\\\d{4}$\";\n// In your JS file\nexport const IMAGES_BASE_URI =\n // Check if a global variable is defined\n window?.LASIK_QUIZ_IMAGES_BASE_URI\n // If yes, use that\n ? window.LASIK_QUIZ_IMAGES_BASE_URI\n // Otherwise, fallback to old path\n : \"/wp-content/themes/lasik/gutenberg/blocks/lasik-quiz/images\";\n\n\n/*************************************************************\n * ChoiceQuestion (Radio or Checkbox, Bubble or Buttons)\n *************************************************************/\nexport class ChoiceQuestion extends Question {\n onSelect(fn) {\n this._onSelect = fn;\n }\n\n /**\n * Return the correct