@@ -115,6 +115,14 @@ function setSuggestionMessage(msg, is_warning) {
115115 }
116116}
117117
118+ function resetHighlight ( ) {
119+ $ ( '#location-name' ) . val ( $ ( '#location-name' ) . data ( 'value' ) ) ;
120+ $ ( '#address' ) . val ( $ ( '#address' ) . data ( 'value' ) ) ;
121+ $ ( '#phone-number' ) . val ( $ ( '#phone-number' ) . data ( 'value' ) ) ;
122+ $ ( '#url' ) . val ( $ ( '#url' ) . data ( 'value' ) ) ;
123+ $ ( '.highlight' ) . removeClass ( 'highlight' ) ;
124+ }
125+
118126function suggestionSubmitted ( r ) {
119127 setSuggestionMessage ( "Suggestion has been created." , false ) ;
120128
@@ -165,23 +173,29 @@ function suggestionButtonClicked() {
165173 'url' : url
166174 } ,
167175 'url' : '/api/add-suggestion' ,
176+ 'beforeSend' : function ( jqXHR , settings ) {
177+ $ ( 'button' ) . prop ( 'disabled' , true ) ;
178+ } ,
168179 'success' : suggestionSubmitted ,
169- 'error' : suggestionFailed
180+ 'error' : suggestionFailed ,
181+ 'complete' : function ( jqXHR , textStatus ) {
182+ $ ( 'button' ) . prop ( 'disabled' , false ) ;
183+ resetHighlight ( ) ;
184+ }
170185 } ) ;
171186}
172187
173188function highlightDiffField ( id ) {
174- var element = document . getElementById ( id ) ;
175- element . addEventListener ( "change" , function ( event ) {
189+ $ ( '#' + id ) . bind ( 'input' , function ( event ) {
176190 //highlight modified suggestion fields
177- if ( element . dataset . value != element . value ) {
178- if ( ! $ ( element ) . hasClass ( 'highlight' ) )
191+ if ( $ ( this ) . data ( ' value' ) != $ ( this ) . val ( ) ) {
192+ if ( ! $ ( this ) . hasClass ( 'highlight' ) )
179193 suggestion_counter += 1 ;
180- $ ( element ) . addClass ( 'highlight' ) ;
194+ $ ( this ) . addClass ( 'highlight' ) ;
181195 } else {
182- if ( $ ( element ) . hasClass ( 'highlight' ) )
196+ if ( $ ( this ) . hasClass ( 'highlight' ) )
183197 suggestion_counter -= 1 ;
184- $ ( element ) . removeClass ( 'highlight' ) ;
198+ $ ( this ) . removeClass ( 'highlight' ) ;
185199 }
186200 // disable submit button when there is no difference in the fields
187201 if ( suggestion_counter > 0 )
0 commit comments