如何在 CKEditor 5 中禁用丢弃事件



我们正在尝试将CKEditor 5实现到我们的应用程序中,但我们在文档方面遇到了一些困难。

我们想禁用拖放事件到编辑区域或以某种方式控制它。有没有活动?

我们尝试editor.model.document.on('clipboardInput')editor.model.document.on('dragover')没有任何运气。不会触发这些事件。

您需要在视图层而不是模型上侦听dragoverdrop事件。

我准备了一个简单的函数,可以作为插件加载到 CKEditor 5 中,从而取消这些事件:

/**
* Cancel the `drop` and `dragover` events.
*
* @param {module:core/editor/editor~Editor} editor
*/
function cancelDropEvents( editor ) {
// High priority means that the callbacks below will be called before other CKEditor's plugins.
editor.editing.view.document.on( 'drop', ( evt, data ) => {
// Stop executing next callbacks.
evt.stop();
// Prevent the default event action.
data.preventDefault();
}, { priority: 'high' } );
editor.editing.view.document.on( 'dragover', ( evt, data ) => {
evt.stop();
data.preventDefault();
}, { priority: 'high' } );
}

您可以在线查看它的工作原理 – https://jsfiddle.net/pomek/qz0o9ku0/。

最新更新