The following quote is arkporter's "Step-by-step
Creating a Non-dialog Based Plugin."
In this example, we will create a toolbar button. It will enclose the selected text in <b> tags and add an exclamation point. This may not be very useful, but it will demostrate the process. We will name the new plugin "Emphasis".
Notes:
-- When referencing the plugin, keep casing consistent.
-- This example works in IE 6.0. I can't guarantee anything else.
-- Your browser may cache your pages, so every time you edit your .js file, clear the cache by going to Tools | Internet Options and "delete files". Then refresh your browser.
-- This post assumes that the FCKeditor folder is in the root of your website, and that all directories and files are in their original locations.
1. Create a new directory in your the FCKeditor/editor/plugins folder with the name of your plugin. For this example, name it "Emphasis".
2. Add a file fckplugin.js to this directory which you can copy from another plugin such as "placeholder" (which should already be in the plugins directory).
3. Replace the code in fckplugin.js with the following:
//Begin Code
var FCKEmphasis = function(name)
{
this.Name = name;
}
FCKEmphasis.prototype.Execute = function()
{
if(document.all)
{
mySelection = FCK.EditorDocument.selection
}
else
{
mySelection = FCK.EditorWindow.getSelection()
}
myTextRange= mySelection.createRange()
myText = myTextRange.text
FCK.InsertHtml("<b>"+myText+"!</b>")
myTextRange.select()
}
// manage the plugins' button behavior
FCKEmphasis.prototype.GetState = function()
{
return FCK_TRISTATE_OFF;
}
FCKCommands.RegisterCommand( 'Emphasis', new FCKEmphasis('Emphasis')) ;
// Create the toolbar button.
var oEmphasisItem = new FCKToolbarButton( 'Emphasis', "Emphasis", null, null, false, true ) ;
oEmphasisItem.IconPath = FCKConfig.PluginsPath + 'Emphasis/Emphasis.gif' ;
FCKToolbarItems.RegisterItem( 'Emphasis', oEmphasisItem ) ;
//End Code
4. Add an icon to the folder that will be used in the toolbar. For now, you can just copy the icon from the placeholder plugin. Name the file Emphasis.gif. If you are creating a new icon, it appears that 20x21 is a good size. You can use a .jpg, but make sure to change fckplugin.js to look for Emphasis.jpg.
5. Add the following line to FCKeditor/fckconfig.js
FCKConfig.Plugins.Add( 'Emphasis');
6. Assuming you are using the default configuration, locate the section of FCKeditor/fckconfig.js that begins with:
FCKConfig.ToolbarSets["Default"] = [
At the end of that section, but before the closing bracket ]; add the following:
,['Emphasis']
7. Save all your files, clear the cache (see note above), and open/refresh your page that includes FCKEditor. You should see your new toolbar item at the end of the list.
8. Select some text, click the new button, and see the results.
I actually followed these steps to the letter after creating this How-To, and my plug-in was working within minutes.
Thanks to everyone who posts to this forum. Some of this How-To was based on previous posts. You are all a big help
I followed the above step by step.
It works fine except one thing.
Although I made a new image for 'emphasis,' and put to toolbar folder,
the new image is not shown at http://www.searchresult.co.kr/fckeditor ... mple01.cfm
You can see my new image at http://220.89.242.20/FCKeditor/editor/s ... phasis.gif.
Did I put the new image to wrong place?
Would you tell me what did I wrong if you see it?
RE: Non-dialog Based Plugin
great job joon_star. Just wanted to find out if anyone has a cross browser solution for the example by joon_star. I need to get this working in firefox 1.0+
thanks in advance.
zawadi
RE: Non-dialog Based Plugin
anyone found a firefox fix for this yet?
zawadi
RE: Non-dialog Based Plugin
The image should be in Emphasis folder not in Toolbar folder.
RE: Non-dialog Based Plugin
My next question is do you know how to do it for a dialog pop box.