|
189 | 189 | } |
190 | 190 | } |
191 | 191 | </style> |
192 | | - |
193 | | -<script> |
194 | | -function initFeedbackWidget() { |
195 | | - const stars = document.querySelectorAll(".rating-stars .star"); |
196 | | - const feedbackForm = document.getElementById("feedback-form"); |
197 | | - const feedbackTextarea = document.getElementById("feedback-text"); |
198 | | - const emailInput = document.getElementById("feedback-email"); |
199 | | - const submitButton = document.getElementById("submit-feedback"); |
200 | | - const statusDiv = document.getElementById("feedback-status"); |
201 | | - const closeButton = document.getElementById("close-feedback"); |
202 | | - const notification = document.getElementById("feedback-notification"); |
203 | | - const submitNotification = document.getElementById("feedback-submit-notification"); |
204 | | - |
205 | | - if (!stars.length || !feedbackForm) return; |
206 | | - |
207 | | - const formURL = "https://docs.google.com/forms/d/e/1FAIpQLSfhscELpzoXB4uyh9pXNmXSeqKc10IH_DxmAoaVGID85sO0Aw/formResponse"; |
208 | | - const fieldIds = { |
209 | | - rating: "entry.303027158", |
210 | | - pageUrl: "entry.295622433", |
211 | | - feedback: "entry.2131350495", |
212 | | - email: "entry.1689727303" |
213 | | - }; |
214 | | - |
215 | | - let selectedRating = 0; |
216 | | - let notificationTimeout; |
217 | | - |
218 | | - function showNotification(msg) { |
219 | | - notification.textContent = msg; |
220 | | - notification.style.display = "block"; |
221 | | - clearTimeout(notificationTimeout); |
222 | | - notificationTimeout = setTimeout(() => { |
223 | | - notification.style.display = "none"; |
224 | | - }, 3000); |
225 | | - } |
226 | | - |
227 | | - function sendRatingOnly(rating) { |
228 | | - const formData = new FormData(); |
229 | | - formData.append(fieldIds.rating, rating); |
230 | | - formData.append(fieldIds.pageUrl, window.location.href); |
231 | | - |
232 | | - fetch(formURL, { |
233 | | - method: "POST", |
234 | | - mode: "no-cors", |
235 | | - body: formData |
236 | | - }).catch(() => { |
237 | | - console.warn("Rating failed to submit silently."); |
238 | | - }); |
239 | | - } |
240 | | - |
241 | | - function submitFeedback(rating, feedbackText = "", email = "") { |
242 | | - const formData = new FormData(); |
243 | | - formData.append(fieldIds.rating, rating); |
244 | | - formData.append(fieldIds.pageUrl, window.location.href); |
245 | | - formData.append(fieldIds.feedback, feedbackText); |
246 | | - if (email) formData.append(fieldIds.email, email); |
247 | | - |
248 | | - fetch(formURL, { |
249 | | - method: "POST", |
250 | | - mode: "no-cors", |
251 | | - body: formData |
252 | | - }).then(() => { |
253 | | - statusDiv.style.color = ""; |
254 | | - feedbackTextarea.value = ""; |
255 | | - emailInput.value = ""; |
256 | | - feedbackForm.style.display = "none"; |
257 | | - selectedRating = 0; |
258 | | - |
259 | | - stars.forEach((s) => { |
260 | | - s.textContent = "☆"; |
261 | | - s.classList.remove("active"); |
262 | | - s.classList.remove("hovered"); |
263 | | - }); |
264 | | - |
265 | | - // ✅ Show post-submit thank-you notification |
266 | | - submitNotification.style.display = "block"; |
267 | | - clearTimeout(notificationTimeout); |
268 | | - notificationTimeout = setTimeout(() => { |
269 | | - submitNotification.style.display = "none"; |
270 | | - }, 4000); |
271 | | - }).catch(() => { |
272 | | - statusDiv.style.color = ""; |
273 | | - statusDiv.textContent = "Error sending feedback."; |
274 | | - }); |
275 | | - } |
276 | | - |
277 | | - stars.forEach((star) => { |
278 | | - const rating = parseInt(star.dataset.rating, 10); |
279 | | - |
280 | | - star.addEventListener("mouseover", () => { |
281 | | - stars.forEach((s, index) => { |
282 | | - s.textContent = index < rating ? "★" : "☆"; |
283 | | - if(index < rating) { |
284 | | - s.classList.add("hovered"); |
285 | | - s.classList.remove("active"); |
286 | | - } else { |
287 | | - s.classList.remove("hovered"); |
288 | | - s.classList.remove("active"); |
289 | | - } |
290 | | - }); |
291 | | - }); |
292 | | - |
293 | | - star.addEventListener("mouseleave", () => { |
294 | | - stars.forEach((s, index) => { |
295 | | - s.textContent = index < selectedRating ? "★" : "☆"; |
296 | | - if(index < selectedRating) { |
297 | | - s.classList.add("active"); |
298 | | - } else { |
299 | | - s.classList.remove("active"); |
300 | | - } |
301 | | - s.classList.remove("hovered"); |
302 | | - }); |
303 | | - }); |
304 | | - |
305 | | - star.addEventListener("click", () => { |
306 | | - selectedRating = rating; |
307 | | - |
308 | | - stars.forEach((s, index) => { |
309 | | - s.textContent = index < rating ? "★" : "☆"; |
310 | | - if(index < rating) { |
311 | | - s.classList.add("active"); |
312 | | - } else { |
313 | | - s.classList.remove("active"); |
314 | | - } |
315 | | - s.classList.remove("hovered"); |
316 | | - }); |
317 | | - |
318 | | - sendRatingOnly(rating); |
319 | | - feedbackForm.style.display = "block"; |
320 | | - statusDiv.textContent = ""; |
321 | | - }); |
322 | | - }); |
323 | | - |
324 | | - submitButton.addEventListener("click", () => { |
325 | | - if (!selectedRating) return; |
326 | | - const feedbackText = feedbackTextarea.value.trim(); |
327 | | - const email = emailInput.value.trim(); |
328 | | - |
329 | | - if (selectedRating < 5 && !feedbackText) { |
330 | | - statusDiv.style.color = ""; |
331 | | - statusDiv.textContent = "Write feedback before sending."; |
332 | | - return; |
333 | | - } |
334 | | - |
335 | | - submitFeedback(selectedRating, feedbackText, email); |
336 | | - }); |
337 | | - |
338 | | - closeButton.addEventListener("click", () => { |
339 | | - feedbackForm.style.display = "none"; |
340 | | - feedbackTextarea.value = ""; |
341 | | - emailInput.value = ""; |
342 | | - statusDiv.textContent = ""; |
343 | | - selectedRating = 0; |
344 | | - |
345 | | - stars.forEach((s) => { |
346 | | - s.textContent = "☆"; |
347 | | - s.classList.remove("active"); |
348 | | - s.classList.remove("hovered"); |
349 | | - }); |
350 | | - }); |
351 | | -} |
352 | | - |
353 | | -// Init on load |
354 | | -document.addEventListener("DOMContentLoaded", initFeedbackWidget); |
355 | | - |
356 | | -// Re-init on page change (MkDocs Material support) |
357 | | -if (typeof document$ !== 'undefined') { |
358 | | - document$.subscribe(() => { |
359 | | - initFeedbackWidget(); |
360 | | - }); |
361 | | -} |
362 | | -</script> |
0 commit comments