CKEditor's click event not firing

半世苍凉 提交于 2019-12-29 09:08:24

问题


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');
});

For some reason, the click event never fires. However, if I listen to the doubleclick event, it fires when the editor is double clicked.

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?

Some further investigations:

Attaching the event handler on editor.document fires for every click, including clicks outside the editor.

Attaching the event handler to editor.container fires for clicks on the container including the toolbars.

Fiddle: http://jsfiddle.net/295PE/


回答1:


Correct way of attaching listeners to the editable element in CKEditor:

editor.on( 'contentDom', function() {
    var editable = editor.editable();
    editable.attachListener( editable, 'click', function() {
        // ...
    } );
} );

Read more about the reasons why contentDom event has to be used instead of e.g. instanceReady in editable.attachListener documentation.




回答2:


Use attach the event handler to the editor's editable. This needs to be done after the editor is ready:

editor.on('instanceReady', function (e) {
    editor.editable().on('click', function (event) {
        console.log('clicked');
    });
});

Fiddle: http://jsfiddle.net/8fZpz/



来源:https://stackoverflow.com/questions/24989766/ckeditors-click-event-not-firing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!