kas*_*ans 11
下载工作插件:https://docs.google.com/file/d/0B0dQ8h7Cze23cUJGb2dJM1h2LWM/edit? pli = 1
这个插件使用jquery但你可以使用纯javascript轻松地重写它!在包含ckeditor之前,请确保将jquery包含在您的页面中
首先在config.js文件中注册插件(只需在config.js文件的末尾添加这些行)
config.extraPlugins = 'savebtn';//savebtn is the plugin's name
config.saveSubmitURL = 'http://server/link/to/post/';//link to serverside script to handle the post
Run Code Online (Sandbox Code Playgroud)
现在我们准备将插件添加到ckeditor.下载插件(请参阅上面的google drive下载链接)并解压缩ckeditors插件文件夹中的zip文件.(下载包含下面的脚本和使用过的图标)
而已.这个插件现在应该可以工作了!
作为参考,我在本答案的底部包含了源代码(plugin.js).如果您不知道发生了什么,我建议您阅读评论.此答案的代码中的注释与实际插件文件中的注释略有不同.最新的评论可以在这里找到.业务逻辑完全相同.
plugin.js
CKEDITOR.plugins.add( 'savebtn', {
icons: 'savebtn',
init: function( editor ) {
//add a new command to the editor.
//We give the command a name 'savecontent',
//so we can reference it later.
editor.addCommand( 'savecontent', {
//this is the business logic of our 'savecontent' command.
//this function gets executed when clicking the button.
//you can change/replace the logic of this function
//according to your own needs.
exec : function(editor){
//get the text from ckeditor you want to save
var data = editor.getData();
//get the current url (optional)
var page = document.URL;
//path to the ajaxloader gif
loading_icon=CKEDITOR.basePath+'plugins/savebtn/icons/loader.gif';
//css style for setting the standard save icon.
//We need this when the request is completed.
normal_icon=$('.cke_button__savebtn_icon').css('background-image');
//replace the standard save icon with the ajaxloader icon.
//We do this with css.
$('.cke_button__savebtn_icon').css("background-image", "url("+loading_icon+")");
//Now we are ready to post to the server...
$.ajax({
url: editor.config.saveSubmitURL,//the url to post at... configured in config.js
type: 'POST',
data: {text: data, id: editor.name, page: page},//editor.name contains the id of the current editable html tag
})
.done(function(response) {
console.log("success");
alert('id: '+editor.name+' \nurl: '+page+' \ntext: '+data);
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
//set the button icon back to the original
$('.cke_button__savebtn_icon').css("background-image", normal_icon);
});
}
});
//add the save button to the toolbar. Mind that we declare command: 'savecontent'.
//This way ckeditor knows what to do when clicking the button.
editor.ui.addButton( 'savebtn', {
label: 'Save',
command: 'savecontent'
// toolbar: 'insert'
});
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7523 次 |
| 最近记录: |