CKEditor Toolbar

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

(Toolbar Definition: Article section proof-read and corrected)
(Customizing the Toolbar: Article section proof-read)
Line 49: Line 49:
 
The '''Full''' definition contains numerous slash (<code>"/"</code>) characters that were placed between toolbar bands. They can be used to force a break at the point where they were placed, rendering the next toolbar band in a new row. This placement will not be changed when CKEditor is resized.
 
The '''Full''' definition contains numerous slash (<code>"/"</code>) characters that were placed between toolbar bands. They can be used to force a break at the point where they were placed, rendering the next toolbar band in a new row. This placement will not be changed when CKEditor is resized.
  
== Customizing the Toolbar ==
+
== Toolbar Customization ==
A simple way to configure all editors toolbar is by simply adding a custom toolbar definition inside the config.js file, or even better in a separated configuration file (see "[[CKEditor_3.x/Developers_Guide/Setting_Configurations|Setting Configurations]]"). The easiest way for that is by simply copying the above "Full" toolbar definition, and strip it down to your needs. For example, the following is a good recommended toolbar definition to have in the config.js file:  
+
A simple way to configure the toolbars of all CKEditor instances is to add a custom toolbar definition inside the <code>config.js</code> file, or even better &mdash; in a separate custom configuration file (see "[[CKEditor 3.x/Developers Guide/Setting Configurations|Setting Configuration]]"). The easiest way to do that is to copy the default '''Full''' toolbar definition, and strip it down to your needs.
 +
 
 +
For example, the following is a good recommended toolbar definition that can be placed in the <code>config.js</code> file:  
 
<source language="js">
 
<source language="js">
 
CKEDITOR.editorConfig = function( config )
 
CKEDITOR.editorConfig = function( config )
Line 71: Line 73:
 
};
 
};
 
</source>  
 
</source>  
You can create as many toolbar definitions as you want inside the configuration file. Later, based on some criteria, you can decide the toolbar to use for each editor instance. For example, with the following code, two editors are created in the page, each one using a different toolbar:  
+
Inside the configuration file you can create as many toolbar definitions as you need. Later, based on some criteria, you can choose the toolbar to use for each CKEditor instance. For example, with the following code, two editors are created on the page and each one is using a different toolbar:  
 
<source language="js">
 
<source language="js">
 
CKEDITOR.replace( 'editor1',
 
CKEDITOR.replace( 'editor1',
 
     {
 
     {
         toolbar&nbsp;: 'MyToolbar'
+
         toolbar : 'MyToolbar'
 
     });
 
     });
  
 
CKEDITOR.replace( 'editor2',
 
CKEDITOR.replace( 'editor2',
 
     {
 
     {
         toolbar&nbsp;: 'Basic'
+
         toolbar : 'Basic'
 
     });
 
     });
 
</source>  
 
</source>  
It's also possible to set the toolbar definition in-page, when creating the editor instance directly. In that case, just assign it to the toolbar setting directly, for example:  
+
It is also possible to set the toolbar definition in-page, at the same time when you create an editor instance. If this is the case, assign the toolbar setting directly to the editor instance, like in the example below:  
 
<source language="js">
 
<source language="js">
 
CKEDITOR.replace( 'editor1',
 
CKEDITOR.replace( 'editor1',
 
     {
 
     {
         toolbar&nbsp;:
+
         toolbar :
 
         [
 
         [
 
             ['Styles', 'Format'],
 
             ['Styles', 'Format'],

Revision as of 10:54, 13 January 2011

While CKEditor is full-featured WYSIWYG editor, not all of its options may be needed in all cases. Because of this, toolbar customization is one of the most common and required tasks when dealing with CKEditor.

Toolbar Definition

A toolbar definition is a JavaScript array that contains the elements to be displayed in all toolbar rows available in the editor.

The toolbar configuration can be defined in CKEditor using one of the following methods:

  • The toolbar setting.
  • The toolbar_name setting, where the name element is the name used to identify the toolbar in the toolbar setting.

The following code snippet contains the default CKEditor toolbar setting.

config.toolbar = 'Full';

config.toolbar_Full =
[
    ['Source','-','Save','NewPage','Preview','-','Templates'],
    ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
    ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
    '/',
    ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
    ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
    ['BidiLtr', 'BidiRtl'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'],
    '/',
    ['Styles','Format','Font','FontSize'],
    ['TextColor','BGColor'],
    ['Maximize', 'ShowBlocks','-','About']
];

config.toolbar_Basic =
[
    ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About']
];

Note that in the code above (just like in the default CKEditor configuration) two toolbar definitions have been defined. The first one is named Full and the second one is Basic. The toolbar was set to use the Full definition.

Toolbar Bands

Every toolbar definition is composed of a series of toolbar bands that are grouped in the final toolbar layout. The bands items move together to new rows when the editor is resized.

As visible in the code above, each toolbar band is defined as a separate JavaScript array of strings. Every string stands for a single toolbar item to be used. Toolbar items are defined by plugins.

You can also include a separator in the toolbar band by including a dash ("-") character in it.

Forcing Row Break

The Full definition contains numerous slash ("/") characters that were placed between toolbar bands. They can be used to force a break at the point where they were placed, rendering the next toolbar band in a new row. This placement will not be changed when CKEditor is resized.

Toolbar Customization

A simple way to configure the toolbars of all CKEditor instances is to add a custom toolbar definition inside the config.js file, or even better — in a separate custom configuration file (see "Setting Configuration"). The easiest way to do that is to copy the default Full toolbar definition, and strip it down to your needs.

For example, the following is a good recommended toolbar definition that can be placed in the config.js file:

CKEDITOR.editorConfig = function( config )
{
    config.toolbar = 'MyToolbar';

    config.toolbar_MyToolbar =
    [
        ['NewPage','Preview'],
        ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Scayt'],
        ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
        ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
        '/',
        ['Styles','Format'],
        ['Bold','Italic','Strike'],
        ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
        ['Link','Unlink','Anchor'],
        ['Maximize','-','About']
    ];
};

Inside the configuration file you can create as many toolbar definitions as you need. Later, based on some criteria, you can choose the toolbar to use for each CKEditor instance. For example, with the following code, two editors are created on the page and each one is using a different toolbar:

CKEDITOR.replace( 'editor1',
    {
        toolbar : 'MyToolbar'
    });

CKEDITOR.replace( 'editor2',
    {
        toolbar : 'Basic'
    });

It is also possible to set the toolbar definition in-page, at the same time when you create an editor instance. If this is the case, assign the toolbar setting directly to the editor instance, like in the example below:

CKEDITOR.replace( 'editor1',
    {
        toolbar :
        [
            ['Styles', 'Format'],
            ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', '-', 'About']
        ]
    });