I am using CKEditor's Enhanced Image plugin (image2) because it allows users to insert captioned images. However, I cannot enable the "captioned image" checkbox by default.
Setting a breakpoint after the code below shows the value is checked, but continuing unchecks it again.
CKEDITOR.on( 'dialogDefinition', function( ev ) {
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if (dialogName == 'image2') {
dialogDefinition.onShow = function() {
captionField = this.getContentElement('info', 'hasCaption');
captionField.setValue('checked');
console.log(captionField);
debugger;
}
}
});
Any advice on how to tick a CKEditor checkbox by default is greatly appreciated.
UPDATE
I tried updating the code based on Marek's answer to fit my needs, but the dialogShow event doesn't seem to get called this way.
CKEDITOR.on('dialogShow', function( evt ) {
var dialog = evt.data;
if ( dialog._.name === 'image2' && !dialog.widget.isReady() ) {
console.log('test');
evt.data.getContentElement( 'info', 'hasCaption' ).setValue( true );
}
});

dialogShowdoesn't work this way because it's called on editor instance, not the global namespace. I recommend playing with CKEditor 4 API docs. If you don't want to useCKEDITOR.replacethen you somehow need to get the editor instance. You can listen toinstanceReadyevent which is fired on a global namespace. And there you'd need to addeditor#dialogShowlistener. But we're going away from original question here. - Marek Lewandowski