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.
I know this is rather old, but I ended up here while searching a solution, so I think it's worth to post another approach.
I didn't want to monitor all possible changes, since most of the activity I forsee in my widget is normal editing or widget creation from external sources, so I ended up simply monitoring the events that would cause the deletion:
Of course the callback has to assume that the calling widget has not been deleted yet, but that's an advantage, since one typically needs its data.
There are no special event like a
onDelete
oronImageRemovedFromContent
. But there are few events that can help you.But
afterUndoImage
fires only onUndo
command, does not fires on manual deleting of elements.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.