ckeditor - 如何在 CKEditor 5 中禁用放置事件
问题描述
我们正在尝试将 CKEditor 5 实施到我们的应用程序中,并且我们在文档方面遇到了一些困难。
我们想禁用拖放事件到编辑区域或以某种方式控制它。有活动吗?
我们正在尝试editor.model.document.on('clipboardInput')
或editor.model.document.on('dragover')
没有任何运气。这些事件不会被触发。
解决方案
您需要在视图层而不是模型dragover
上监听和drop
事件。
我准备了一个简单的函数,可以作为插件加载到 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/ 。
推荐阅读
- python - Matplotlib:如何从列表中给出 xticks 值
- angular - Angular 6,我收到以下错误 - getForecast 不是函数
- php - 转义文字,使其用双引号括起来
- ssl - 生成和管理 ssl 证书管理器 kubernetes 的简单方法?
- c++ - 用多种颜色为 macOS 中的标题栏着色
- asp.net-core - ASP.NET Core 中特定于区域的身份验证方案
- android - 我正在尝试创建一个 onclicklistener,它将调用另一个类的函数
- angular - 在 console.log 中显示后未定义的值
- javascript - 如何让 Angular 组件知道您的外部 javascript 文件?
- javascript - 尝试在需要管道的子进程中运行 git 命令