Is there a way in JavaScript (or CKEditor) to detect when an image is removed from CKEditor. I need it for a caption element which is inserted together with the image, but once I delete the image, the caption should be deleted aswell.
Any help would be greatly appreciated.
There are no special event like a onDelete
or onImageRemovedFromContent
. But there are few events that can help you.
editor.on('afterUndoImage', function( e ){ ... } )
But afterUndoImage
fires only on Undo
command, does not fires on manual deleting of elements.
editor.on('afterCommandExec', function( e ){ ... } )
CKEditor changes content with execCommand
(mostly), so that fires on many content's change, so you can check the diff with regex for example.
Also you can use plugin onchange to detect the changes of contents, it combines onUndo
, onRedo
, afterCommandExec
, etc.