@@ -151,8 +151,8 @@ export class Comment extends CanvasSectionObject {
151151 var button = L . DomUtil . create ( 'div' , 'annotation-btns-container' , this . sectionProperties . nodeModify ) ;
152152 L . DomEvent . on ( this . sectionProperties . nodeModifyText , 'blur' , this . onLostFocus , this ) ;
153153 L . DomEvent . on ( this . sectionProperties . nodeReplyText , 'blur' , this . onLostFocusReply , this ) ;
154- L . DomEvent . on ( this . sectionProperties . nodeModifyText , 'input ' , this . textAreaInput , this ) ;
155- L . DomEvent . on ( this . sectionProperties . nodeReplyText , 'input ' , this . textAreaInput , this ) ;
154+ L . DomEvent . on ( this . sectionProperties . nodeModifyText , 'focus ' , this . onFocus , this ) ;
155+ L . DomEvent . on ( this . sectionProperties . nodeReplyText , 'focus ' , this . onFocusReply , this ) ;
156156 this . createButton ( button , 'annotation-cancel-' + this . sectionProperties . data . id , 'annotation-button button-secondary' , _ ( 'Cancel' ) , this . handleCancelCommentButton ) ;
157157 this . createButton ( button , 'annotation-save-' + this . sectionProperties . data . id , 'annotation-button button-primary' , _ ( 'Save' ) , this . handleSaveCommentButton ) ;
158158 button = L . DomUtil . create ( 'div' , '' , this . sectionProperties . nodeReply ) ;
@@ -283,7 +283,6 @@ export class Comment extends CanvasSectionObject {
283283 this . sectionProperties . authorAvatartdImg = tdImg ;
284284 this . sectionProperties . contentAuthor = L . DomUtil . create ( 'div' , 'cool-annotation-content-author' , tdAuthor ) ;
285285 this . sectionProperties . contentDate = L . DomUtil . create ( 'div' , 'cool-annotation-date' , tdAuthor ) ;
286- this . sectionProperties . autoSave = L . DomUtil . create ( 'div' , 'cool-annotation-autosavelabel' , tdAuthor ) ;
287286 }
288287
289288 private createMenu ( ) : void {
@@ -345,8 +344,12 @@ export class Comment extends CanvasSectionObject {
345344 this . sectionProperties . resolvedTextElement . innerText = state === 'true' ? _ ( 'Resolved' ) : '' ;
346345 }
347346
348- private textAreaInput ( ) : void {
349- this . sectionProperties . autoSave . innerText = '' ;
347+ private onFocus ( ) {
348+ this . resetControl ( this . getSaveButton ( ) , _ ( 'Save' ) , 'annotation-button-autosaved' ) ;
349+ }
350+
351+ private onFocusReply ( ) {
352+ this . resetControl ( this . getReplyButton ( ) , _ ( 'Reply' ) , 'annotation-button-autosaved' ) ;
350353 }
351354
352355 private updateContent ( ) : void {
@@ -885,7 +888,6 @@ export class Comment extends CanvasSectionObject {
885888 public handleReplyCommentButton ( e : any ) : void {
886889 cool . CommentSection . autoSavedComment = null ;
887890 cool . CommentSection . commentWasAutoAdded = false ;
888- this . textAreaInput ( ) ;
889891 this . onReplyClick ( e ) ;
890892 }
891893
@@ -950,7 +952,6 @@ export class Comment extends CanvasSectionObject {
950952 cool . CommentSection . autoSavedComment = null ;
951953 cool . CommentSection . commentWasAutoAdded = false ;
952954 this . sectionProperties . contentText . unedited = null ;
953- this . textAreaInput ( ) ;
954955 this . onSaveComment ( e ) ;
955956 }
956957
@@ -964,10 +965,49 @@ export class Comment extends CanvasSectionObject {
964965 this . sectionProperties . commentListSection . save ( this ) ;
965966 }
966967
968+
969+ private getSaveButton ( ) : HTMLButtonElement | null {
970+ return this . sectionProperties . nodeModify . querySelector ( 'input[type="button"][id^="annotation-save-"]' ) ;
971+ }
972+
973+ private getCancelButton ( ) : HTMLButtonElement | null {
974+ return this . sectionProperties . nodeModify . querySelector ( 'input[type="button"][id^="annotation-cancel-"]' ) ;
975+ }
976+
977+ private getReplyButton ( ) : HTMLButtonElement | null {
978+ return this . sectionProperties . nodeReply . querySelector ( 'input[type="button"][id^="annotation-reply-"]' ) ;
979+ }
980+
981+ private getCancelReplyButton ( ) : HTMLButtonElement | null {
982+ return this . sectionProperties . nodeReply . querySelector ( 'input[type="button"][id^="annotation-cancel-reply-"]' ) ;
983+ }
984+
985+ private updateControl (
986+ button : HTMLButtonElement | null ,
987+ label : string ,
988+ className : string
989+ ) : void {
990+ if ( button ) {
991+ button . value = label ;
992+ button . classList . add ( className ) ;
993+ }
994+ }
995+
996+ private updateSaveControls ( ) {
997+ this . updateControl ( this . getSaveButton ( ) , _ ( 'Saved' ) , 'annotation-button-autosaved' ) ;
998+ this . updateControl ( this . getCancelButton ( ) , _ ( 'Delete' ) , 'annotation-button-delete' ) ;
999+ }
1000+
1001+ private updateReplyControls ( ) {
1002+ this . updateControl ( this . getReplyButton ( ) , _ ( 'Saved' ) , 'annotation-button-autosaved' ) ;
1003+ this . updateControl ( this . getCancelReplyButton ( ) , _ ( 'Delete' ) , 'annotation-button-delete' ) ;
1004+ }
1005+
9671006 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
9681007 public onLostFocus ( e : any ) : void {
9691008 if ( ! this . sectionProperties . isRemoved ) {
9701009 $ ( this . sectionProperties . container ) . removeClass ( 'annotation-active reply-annotation-container modify-annotation-container' ) ;
1010+ this . updateSaveControls ( ) ;
9711011 if ( this . sectionProperties . contentText . origText !== this . sectionProperties . nodeModifyText . value ) {
9721012 if ( ! this . sectionProperties . contentText . unedited )
9731013 this . sectionProperties . contentText . unedited = this . sectionProperties . contentText . origText ;
@@ -989,6 +1029,7 @@ export class Comment extends CanvasSectionObject {
9891029 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
9901030 public onLostFocusReply ( e : any ) : void {
9911031 if ( this . sectionProperties . nodeReplyText . value !== '' ) {
1032+ this . updateReplyControls ( ) ;
9921033 if ( ! this . sectionProperties . contentText . unedited )
9931034 this . sectionProperties . contentText . unedited = this . sectionProperties . contentText . origText ;
9941035 cool . CommentSection . autoSavedComment = this ;
@@ -999,10 +1040,38 @@ export class Comment extends CanvasSectionObject {
9991040 }
10001041 }
10011042
1043+ private resetControl (
1044+ button : HTMLButtonElement | null ,
1045+ label : string ,
1046+ className : string
1047+ ) : void {
1048+ if ( button ) {
1049+ button . value = label ;
1050+ button . classList . remove ( className ) ;
1051+ }
1052+ }
1053+
1054+ private resetSaveControls ( ) : void {
1055+ this . resetControl ( this . getSaveButton ( ) , _ ( 'Save' ) , 'annotation-button-autosaved' ) ;
1056+ this . resetControl ( this . getCancelButton ( ) , _ ( 'Cancel' ) , 'annotation-button-delete' ) ;
1057+ }
1058+
1059+ private resetReplyControls ( ) : void {
1060+ this . resetControl ( this . getReplyButton ( ) , _ ( 'Reply' ) , 'annotation-button-autosaved' ) ;
1061+ this . resetControl ( this . getCancelReplyButton ( ) , _ ( 'Cancel' ) , 'annotation-button-delete' ) ;
1062+ }
1063+
10021064 public focus ( ) : void {
10031065 this . sectionProperties . container . classList . add ( 'annotation-active' ) ;
10041066 this . sectionProperties . nodeModifyText . focus ( ) ;
10051067 this . sectionProperties . nodeReplyText . focus ( ) ;
1068+ this . resetSaveControls ( ) ;
1069+ this . resetReplyControls ( ) ;
1070+ }
1071+
1072+ public focusLost ( ) : void {
1073+ this . updateSaveControls ( ) ;
1074+ this . updateReplyControls ( ) ;
10061075 }
10071076
10081077 public reply ( ) : Comment {
0 commit comments