CKeditor保存事件 [英] CKeditor save event

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

问题描述

我正在遵循本主题中的步骤: CKEditor,AJAX Save
I试图触发自定义的saved.ckeditor事件,如果有人按下AjaxSave按钮。但是我没有成功。

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

推荐答案

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

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