11import { Component } from './component' ;
22import { getLoading , htmlToDom } from '../services/dom' ;
3+ import { buildForInput } from '../wysiwyg/config' ;
34
45export class PageComments extends Component {
56
@@ -21,6 +22,11 @@ export class PageComments extends Component {
2122 this . hideFormButton = this . $refs . hideFormButton ;
2223 this . removeReplyToButton = this . $refs . removeReplyToButton ;
2324
25+ // WYSIWYG options
26+ this . wysiwygLanguage = this . $opts . wysiwygLanguage ;
27+ this . wysiwygTextDirection = this . $opts . wysiwygTextDirection ;
28+ this . wysiwygEditor = null ;
29+
2430 // Translations
2531 this . createdText = this . $opts . createdText ;
2632 this . countText = this . $opts . countText ;
@@ -59,9 +65,8 @@ export class PageComments extends Component {
5965 this . form . after ( loading ) ;
6066 this . form . toggleAttribute ( 'hidden' , true ) ;
6167
62- const text = this . formInput . value ;
6368 const reqData = {
64- text ,
69+ html : this . wysiwygEditor . getContent ( ) ,
6570 parent_id : this . parentId || null ,
6671 } ;
6772
@@ -86,19 +91,19 @@ export class PageComments extends Component {
8691 }
8792
8893 resetForm ( ) {
94+ this . removeEditor ( ) ;
8995 this . formInput . value = '' ;
9096 this . parentId = null ;
9197 this . replyToRow . toggleAttribute ( 'hidden' , true ) ;
9298 this . container . append ( this . formContainer ) ;
9399 }
94100
95101 showForm ( ) {
102+ this . removeEditor ( ) ;
96103 this . formContainer . toggleAttribute ( 'hidden' , false ) ;
97104 this . addButtonContainer . toggleAttribute ( 'hidden' , true ) ;
98105 this . formContainer . scrollIntoView ( { behavior : 'smooth' , block : 'nearest' } ) ;
99- setTimeout ( ( ) => {
100- this . formInput . focus ( ) ;
101- } , 100 ) ;
106+ this . loadEditor ( ) ;
102107 }
103108
104109 hideForm ( ) {
@@ -112,6 +117,34 @@ export class PageComments extends Component {
112117 this . addButtonContainer . toggleAttribute ( 'hidden' , false ) ;
113118 }
114119
120+ loadEditor ( ) {
121+ if ( this . wysiwygEditor ) {
122+ this . wysiwygEditor . focus ( ) ;
123+ return ;
124+ }
125+
126+ const config = buildForInput ( {
127+ language : this . wysiwygLanguage ,
128+ containerElement : this . formInput ,
129+ darkMode : document . documentElement . classList . contains ( 'dark-mode' ) ,
130+ textDirection : this . wysiwygTextDirection ,
131+ translations : { } ,
132+ translationMap : window . editor_translations ,
133+ } ) ;
134+
135+ window . tinymce . init ( config ) . then ( editors => {
136+ this . wysiwygEditor = editors [ 0 ] ;
137+ setTimeout ( ( ) => this . wysiwygEditor . focus ( ) , 50 ) ;
138+ } ) ;
139+ }
140+
141+ removeEditor ( ) {
142+ if ( this . wysiwygEditor ) {
143+ this . wysiwygEditor . remove ( ) ;
144+ this . wysiwygEditor = null ;
145+ }
146+ }
147+
115148 getCommentCount ( ) {
116149 return this . container . querySelectorAll ( '[component="page-comment"]' ) . length ;
117150 }
0 commit comments