I'd like to add a button to the toolbar that calls a JavaScript function like Tada()?
Any ideas on how to add this?
I'd like to add a button to the toolbar that calls a JavaScript function like Tada()?
Any ideas on how to add this?
You'll need to create a plug-in. The documentation for CKEditor is very poor for this, especially since I believe it has changed significantly since FCKEditor. I would suggest copying an existing plug-in and studying it. A quick google for "CKEditor plugin" also found this blog post.
I am in the process of developing a number of custom Plugins for CKEditor and here's my survival pack of bookmarks:
For your purpose, I would recommend look at one of the plugins in the _source/plugins
directory, for example the "print" button. Adding a simple Javascript function is quite easy to achieve. You should be able to duplicate the print plugin (take the directory from _source into the actual plugins/ directory, worry about minification later), rename it, rename every mention of "print" within it, give the button a proper name you use later in your toolbar setup to include the button, and add your function.
See this URL for a easy example http://ajithmanmadhan.wordpress.com/2009/12/16/customizing-ckeditor-and-adding-a-new-toolbar-button/
1) create a plugin folder 2) register your plugin (the URL above says to edit the ckeditor.js file DO NOT do this, as it will break next time a new version is relased. Instead edit the config.js and add a line like so
config.extraPlugins = 'pluginX,pluginY,yourPluginNameHere';
3) make a JS file called plugin.js inside your plugin folder Here is my code
(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
});
}
});
})();