forked from JetBrains/kotlin-web-site
-
Notifications
You must be signed in to change notification settings - Fork 421
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JetBrains#4169 from JetBrains/fix-issues
Add Core API form feedback
- Loading branch information
Showing
5 changed files
with
1,794 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
function closePopup() { | ||
document.querySelector('.app-feedback-popup').classList.add('app-feedback-popup_close'); | ||
} | ||
|
||
function showThanks() { | ||
document.querySelector('.feedback__block--active').classList.remove('feedback__block--active'); | ||
document.querySelector('[data-test="feedback-left"]').classList.add('feedback__block--active'); | ||
} | ||
|
||
function toggleEmail(val) { | ||
const email = document.querySelector('[data-test-id="feedback-email"]'); | ||
email.setAttribute('aria-invalid', String(!val)); | ||
|
||
const classes = email.parentNode.parentNode.parentNode.parentNode.classList; | ||
classes.toggle('_error_1fowpgw_83', !val); | ||
classes.toggle('input_error', !val); | ||
} | ||
|
||
function toggleSubmit(val) { | ||
const submit = document.querySelector('[data-test="feedback-send"]'); | ||
submit.toggleAttribute('disabled', !val); | ||
|
||
const classes = submit.classList; | ||
classes.toggle('_disabled_joawza_61', !val); | ||
classes.toggle('button_disabled', !val); | ||
} | ||
|
||
export function initFeedback() { | ||
const feedback = document.querySelector('.feedback'); | ||
|
||
if (feedback) { | ||
feedback.querySelector('[data-test="feedback-yes"]').addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
closePopup(); | ||
showThanks(); | ||
}); | ||
|
||
feedback.querySelector('[data-test="feedback-no"]').addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
document.querySelector('.app-feedback-popup').classList.remove('app-feedback-popup_close'); | ||
}); | ||
} | ||
|
||
const form = document.querySelector('.app-feedback-popup form'); | ||
|
||
if (form) { | ||
const fields = form.elements; | ||
|
||
form.querySelector('[data-test="feedback-close"]').addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
closePopup(); | ||
}); | ||
|
||
form.addEventListener('input', function() { | ||
const emailValid = fields.email.value === '' || fields.email.validity.valid; | ||
|
||
toggleEmail(emailValid); | ||
toggleSubmit(fields.content.value !== '' && emailValid); | ||
}); | ||
|
||
form.addEventListener('submit', function(e) { | ||
e.preventDefault(); | ||
|
||
const content= document.getElementById('content'); | ||
const articleId = content && content.getAttribute('pageids'); | ||
const titleNode = document.querySelector('h1.cover'); | ||
const title = titleNode && titleNode.textContent; | ||
|
||
window.fetch('https://forms-service.jetbrains.com/feedback', { | ||
method: 'POST', | ||
mode: 'cors', | ||
credentials: 'omit', | ||
headers: { | ||
'content-type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
content: fields.content.value || '', | ||
name: fields.name.value || '', | ||
email: fields.email.value || '', | ||
url: document.location.href || '', | ||
articleId: articleId || 'core-api', | ||
title: title || 'Core API: Untitled' | ||
}) | ||
}); | ||
|
||
showThanks(); | ||
closePopup(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.