11function initFeedbackWidget ( ) {
2- const stars = document . querySelectorAll ( ".rating-stars .star" ) ;
2+ const widget = document . querySelector ( ".rating-stars" ) ;
3+ if ( ! widget || widget . dataset . initialized === "true" ) return ; // ✅ already initialized
4+ widget . dataset . initialized = "true" ;
5+
6+ const stars = widget . querySelectorAll ( ".star" ) ;
37 const feedbackForm = document . getElementById ( "feedback-form" ) ;
48 const feedbackTextarea = document . getElementById ( "feedback-text" ) ;
59 const emailInput = document . getElementById ( "feedback-email" ) ;
@@ -21,6 +25,7 @@ function initFeedbackWidget() {
2125
2226 let selectedRating = 0 ;
2327 let notificationTimeout ;
28+ let ratingLocked = false ; // 🔒 cooldown lock
2429
2530 function showNotification ( msg ) {
2631 notification . textContent = msg ;
@@ -69,12 +74,11 @@ function initFeedbackWidget() {
6974 s . classList . remove ( "hovered" ) ;
7075 } ) ;
7176
72- // ✅ Show post-submit thank-you notification
73- submitNotification . style . display = "block" ;
74- clearTimeout ( notificationTimeout ) ;
75- notificationTimeout = setTimeout ( ( ) => {
76- submitNotification . style . display = "none" ;
77- } , 4000 ) ;
77+ submitNotification . style . display = "block" ;
78+ clearTimeout ( notificationTimeout ) ;
79+ notificationTimeout = setTimeout ( ( ) => {
80+ submitNotification . style . display = "none" ;
81+ } , 4000 ) ;
7882 } ) . catch ( ( ) => {
7983 statusDiv . style . color = "" ;
8084 statusDiv . textContent = "Error sending feedback." ;
@@ -85,6 +89,7 @@ function initFeedbackWidget() {
8589 const rating = parseInt ( star . dataset . rating , 10 ) ;
8690
8791 star . addEventListener ( "mouseover" , ( ) => {
92+ if ( ratingLocked ) return ;
8893 stars . forEach ( ( s , index ) => {
8994 s . textContent = index < rating ? "★" : "☆" ;
9095 if ( index < rating ) {
@@ -98,6 +103,7 @@ function initFeedbackWidget() {
98103 } ) ;
99104
100105 star . addEventListener ( "mouseleave" , ( ) => {
106+ if ( ratingLocked ) return ;
101107 stars . forEach ( ( s , index ) => {
102108 s . textContent = index < selectedRating ? "★" : "☆" ;
103109 if ( index < selectedRating ) {
@@ -110,6 +116,9 @@ function initFeedbackWidget() {
110116 } ) ;
111117
112118 star . addEventListener ( "click" , ( ) => {
119+ if ( ratingLocked ) return ;
120+ ratingLocked = true ; // 🔒 lock stars for 10 seconds
121+
113122 selectedRating = rating ;
114123
115124 stars . forEach ( ( s , index ) => {
@@ -125,6 +134,10 @@ function initFeedbackWidget() {
125134 sendRatingOnly ( rating ) ;
126135 feedbackForm . style . display = "block" ;
127136 statusDiv . textContent = "" ;
137+
138+ setTimeout ( ( ) => {
139+ ratingLocked = false ; // ⏱ unlock after 10 seconds
140+ } , 10000 ) ;
128141 } ) ;
129142 } ) ;
130143
@@ -148,6 +161,7 @@ function initFeedbackWidget() {
148161 emailInput . value = "" ;
149162 statusDiv . textContent = "" ;
150163 selectedRating = 0 ;
164+ ratingLocked = false ;
151165
152166 stars . forEach ( ( s ) => {
153167 s . textContent = "☆" ;
0 commit comments