|
| 1 | +;(function () { |
| 2 | + 'use strict' |
| 3 | + |
| 4 | + var feedbackFormOptionButtons = document.querySelector('.feedback-form-options').querySelectorAll('button') |
| 5 | + if (!feedbackFormOptionButtons) return |
| 6 | + |
| 7 | + feedbackFormOptionButtons.forEach((button) => { |
| 8 | + button.addEventListener('click', selectFeedbackFormOptionButton) |
| 9 | + }) |
| 10 | + |
| 11 | + function selectFeedbackFormOptionButton (e) { |
| 12 | + e.stopPropagation() // trap event |
| 13 | + feedbackFormOptionButtons.forEach((button) => { |
| 14 | + if (button === this) { |
| 15 | + this.classList.add('selected') |
| 16 | + } else { |
| 17 | + button.classList.remove('selected') |
| 18 | + } |
| 19 | + }) |
| 20 | + |
| 21 | + var feedbackFormText = document.querySelector('.feedback-form-text') |
| 22 | + if (!feedbackFormText) return |
| 23 | + |
| 24 | + feedbackFormText.classList.remove('hide') |
| 25 | + } |
| 26 | + |
| 27 | + var feedbackFormSubmitButton = document.querySelector('.feedback-form-submit-button') |
| 28 | + if (!feedbackFormSubmitButton) return |
| 29 | + |
| 30 | + var feedbackFormTextArea = document.querySelector('.feedback-form-text textarea') |
| 31 | + if (!feedbackFormTextArea) return |
| 32 | + |
| 33 | + feedbackFormSubmitButton.addEventListener('click', submitFeedback) |
| 34 | + |
| 35 | + function submitFeedback (e) { |
| 36 | + e.stopPropagation() // trap event |
| 37 | + feedbackFormSubmitButton.classList.add('selected') |
| 38 | + |
| 39 | + // TODO: Submit feedback to backend, alternatively let netlify handle it |
| 40 | + |
| 41 | + feedbackFormSubmitButton.innerText = 'Submitted' |
| 42 | + feedbackFormSubmitButton.disabled = true |
| 43 | + feedbackFormTextArea.disabled = true |
| 44 | + |
| 45 | + feedbackFormOptionButtons.forEach((button) => { |
| 46 | + button.disabled = true |
| 47 | + }) |
| 48 | + |
| 49 | + var feedbackFormThankYou = document.querySelector('.feedback-form-thank-you') |
| 50 | + if (!feedbackFormThankYou) return |
| 51 | + |
| 52 | + feedbackFormThankYou.classList.remove('hide') |
| 53 | + } |
| 54 | +})() |
0 commit comments