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,CACAuB,IAAAA,U,MAAAA,WACMhB,KAAK2F,OAAO3F,KAAK2F,MAAMzE,SAAQzB,SAAAA,G,OAAMA,EAAGuB,S,IAE5ChB,KAAKP,GAAK,KACVO,KAAK0F,QAAU,KACf1F,KAAK2F,MAAQ,IACf,G,CAEAE,IAAAA,Q,MAAAA,WAAU7F,KAAKe,aAAe,G,CAC9B+E,IAAAA,O,MAAAA,WACE9F,KAAKiB,gBAEDjB,KAAK2F,OAAQ3F,KAAK2F,MAAMzE,SAAQ6E,SAAAA,G,OAAQA,EAAK/E,S,IACjDhB,KAAK2F,MAAQ,IACf,G,CAEA5E,IAAAA,c,MAAAA,W,WACMf,KAAK2F,OAAQ3F,KAAK2F,MAAMzE,SAAQW,SAAAA,G,OAAQA,EAAKT,GAAG,SAAU,EAAKwE,c,GACrE,G,CACA3E,IAAAA,gB,MAAAA,W,WACMjB,KAAK2F,OAAQ3F,KAAK2F,MAAMzE,SAAQW,SAAAA,G,OAAQA,EAAKR,IAAI,SAAU,EAAKuE,c,GACtE,G,CAEAA,IAAAA,gB,MAAAA,WACE5F,KAAK0F,QAAQpE,KAAK,oBACpB,M,2BApCImE,C,CAwCH,E","sources":["webpack://moosehead/./src/js/core/locales.js","webpack://moosehead/./src/js/components/ContestCodeForm.js","webpack://moosehead/./src/js/ui/contest-code-checker/index.js"],"sourcesContent":["import IntlMessageFormat from \"intl-messageformat\";\n\nexport const defaultLocale = \"fr\";\n\nconst MESSAGES = {\n fr: {\n 'My String': 'Ma string',\n },\n en: {\n 'My String': 'My string',\n }\n};\n\nexport const getCurrentlocale = () => (typeof MILL3WP.locale !== \"undefined\" ? MILL3WP.locale : defaultLocale);\n\nexport const getMessage = ID => {\n const locale = getCurrentlocale();\n try {\n const msg = new IntlMessageFormat(MESSAGES[`${locale}`][ID], defaultLocale);\n return msg ? msg.format() : ID;\n } catch (error) {\n return ID;\n }\n};\n\nexport default getMessage;\n","/*\n ContestCodeForm : handles form validation for the contest-code-checker (https://wordpress.org/plugins/contest-code-checker/) plugin because plugin has poor validation support\n Also handles translation of labels, placeholders and error messages with | separator(s) for different locales\n*/\n\n/* eslint-disable no-undef */\nimport EventEmitter2 from \"eventemitter2\";\n\nimport { getCurrentlocale } from \"@core/locales\";\nimport { $, $$ } from \"@utils/dom\";\nimport { on, off } from \"@utils/listener\";\n\nconst SELECTOR_INPUTS = \"input:not([type='hidden']), textarea, select\";\nconst SELECTOR_EMAIL = \"input#contestants_email\";\nconst SELECTOR_DATE_OF_BIRTH = \"input[placeholder*='Date of Birth'], input[type='date']\";\nconst SELECTOR_FILE_UPLOAD = \"input[type='file']\";\nconst SELECTOR_CHECKBOX = \"input[type='checkbox'],input[type='radio']\";\nconst SELECTOR_RECAPTCHA = \"input.hiddenRecaptcha\";\n\nconst PROVINCE_CODES = {\n \"Alberta\": \"AB\",\n \"British-Columbia\": \"BC\",\n \"Manitoba\": \"MB\",\n \"New-Brunswick\": \"NB\",\n \"Newfoundland & Labrador\": \"NL\",\n \"Nova-Scotia\": \"NS\",\n \"NorthwestTerritories\": \"NT\",\n \"Nunavut\": \"NU\",\n \"Ontario\": \"ON\",\n \"Prince Edward Island\": \"PE\",\n \"Québec\": \"QC\",\n \"Saskatchewan\": \"SK\",\n \"Yukon\": \"YT\",\n};\nconst AGE_MAJORITY_DEFAULT = 18;\nconst AGE_MAJORITY = {\n AB: 18,\n BC: 19,\n MB: 18,\n NB: 19,\n NL: 19,\n NS: 19,\n NT: 19,\n NU: 19,\n ON: 18,\n PE: 19,\n QC: 18,\n SK: 18,\n YT: 19,\n};\nconst ERROR_MESSAGES = {\n FILE_SIZE: \"File size must be under 5MB\",\n EMAIL: \"A valid email is required\",\n REQUIRED: \"This field is required\",\n FILE: \"A file is required\",\n};\n\nclass ContestCodeForm extends EventEmitter2 {\n constructor(el) {\n super();\n this.el = el;\n this.inputs = $$(SELECTOR_INPUTS, this.el);\n this._onValidate = this._onValidate.bind(this);\n this._onSubmit = this._onSubmit.bind(this);\n this.init();\n }\n\n init() {\n // remove built-in validation on form\n this.el.setAttribute(\"novalidate\", \"novalidate\");\n\n // register all fields base on their type\n this.fields = [...this.inputs].map((input, index) => {\n const type = input.nodeName.toLowerCase();\n if (input.matches(SELECTOR_EMAIL)) {\n return new ContestCodeEmailField(input, type, index);\n } else if (input.matches(SELECTOR_DATE_OF_BIRTH)) {\n return new ContestCodeDateOfBirthField(input, \"date\", index);\n } else if (input.matches(SELECTOR_CHECKBOX)) {\n return new ContestCodeCheckboxField(input, \"checkbox\", index);\n } else if (input.matches(SELECTOR_FILE_UPLOAD)) {\n return new ContestCodeFileField(input, \"file\", index);\n } else {\n return new ContestCodeField(input, type, index);\n }\n });\n\n this._bindEvents();\n }\n\n destroy() {\n this._unbindEvents();\n this.fields.forEach((field) => field.destroy());\n this.fields = null;\n this.inputs = null;\n this.el = null;\n }\n\n _bindEvents() {\n this.fields.forEach((field) => field.on(\"validate\", this._onValidate));\n on(this.el, \"submit\", this._onSubmit);\n }\n\n _unbindEvents() {\n this.fields.forEach((field) => field.off(\"validate\", this._onValidate));\n off(this.el, \"submit\", this._onSubmit);\n }\n\n _onValidate() {\n this.emit(\"update\");\n }\n\n _onSubmit(e) {\n // trigger validation on all fields\n this.fields.forEach((field) => field._validate());\n\n // check if all fields are valid\n const isValid = this.fields.every((field) => field.valid);\n\n // prevent form submission if not valid\n if (!isValid) e.preventDefault();\n\n // emit submit event\n this.emit(\"update\");\n }\n}\n\n// main class for all fields\nclass ContestCodeField extends EventEmitter2 {\n constructor(input, type, index) {\n super();\n this.form = input.form;\n this.input = input;\n this.type = type;\n this.value = true;\n this.valid = null;\n this.index = index + 1; // avoid 0 based index\n this.parent = this.input.parentElement;\n this.label = $(\"label\", this.parent);\n this.errorMessage = this.input.getAttribute(\"data-msg\") || ERROR_MESSAGES.REQUIRED;\n this.validateOnBlur = true;\n\n this._focus = this._focus.bind(this);\n this._blur = this._blur.bind(this);\n this._change = this._change.bind(this);\n this._validate = this._validate.bind(this);\n\n this.init();\n }\n\n init() {\n this.parent.classList.add(`--field-${this.index}`);\n this.parent.classList.add(`--type-${this.type}`);\n this._bindEvents();\n this._customBindEvents();\n this.translate();\n this.setPlaceholder();\n\n // set --index style on element\n this.parent.style = `--index: ${this.index}`;\n }\n\n destroy() {\n this._unbindEvents();\n this._customUnbindEvents();\n this.form = null;\n this.input = null;\n this.index = null;\n this.parent = null;\n this.label = null;\n }\n\n // the plugin doesn't have a way to translate the label text content, so we need to do it manually\n // by splitting the text content by the pipe character and then selecting the correct text based on the current locale\n // example: \"My String|Ma ligne\" will display \"My String\" if the current locale is \"en\" and \"Ma ligne\" if the current locale is \"fr\"\n translate() {\n if (!this.label && !this.input) return;\n\n // translate label\n const labelValue = this.label ? this.label.textContent : \"\";\n const parts = labelValue.split(\"|\");\n if (parts.length > 1) {\n this.label.innerHTML = parts[getCurrentlocale() === \"fr\" ? 1 : 0];\n }\n\n // translate placeholder\n const placeholder = this.input.getAttribute(\"placeholder\");\n const placeholderParts = placeholder ? placeholder.split(\"|\") : [];\n if (placeholderParts.length > 1) {\n this.input.setAttribute(\"placeholder\", placeholderParts[getCurrentlocale() === \"fr\" ? 1 : 0]);\n }\n\n // translate error message\n const errorMessageParts = this.errorMessage.split(\"|\");\n if (errorMessageParts.length > 1) {\n this.errorMessage = errorMessageParts[getCurrentlocale() === \"fr\" ? 1 : 0];\n }\n }\n\n // The plugin doesn't expose a placeholder attribute for each type of inputs, only custom fields has the placeholder attribute\n // so we need to set the placeholder attribute manually using the label text content\n setPlaceholder() {\n if (!this.label) return;\n if (this.input.hasAttribute(\"placeholder\")) return;\n const value = this.label?.textContent;\n this.input.setAttribute(\"placeholder\", value);\n }\n\n _bindEvents() {\n on(this.input, \"focus\", this._focus);\n on(this.input, \"blur\", this._blur);\n on(this.input, \"change\", this._change);\n }\n\n _unbindEvents() {\n off(this.input, \"focus\", this._focus);\n off(this.input, \"blur\", this._blur);\n off(this.input, \"change\", this._change);\n }\n\n _customBindEvents() { } // void by default\n _customUnbindEvents() { } // void by default\n\n _focus() {\n this.parent.classList.add(\"--focus\");\n }\n\n _blur() {\n this.parent.classList.toggle(\"--filled\", this.input.value.length > 0);\n this.parent.classList.remove(\"--focus\");\n if(this.validateOnBlur) this._validate();\n }\n\n _validate() {\n this.valid = this.input.checkValidity();\n if (!this.valid) this._showError();\n else this._hideError();\n this.emit(\"validate\");\n }\n\n _change() { } // void by default\n\n // Error messages are displayed attached to the parent element\n // using an ::after pseudo element using \"content: attr(data-error);\"\n _showError() {\n this.parent.setAttribute(\"data-error\", this.errorMessage);\n this.parent.classList.add(\"--error\");\n }\n\n _hideError() {\n this.parent.removeAttribute(\"data-error\");\n this.parent.classList.remove(\"--error\");\n }\n}\n\nclass ContestCodeFileField extends ContestCodeField {\n constructor(input, type, index) {\n super(input, type, index);\n this.validateOnBlur = false;\n this.errorMessage = this.input.getAttribute(\"data-msg\") || ERROR_MESSAGES.FILE;\n this.labelText = this.label.textContent;\n this._validate = this._validate.bind(this);\n }\n init() {\n super.init();\n // set allowed file types\n this.input.setAttribute(\"accept\", \"image/jpg, image/png, image/jpeg, image/gif\");\n }\n\n _customBindEvents() {\n on(this.input, \"change\", this._change);\n }\n\n _customUnbindEvents() {\n off(this.input, \"change\", this._change);\n }\n\n // set filename on label once file is selected\n _change(event) {\n const filename = event.target.files[0]?.name;\n if(filename) {\n this.label.textContent = filename;\n } else {\n this.label.textContent = this.labelText;\n }\n }\n\n _validate() {\n // Custom validation logic\n const file = this.input.files[0];\n if (file && file.size > 5 * 1024 * 1024) {\n this.errorMessage = ERROR_MESSAGES.FILE_SIZE;\n this.input.setCustomValidity(this.errorMessage);\n this.valid = false;\n this._showError();\n } else {\n this.input.setCustomValidity(\"\");\n this.valid = true;\n this._hideError();\n }\n\n // Call base validation\n super._validate();\n }\n}\n\nclass ContestCodeEmailField extends ContestCodeField {\n constructor(input, type, index) {\n super(input, type, index);\n this.errorMessage = this.input.getAttribute(\"data-msg\") || ERROR_MESSAGES.EMAIL;\n\n }\n init() {\n super.init();\n this.input.setAttribute(\"type\", \"email\");\n }\n\n}\n\nclass ContestCodeCheckboxField extends ContestCodeField {\n constructor(input, type, index) {\n super(input, type, index);\n }\n // Note: this works only if a is manually added in the CMS for the checkbox or radio type custom fields\n translate() {\n // find a parent label element\n const label = $(\"label\", this.parent);\n if(!label) {\n super.translate();\n return;\n }\n\n // translate label\n const labelValue = label ? label.innerHTML : \"\";\n const parts = labelValue.split(\"|\");\n\n if (parts.length > 1) {\n label.innerHTML = parts[getCurrentlocale() === \"fr\" ? 1 : 0];\n }\n\n super.translate();\n }\n}\n\nclass ContestCodeDateOfBirthField extends ContestCodeField {\n constructor(input, type, index) {\n super(input, type, index);\n this.errorMessage = this.input.getAttribute(\"data-msg\") || `You must be at least ${AGE_MAJORITY_DEFAULT} years old.`;\n this._validate = this._validate.bind(this);\n }\n\n init() {\n super.init();\n this.input.setAttribute(\"type\", \"date\");\n }\n\n destroy() {\n super.destroy();\n }\n\n _validate() {\n super.translate(); // re-call translation to update error message\n\n const today = new Date();\n const dobValue = new Date(this.input.value);\n\n // find province code from parent form and get age majority for selected province\n // This will only works if the select element has the placeholder attribute with the \"Province\" value\n const provinceSelect = this.form.querySelector(\"select[placeholder*='Province']\");\n const provinceName = provinceSelect?.value;\n const province = PROVINCE_CODES[provinceName];\n const ageMajority = AGE_MAJORITY[province] ?? AGE_MAJORITY_DEFAULT;\n\n // regex any number in this.errorMessage\n const regex = /(\\d+)/;\n const match = this.errorMessage.match(regex);\n if (match) {\n this.errorMessage = this.errorMessage.replace(regex, ageMajority);\n }\n\n // Calculate age\n let age = today.getFullYear() - dobValue.getFullYear();\n let monthDiff = today.getMonth() - dobValue.getMonth();\n let dayDiff = today.getDate() - dobValue.getDate();\n\n // Adjust age if birthdate hasn't occurred yet this year\n if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {\n age--;\n }\n\n if (age < ageMajority) {\n this.input.setCustomValidity(this.errorMessage);\n } else {\n // Reset error state and set as valid\n this.input.setCustomValidity(\"\");\n }\n\n this.valid = this.input.checkValidity();\n if (!this.valid) this._showError();\n else this._hideError();\n\n // emit validate event\n this.emit(\"validate\");\n }\n}\n\n// class ContestCodeRecaptchaField extends ContestCodeField {\n// constructor(input, index) {\n// super(input, index);\n// this.label = null;\n// this._onInput = this._onInput.bind(this);\n// }\n// init() {\n// super.init();\n// this.input.setAttribute(\"required\", \"required\");\n// }\n// }\n\nexport default ContestCodeForm;\n\n","import ContestCodeForm from \"@components/ContestCodeForm\";\nimport { $$ } from \"@utils/dom\";\n// import Throttle from \"@utils/throttle\";\n\nexport const SELECTOR = `.contest_code_checker_pro_form`;\n\nclass ContestCodeCheckerFactory {\n constructor(el, emitter) {\n this.el = el;\n this.emitter = emitter;\n this.items = null;\n this._onFormUpdate = this._onFormUpdate.bind(this);\n }\n\n init() {\n this.items = [...$$(SELECTOR, this.el)].map(el => new ContestCodeForm(el));\n }\n destroy() {\n if (this.items) this.items.forEach(el => el.destroy());\n\n this.el = null;\n this.emitter = null;\n this.items = null;\n }\n\n start() { this._bindEvents(); }\n stop() {\n this._unbindEvents();\n\n if( this.items ) this.items.forEach(item => item.destroy());\n this.items = null;\n }\n\n _bindEvents() {\n if( this.items ) this.items.forEach(form => form.on('update', this._onFormUpdate));\n }\n _unbindEvents() {\n if( this.items ) this.items.forEach(form => form.off('update', this._onFormUpdate));\n }\n\n _onFormUpdate() {\n this.emitter.emit(\"SiteScroll.update\");\n }\n\n}\n\nexport default ContestCodeCheckerFactory;\n"],"names":["getCurrentlocale","MILL3WP","locale","PROVINCE_CODES","AGE_MAJORITY","AB","BC","MB","NB","NL","NS","NT","NU","ON","PE","QC","SK","YT","ERROR_MESSAGES","ContestCodeForm","el","inputs","$$","_onValidate","bind","_onSubmit","init","this","setAttribute","fields","map","input","index","type","nodeName","toLowerCase","matches","ContestCodeEmailField","ContestCodeDateOfBirthField","ContestCodeCheckboxField","ContestCodeFileField","ContestCodeField","_bindEvents","destroy","_unbindEvents","forEach","field","on","off","emit","e","_validate","every","valid","preventDefault","EventEmitter2","form","value","parent","parentElement","label","$","errorMessage","getAttribute","validateOnBlur","_focus","_blur","_change","classList","add","_customBindEvents","translate","setPlaceholder","style","_customUnbindEvents","parts","textContent","split","length","innerHTML","placeholder","placeholderParts","errorMessageParts","hasAttribute","toggle","remove","checkValidity","_hideError","_showError","removeAttribute","labelText","event","filename","target","files","name","file","size","setCustomValidity","today","Date","dobValue","provinceSelect","querySelector","provinceName","ageMajority","regex","match","replace","age","getFullYear","monthDiff","getMonth","dayDiff","getDate","SELECTOR","ContestCodeCheckerFactory","emitter","items","_onFormUpdate","start","stop","item"],"sourceRoot":""}