CKeditor 保存事件 [英] CKeditor save event

查看:44
本文介绍了CKeditor 保存事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照本主题中编写的步骤进行操作:CKEditor, AJAX Save如果有人按下 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 事件将自动被触发.但我什至无法手动触发getData.ckeditor"事件.

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)?

推荐答案

你可以编辑常规保存按钮的功能来做你想做的事:

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 保存事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆