CKEditor的,AJAX保存 [英] CKEditor, AJAX Save
问题描述
可以提供关于如何设置的CKEditor通过AJAX保存使用保存按钮在工具栏的CKEditor的例子?
Can you provide an example on how to setup CKEditor to save via AJAX using the Save button in the CKEditor toolbar?
我有兴趣创建一个CKEditor的AJAX保存页面,但我没有看到他们的网站上的任何实例。
I'm interested in creating a CKEditor AJAX save page but am not seeing any examples on their site.
谢谢!
推荐答案
尝试从_source /插件/保存/ plugin.js直接拷贝,并根据需要改变。创建新的插件在/路径/到/的CKEditor /插件(即不在/路径/到/的CKEditor / _source /插件)。例如,在/路径/到/的CKEditor /插件创建一个新的目录AjaxSave,然后在该目录下创建文件plugin.js。然后,在该文件中做这样的事情(在源文件夹改编自正常的保存插件):
Try copying straight from _source/plugins/save/plugin.js and changing as needed. Create your new plugin in /path/to/ckeditor/plugins (i.e. Not in /path/to/ckeditor/_source/plugins). For example, in /path/to/ckeditor/plugins create a new directory "AjaxSave", then in that directory create a file "plugin.js". Then in that file do something like this (adapted from the normal "save" plugin in the source folder):
(function()
{
var saveCmd =
{
modes : { wysiwyg:1, source:1 },
exec : function( editor )
{
var $form = editor.element.$.form;
if ( $form )
{
try
{
editor.updateElement();
//Here is where you put your ajax submit function. For example... if you are using
// jQuery and the ajaxform plugin, do something like this:
$($form).ajaxSubmit({
success: function(response){
//do something with the response
}
});
} catch ( e ) {
//alert(e);
}
}
}
}
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,
icon: "/img/save.png"
});
}
});
})();
然后在配置,在这里你定义工具栏,改变AjaxSave'为'保存'。
Then in the config, where you define your toolbar, change 'AjaxSave' for 'Save'.
编辑:你还必须添加 config.extraPlugins =ajaxsave; 到config。
you must also add config.extraPlugins = "ajaxsave"; to the config.
这篇关于CKEditor的,AJAX保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!