Javascript 如何在 CKEditor 中监听基本事件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5721916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to listen to basic events in CKEditor?
提问by lisak
I can't figure out how to listen to focus, click, onKeyUp and other basic dom events in ckeditor. In the events summarythere is only a few events regarding the lifecycle of 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 中收听 focus、click、onKeyUp 和其他基本 dom 事件。在事件摘要中,只有几个关于 ckeditor 生命周期的事件。而ckeditor的“textArea”是一个iframe,本身就是html,所以不清楚要监听哪个dom节点。
回答by lisak
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
回答by bpeterson76
CKEditor actually has built-in event handling in the object. See this article for an explanation: http://alfonsoml.blogspot.com/2009/09/ckeditor-events.html
CKEditor 实际上在对象中有内置的事件处理。请参阅这篇文章的解释: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,它得到了我的投票,成为那里的最佳选择。