删除元素时的 CKEditor 事件?
JavaScript(或 CKEditor)中有没有办法检测图像何时从 CKEditor 中删除。 我需要它作为与图像一起插入的标题元素,但是一旦删除图像,标题也应该被删除。
任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有像
onDelete
或onImageRemovedFromContent
这样的特殊事件。但很少有活动可以帮助您。但是
afterUndoImage
仅在Undo
命令上触发,在手动删除元素时不会触发。CKEditor 使用
execCommand
(大多数情况下)更改内容,这样会触发许多内容的更改,因此您可以使用正则表达式检查差异。您还可以使用插件 onchange 来检测内容,它结合了
onUndo
、onRedo
、afterCommandExec
等。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.使用插件--> https://github.com/shibbirweb/ckeditor5-image-remove- event-callback-plugin
该插件使您能够传递自己的回调函数,当您从编辑器中删除图像时将调用该函数。我在 VueJs 中实现了这个,花了几个小时后,我意识到这很容易做到。如果你问我的话,它是一个很酷的插件。下面的代码片段演示了实现此目的的非 Vuejs 方式。如果您需要了解 VueJs 实现,可以给我回信。
谢谢
:此代码片段来自包文档,这就是其中的所有信息。
Use the plugin--> https://github.com/shibbirweb/ckeditor5-image-remove-event-callback-plugin
This plugin enables you to pass your own callback function which will be called when you will remove the image from your editor. I implemented this in VueJs and after having spent a couple of hours, I realized it was quite easy to do so. Its a cool plugin if you ask me. The below code snippet demonstrate the non-Vuejs way to implement this. You can write back to me if you need to know the VueJs implementation.
Thanks
P.S. : This code snippet is from the package documentation and that's all the info there is.
我知道这已经相当老了,但我在寻找解决方案时最终来到这里,所以我认为值得发布另一种方法。
我不想监视所有可能的更改,因为我在小部件中预见的大多数活动都是正常编辑或从外部源创建小部件,所以我最终只是监视会导致删除的事件:
当然回调有假设调用小部件尚未被删除,但这是一个优点,因为人们通常需要其数据。
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.