Reputation: 1349
I have mail application with CKEditor, below code is used to open modal for mail and then create CKEditor on textarea,
<textarea id="editor" name="editor" class="border-0"></textarea>
$(document).on('click', '.sendEmailButton', function () {
//Show mail modal
$('#compose').modal("show");
//Init. Editor
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then( newEditor => {
editor = newEditor;
} )
.catch( error => {
console.error( error );
} );
});
My problem is when user click on .sendEmailButton
it recreates editor again on textarea
,
How can I check that textarea
have CKEditor assigned so that on next click it should not recreate it?
Thank you,
Upvotes: 0
Views: 709
Reputation: 1536
Check as follows and then create the CKEDITOR assign the editor to the empty global variable and then check it's empty or not. Initialize it will empty and it will create.on next it will occupaid with editor and not creates it again.
var editorVar = "";
$(document).on('click', '.sendEmailButton', function () {
//Show mail modal
$('#compose').modal("show");
//Init. Editor
if(editorVar == "") {
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then( newEditor => {
editor = newEditor;
editorVar = newEditor;
} )
.catch( error => {
console.error( error );
} );
}
});
Upvotes: 1