FCKeditor Plug-in Development sample (detailed version) _ Web page Editor

Source: Internet
Author: User
(FCKeditor. Address is: http://www.fckeditor.net/. I downloaded the version is: 2.6.3. )
What?
FCKeditor has always been a better choice for editors on the web, and he is open source and works well. The FCKeditor plug-in is an extension of the FCKeditor function.
Why?
Although FCKeditor can be adapted to use under general conditions, you may not be satisfied with the fckeditor only function, good. FCKeditor provides the plugin open function, as long as you can think of, you do it.
How ?
I have a simple "Hello" as an example to introduce the development of FCKeditor plug-in (affirmation: I am also a rookie, there is nothing wrong, please point out, we progress. )
First, enter the plugins directory under the editor file under the FCKeditor Editor directory. This directory is for FCKeditor plug-ins. So, create a folder named ' Hello '.
The second step is to enter the ' Hello ' folder. Create a "fckplugin.js" file. This is necessary for FCKeditor Plug-ins, mainly plug-in registration and so on.
Create a language file again. Create a folder for ' Lang ' under the ' Hello ' folder. To create a language file under the ' Lang ' folder, the language file name of the FCKeditor plug-in is: Country or region. js. such as China is zh.js. Simplified Chinese is zh-cn.js. English is en.js and so on. We set up two "En.js" and "Zh-cn.js".
Then edit the language file. We edit "En.js". Write the following: fcklang.hello= "Hello";(note contains ";", JS code, in the "Zh-cn.js" write: fcklang.hello= "HI";
The FCKeditor plug-in language is named: Fcklang. Variable name = "Language Definition"
OK, the language problem definition is complete, then the plug-in definition.
Open the second step of "Fckplugin.js".
Copy Code code as follows:

Registered
Fckcommands.registercommand (' Hello ', new Fckdialogcommand (' Hello ', fcklang.hellob,fckplugins.items[' hello '). path+ "hello.html", 200,200));
Defining toolbars
var nhello=new fcktoolbarbutton (' Hello ', Fcklang.hello);
nhello.iconpath=fckplugins.items[' Hello ']. path+ ' Hello. GIF ';
Registered
Fcktoolbaritems.registeritem (' Hello ', Nhello);

OK, don't you understand? Detailed Description:

Plugin mechanism: Register command-Define toolbars-register to Toolbars

Registration Command:: Fckcommands.registercommand (Command name, dialog box command)

dialog box command: Fckdialogcommand (command name, dialog box title, URl, width, height)

This completes the registration command and then defines a toolbar

Fcktoolbarbutton (Command name, button caption)

You'd better add an icon:iconpath= icon Address

Now the command is also registered, the toolbar is defined and then added:

Fcktoolbaritems.registeritem (command name, toolbar);

Note: "Hello.html" is what you want to display in HTML should contain the following statement.

Copy Code code as follows:

<script language= "JavaScript" >
var dialog = Window.parent;
var oeditor = dialog. Innerdialogloaded ();
var Fcklang = Oeditor.fcklang;
</script>

OK. The plugin is finished, how to show it?

Find "Fckconfig.js" in the FCKeditor directory, which is the FCKeditor settings file. Found it

"Fckconfig.pluginspath = Fckconfig.basepath + ' plugins/';"

Add: "FCKConfig.Plugins.Add (' Hello ', ' zh-cn,en '); "

Explanation:FCKConfig.Plugins.Add (plugin name, ' language file '); The language file is optional, and if not, it is automatically set.

Then in the "fckconfig.toolbarsets[" Default "]=." "[]" in the "[]" Add casually ' Hello ' (note contains quotes).

Ok...! Complete

OK, let's reconfirm the process of FCKeditor plug-in development:

Create "Fckplugin.js"-Create plug-ins (language files, etc.)-add plug-ins.

Necessary steps to create a plug-in: Insert Registration command-Define toolbars-register to toolbars

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.