简体   繁体   English

如何在CKEditor中收听基本事件?

[英]How to listen to basic events in CKEditor?

I can't figure out how to listen to focus, click, onKeyUp and other basic dom events in ckeditor. 我无法弄清楚如何在ckeditor中收听焦点,click,onKeyUp和其他基本dom事件。 In the events summary there is only a few events regarding the lifecycle of ckeditor. 事件摘要中 ,只有少数关于ckeditor生命周期的事件。 And the "textArea" of ckeditor is an iframe, and it's html itself, so it is not clear on what dom node to listen. ckeditor的“textArea”是一个iframe,它本身就是html,所以不清楚要监听什么dom节点。

It's not a big deal, just do the following, works for focus, blur, click etc. 这不是什么大问题,只需执行以下操作,适用于焦点,模糊,点击等。

var ckeditor = CKEDITOR.instances['textArea_id'];
ckeditor.on('focus', fnHandler, context, data, priority);

or a jQuery example : 或jQuery示例:

$(document).ready(function () {
    $('#YOUR_TEXTAREA_ID').ckeditor(ckeditor_config);

    CKEDITOR.instances.YOUR_TEXTAREA_ID.on('blur', fnHandler);
});

I don't know when this support appeared, but it definitely works for 3.5.x 我不知道这个支持何时出现,但它肯定适用于3.5.x.

CKEditor actually has built-in event handling in the object. CKEditor实际上在对象中有内置的事件处理。 See this article for an explanation: http://alfonsoml.blogspot.com/2009/09/ckeditor-events.html 请参阅此文章以获得解释: http//alfonsoml.blogspot.com/2009/09/ckeditor-events.html

So, to catch a modification in a CKEditor instance you could do this: 因此,要在CKEditor实例中捕获修改,您可以这样做:

CKEDITOR.on('currentInstance', function(){modified = true;});

Also, it appears that version 3 has an event processor built into it that's more straightforward: http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.dialog.file.html#eventProcessors 此外,似乎版本3内置了一个事件处理器,它更直接: http//docs.cksource.com/ckeditor_api/symbols/CKEDITOR.ui.dialog.file.html#eventProcessors

CK is a bit convoluted and documentation has holes, but based on its ability to gracefully handle Word generated HTML it gets my vote as the best option out there. CK有点复杂,文档有漏洞,但基于它优雅地处理Word生成的HTML的能力,它得到我的投票作为最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM