2012-12-07 40 views
2

enter image description hereCKEditor 4内联编辑保存按钮插件

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

文件夹:/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' 
     }); 
    } 
}); 
+0

问题是什么?它会给你一个错误?它没有保存吗?请带我们解决问题。 – Trufa

+0

@Trufa它不识别可编辑的内容。我如何获取内容并通过ajax传递它。 – tonoslfx

回答

0

试试这个: -

var ckvalue = CKEDITOR.instances['editor1'].getData(); // editor1 is id of the ckeditor textarea 


    //or 

    $('#editor1').ckeditor(function(textarea){ 
    $(textarea).val(); 
    }); 
3
**var $content = editor.instances.editor1.getData(); ?????** 

应该是:

var $content = editor.getData(); 

editor有一个你的插件的init方法的参数。这个方法被每个编辑器实例调用。