问题描述
我是按照本主题所写的步骤操作:
I如果有人按下AjaxSave按钮,则尝试触发自定义的saved.ckeditor事件。但我没有成功。
I was following the steps written in this topic: CKEditor, AJAX Save I tried to fire a custom 'saved.ckeditor' event if anybody press the AjaxSave button. But I did not succeeded.
ckeditor / plugins / ajaxsave / plugin.js:
ckeditor/plugins/ajaxsave/plugin.js:
(function(){
var saveCmd =
{
modes : { wysiwyg:1, source:1 },
exec : function( editor )
{
editor.fire('saved.ckeditor');
$(editor).trigger('saved.ckeditor', editor.getData());
alert(editor.getData());
}
}
var pluginName = 'ajaxsave';
CKEDITOR.plugins.add( pluginName,
{
init : function( editor )
{
var command = editor.addCommand( pluginName, saveCmd );
command.modes = { wysiwyg : !!( editor.element.$.form ) };
editor.ui.addButton( 'AjaxSave',
{
label : editor.lang.save,
command : pluginName,
className : 'cke_button_save'
});
}
});
})();
如果我在函数中获取或设置编辑器数据,get和set事件将自动触发。
If I get or set the editor data in the function, the get and set events will automatically be fired. But I could not even fire a 'getData.ckeditor' event manually.
任何提示?
另一个事情:如果编辑器的内容自上次保存后没有改变(它不脏了),如何禁用按钮?
An other thing: how can I disable the button if the editor's content haven't changed since the last save (it is not dirty)?
推荐答案
p>您可以编辑常规保存按钮的功能以执行所需操作:
You can edit the functionality of the regular save button to do what you want:
html:
<textarea id="CKEditor1"></textarea>
javascript:
javascript:
<script>
// Need to wait for the ckeditor instance to finish initialization
// because CKEDITOR.instances.editor.commands is an empty object
// if you try to use it immediately after CKEDITOR.replace('editor');
CKEDITOR.on('instanceReady', function (ev) {
// Create a new command with the desired exec function
var overridecmd = new CKEDITOR.command(editor, {
exec: function(editor){
// Replace this with your desired save button code
alert(editor.document.getBody().getHtml());
}
});
// Replace the old save's exec function with the new one
ev.editor.commands.save.exec = overridecmd.exec;
});
CKEDITOR.replace('CKEditor1');
</script>
这篇关于CKeditor保存事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!