CKEditor的点击事件不触发 [英] CKEditor's click event not firing
问题描述
我正在使用CKEditor 4.4.3,并尝试听编辑器的点击事件:
I am using CKEditor 4.4.3 and trying to listen to an editor's click event:
editor.on('click', function (e) {
console.log('click event from attaching to the editor');
});
由于某些原因,点击事件永远不会触发。但是,如果我听 doubleclick
事件,则在双击编辑器时触发。
For some reason, the click event never fires. However, if I listen to the doubleclick
event, it fires when the editor is double clicked.
聆听 editor.editable
上的点击事件,但对于没有内联的编辑者来说,它似乎不起作用。为什么点击
事件不起作用?
I was previously listening to the click event on editor.editable
, but it doesn't appear to work for editors that are not inlined. Why is the click
event not working?
进一步的调查:
在 editor.document
中附加事件处理程序,每次点击都会触发,包括编辑器外的点击。
Attaching the event handler on editor.document
fires for every click, including clicks outside the editor.
将事件处理程序附加到 editor.container
触发包含工具栏的容器点击。
Attaching the event handler to editor.container
fires for clicks on the container including the toolbars.
小提琴: http://jsfiddle.net/295PE/
推荐答案
正确方法将侦听器附加到CKEditor中的可编辑元素:
Correct way of attaching listeners to the editable element in CKEditor:
editor.on( 'contentDom', function() {
var editable = editor.editable();
editable.attachListener( editable, 'click', function() {
// ...
} );
} );
详细了解 contentDom
事件的原因必须使用而不是例如 instanceReady
在 editable.attachListener
文档。
Read more about the reasons why contentDom
event has to be used instead of e.g. instanceReady
in editable.attachListener
documentation.
这篇关于CKEditor的点击事件不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!