我想在工具栏中添加一个按钮,用于调用Tada()
之类的JavaScript函数
对如何添加这个有什么想法吗?
发布于 2014-08-22 17:07:04
还有一种很好的方式,可以让你在不创建插件的情况下添加按钮。
html:
<textarea id="container">How are you!</textarea>
javascript:
editor = CKEDITOR.replace('container'); // bind editor
editor.addCommand("mySimpleCommand", { // create named command
exec: function(edt) {
alert(edt.getData());
}
});
editor.ui.addButton('SuperButton', { // add new button and bind our command
label: "Click me",
command: 'mySimpleCommand',
toolbar: 'insert',
icon: 'https://avatars1.githubusercontent.com/u/5500999?v=2&s=16'
});
在这里查看它是如何工作的:DEMO
发布于 2010-01-04 10:42:06
有关简单的http://ajithmanmadhan.wordpress.com/2009/12/16/customizing-ckeditor-and-adding-a-new-toolbar-button/示例,请参阅此URL
有几个步骤:
1)创建插件文件夹
2)注册你的插件(上面的网址说要编辑ckeditor.js文件,不要这样做,因为它会在下一次发布新版本时崩溃。而是编辑config.js并添加一行,如下所示
config.extraPlugins = 'pluginX,pluginY,yourPluginNameHere';
3)在插件文件夹中创建一个名为plugin.js的JS文件
(function() {
//Section 1 : Code to execute when the toolbar button is pressed
var a = {
exec: function(editor) {
var theSelectedText = editor.getSelection().getNative();
alert(theSelectedText);
}
},
//Section 2 : Create the button and add the functionality to it
b='addTags';
CKEDITOR.plugins.add(b, {
init: function(editor) {
editor.addCommand(b, a);
editor.ui.addButton("addTags", {
label: 'Add Tag',
icon: this.path+"addTag.gif",
command: b
});
}
});
})();
发布于 2011-11-16 03:08:57
如果有人感兴趣,我用Prototype写了一个解决方案。为了让按钮正确显示,我必须从CKEDITOR.replace()
方法调用内部指定extraPlugins: 'ajaxsave'
。
下面是plugin.js:
CKEDITOR.plugins.add('ajaxsave',
{
init: function(editor)
{
var pluginName = 'ajaxsave';
editor.addCommand( pluginName,
{
exec : function( editor )
{
new Ajax.Request('ajaxsave.php',
{
method: "POST",
parameters: { filename: 'index.html', editor: editor.getData() },
onFailure: function() { ThrowError("Error: The server has returned an unknown error"); },
on0: function() { ThrowError('Error: The server is not responding. Please try again.'); },
onSuccess: function(transport) {
var resp = transport.responseText;
//Successful processing by ckprocess.php should return simply 'OK'.
if(resp == "OK") {
//This is a custom function I wrote to display messages. Nicer than alert()
ShowPageMessage('Changes have been saved successfully!');
} else {
ShowPageMessage(resp,'10');
}
}
});
},
canUndo : true
});
editor.ui.addButton('ajaxsave',
{
label: 'Save',
command: pluginName,
className : 'cke_button_save'
});
}
});
https://stackoverflow.com/questions/1957156
复制相似问题