-
Notifications
You must be signed in to change notification settings - Fork 1
/
feedback.js
163 lines (138 loc) · 4.31 KB
/
feedback.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
document.addEventListener('DOMContentLoaded', () => {
const starsContainers = document.getElementsByClassName("stars");
const ratingTexts = document.querySelectorAll('[id$="-rating-text"]');
let currentRating = 0;
function colourStar(ind , container) {
let s = container.querySelectorAll("span");
s = Array.from(s);
// remove existing rating
for(let i = 0; i < s.length; i++) {
s[i].style.color = "white";
}
for(let i = 0; i < ind; i++) {
s[i].style.color = "#FFA500";
}
// console.log(container);
}
// Create 5 stars dynamically for each stars container
Array.from(starsContainers).forEach((starsContainer, index) => {
for (let i = 1; i <= 5; i++) {
const star = document.createElement('span');
star.classList.add('star');
star.innerHTML = '★';
star.setAttribute('data-rating', i);
starsContainer.appendChild(star);
star.addEventListener('click', () => {
currentRating = i;
updateRating(index);
colourStar(i , starsContainer);
});
}
});
const updateRating = (index) => {
ratingTexts[index].textContent = `Rating: ${currentRating}`;
};
});
function submitFeedback() {
var feedbackInput = document.getElementById("feedback-input");
var feedback = feedbackInput.value.trim();
// Check if the feedback is empty
if (feedback === "") {
// Show a SweetAlert error modal
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Please enter your feedback before submitting.',
});
return; // Exit the function if feedback is empty
}
Swal.fire({
icon: 'success',
title: 'Success!',
text: 'Your response has been recorded.',
}).then((result) => {
// Clear the feedback input box after the user acknowledges the success modal
if (result.isConfirmed || result.isDismissed) {
feedbackInput.value = "";
}
});
}
// JS FOR ACCESSIBILITY
var screenReaderEnabled = false;
var voiceRecognitionEnabled = false;
function toggleAccessibilityMenu() {
var menu = document.getElementById("accessibilityMenu");
menu.classList.toggle("active");
}
function toggleScreenReader() {
screenReaderEnabled = !screenReaderEnabled;
var menuButton = document.getElementById("screenReaderButton");
if (screenReaderEnabled) {
speakText("Screen reader enabled");
menuButton.innerText = "Disable Screen Reader";
document.body.classList.add("screen-reader-enabled");
setTimeout(toggleAccessibilityMenu, 5000);
} else {
speakText("Screen reader disabled");
menuButton.innerText = "Enable Screen Reader";
document.body.classList.remove("screen-reader-enabled");
toggleAccessibilityMenu();
}
}
function speakText(text) {
if (screenReaderEnabled) {
var utterance = new SpeechSynthesisUtterance(text);
window.speechSynthesis.speak(utterance);
}
}
function stopSpeaking() {
window.speechSynthesis.cancel();
}
function toggleVoiceRecognition() {
voiceRecognitionEnabled = !voiceRecognitionEnabled;
var menuButton = document.getElementById("voiceRecognitionButton");
if (voiceRecognitionEnabled) {
startVoiceRecognition();
menuButton.innerText = "Disable voice recognition";
} else {
stopVoiceRecognition();
menuButton.innerText = "Enable voice recognition";
toggleAccessibilityMenu();
}
}
function startVoiceRecognition() {
if (annyang) {
annyang.start();
speakText("Voice recognition enabled");
}
}
function stopVoiceRecognition() {
if (annyang) {
annyang.abort();
speakText("Voice recognition disabled");
}
}
// Voice commands
if (annyang) {
var commands = {
'enable voice recognition': toggleVoiceRecognition,
'disable voice recognition': toggleVoiceRecognition,
'submit': submit,
'go to feedback': focusOnfeedback,
'enter feedback *feedback': enterfeedback,
};
annyang.addCommands(commands);
annyang.debug(true);
}
// function submit() {
// var submit = document.getElementById('myButton');
// if (submit) {
// button.click();
// }
// };
function focusOnfeedback() {
document.getElementById('feedback-input').focus();
}
function enterfeedback(fb) {
document.getElementById('feedback-input').value = fb;
}