2023-02-17 16:59:59 -05:00
|
|
|
const yesButton = document.getElementById('yes');
|
|
|
|
const noButton = document.getElementById('no');
|
|
|
|
const numCharsLabel = document.getElementById('num-chars');
|
|
|
|
const sendButton = document.getElementById('send');
|
|
|
|
const commentTextArea = document.getElementById('comment');
|
|
|
|
const thankYouText = document.getElementById('thank-you');
|
2024-01-16 13:11:25 -05:00
|
|
|
const nav = document.getElementById('site-nav');
|
|
|
|
const versionPanel = document.getElementById('version-panel');
|
2023-02-17 16:59:59 -05:00
|
|
|
document.addEventListener('DOMContentLoaded', updateTextArea);
|
|
|
|
|
2022-12-27 11:45:32 -05:00
|
|
|
document.addEventListener('click', function(event) {
|
|
|
|
const { target } = event;
|
|
|
|
if (target.matches('.feedback-issue')) {
|
|
|
|
gtag('event', 'submit_issue_click');
|
|
|
|
}
|
|
|
|
else if (target.matches('.feedback-edit')) {
|
|
|
|
gtag('event', 'edit_page_click');
|
|
|
|
}
|
2023-10-31 15:29:28 -04:00
|
|
|
else if (target.matches('.feedback-forum')) {
|
|
|
|
gtag('event', 'forum_link_click');
|
|
|
|
}
|
2022-12-27 11:45:32 -05:00
|
|
|
else if (target.matches('.feedback-button')) {
|
2023-02-17 16:59:59 -05:00
|
|
|
sendButton.disabled = false;
|
|
|
|
}
|
|
|
|
else if (target.matches('.send-button')) {
|
|
|
|
sendFeedback();
|
2022-12-27 11:45:32 -05:00
|
|
|
}
|
|
|
|
else if (target.matches('.copy-button')) {
|
|
|
|
window.navigator.clipboard.writeText(target.getAttribute('data-text'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-16 13:11:25 -05:00
|
|
|
nav.addEventListener('scroll',(e)=>{
|
|
|
|
if(nav.scrollTop > 0){
|
|
|
|
versionPanel.classList.add("nav-shadow");
|
|
|
|
}else{
|
|
|
|
versionPanel.classList.remove("nav-shadow");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-17 16:59:59 -05:00
|
|
|
commentTextArea.addEventListener('input', updateTextArea);
|
|
|
|
|
|
|
|
function updateTextArea() {
|
|
|
|
const text = commentTextArea.value.trim();
|
|
|
|
|
|
|
|
if (!yesButton.checked && !noButton.checked) {
|
|
|
|
text.length > 0 ? sendButton.disabled = false : sendButton.disabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// calculate the number of characters remaining
|
|
|
|
counter = 350 - commentTextArea.value.length;
|
|
|
|
numCharsLabel.innerText = counter + " characters left";
|
|
|
|
}
|
|
|
|
|
|
|
|
function sendFeedback() {
|
|
|
|
let helpful = 'none';
|
|
|
|
if (yesButton.checked) {
|
|
|
|
helpful = 'yes';
|
|
|
|
}
|
|
|
|
else if (noButton.checked) {
|
|
|
|
helpful = 'no';
|
|
|
|
}
|
|
|
|
|
|
|
|
let comment = commentTextArea.value.trim();
|
|
|
|
if(comment.length == 0) {
|
|
|
|
comment = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (helpful === 'none' && comment === 'none') return;
|
|
|
|
|
2023-02-28 15:18:02 -05:00
|
|
|
// split the comment into 100-char parts because of GA limitation on custom dimensions
|
|
|
|
const commentLines = ["", "", "", ""];
|
|
|
|
for (let i = 0; i <= (comment.length - 1)/100; i++) {
|
|
|
|
commentLines[i] = comment.substring(i * 100, Math.min((i + 1)*100, comment.length));
|
|
|
|
}
|
|
|
|
|
2022-12-27 11:45:32 -05:00
|
|
|
gtag('event', 'feedback_click', {
|
2023-02-17 16:59:59 -05:00
|
|
|
'helpful': helpful,
|
2023-02-28 15:18:02 -05:00
|
|
|
'comment': commentLines[0],
|
|
|
|
'comment_2': commentLines[1],
|
|
|
|
'comment_3': commentLines[2],
|
|
|
|
'comment_4': commentLines[3],
|
2022-12-27 11:45:32 -05:00
|
|
|
});
|
2023-02-17 16:59:59 -05:00
|
|
|
|
2022-12-27 11:45:32 -05:00
|
|
|
// show the hidden feedback text
|
2023-02-17 16:59:59 -05:00
|
|
|
thankYouText.classList.remove('hidden');
|
2022-12-27 11:45:32 -05:00
|
|
|
|
|
|
|
// disable the feedback buttons
|
2023-02-17 16:59:59 -05:00
|
|
|
yesButton.disabled = true;
|
|
|
|
noButton.disabled = true;
|
|
|
|
|
|
|
|
// disable the text area
|
|
|
|
commentTextArea.disabled = true;
|
|
|
|
|
|
|
|
// disable the send button
|
|
|
|
sendButton.disabled = true;
|
|
|
|
}
|