4在线编辑保存按钮插件

4在线编辑保存按钮插件

本文介绍了CKEditor 4在线编辑保存按钮插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚创建了一个插件ajax保存。我看过的文档,而不是让我困惑实现它。
当我点击并通过ajax php保存内容时,如何使按钮工作?目前我无法得到内容。

i have just created a plugin ajax save. i have looked around the documentation instead its getting me confused to implement it.how do i make the button work when click and save the content via ajax php? at the moment i cant get the content.

文件夹:/plugins/ajaxsave/plugin.js

var saveCmd = {
    modes : { wysiwyg:1 },
    exec : function( editor ) {
        **var $content = editor.instances.editor1.getData(); ?????**
        var $data = {'keyId': 1, 'token': TOKEN, 'content': $content};

        $.ajax({
            type: 'post',
            url: '../../script/php/file.php',
            data: $data,
            dataType: 'json',
            cache: false,
            success: function(data) {

                    alert( 'OK' );

            },
            error: function(data){
                alert('fatal error');
            }
        });
       CKEDITOR.instances.editor1.destroy();
   }

}
CKEDITOR.plugins.add('ajaxsave',  {

    init:function(editor) {

        var pluginName = 'ajaxsave';
        var command = editor.addCommand(pluginName,saveCmd);
        command.modes = {wysiwyg:1 };

        editor.ui.addButton('ajaxsave', {
            label: 'Save text',
            command: pluginName,
            toolbar: 'undo,1',
            icon: this.path+'save.png'
        });
    }
});


推荐答案

**var $content = editor.instances.editor1.getData(); ?????**

应为:

var $content = editor.getData();

的插件。对每个编辑器实例调用此方法。

editor there is an argument of init method of your plugin. This method is called for each editor instance.

这篇关于CKEditor 4在线编辑保存按钮插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:30