Submit a request
Submit a request

Customizing the RTE toolbar in Question Editor API

Introduction

If your text editor of choice is CKEditor, you can customize its toolbar by using the following init options:

  • rich_text_editor.toolbar_settings.ltr_toolbar for languages which are written from left to right (such as English and Spanish), and
  • rich_text_editor.toolbar_settings.rtl_toolbar for languages which are written from right to left (such as Arabic and Hebrew). In order to use the rtl_toolbar setting, you need to configure Author API and Question Editor API to initialize in right-to-left mode, as described in this article.

The easiest way to customize a toolbar is to start with the default settings and change them as required.

 

Default settings

Toolbar settings are defined as an array of objects. Each object defines a toolbar group by specifying its name and the items (i.e. the buttons), which should be displayed as part of the group. The default toolbar looks like this:

Screen_Shot_2020-10-22_at_12.33.48_pm.png

Figure 1: the default CKEditor toolbar.

Its settings are:

'ltr_toolbar': [
{
'name': 'basicstyles',
'items': ['Bold', 'Italic', 'Underline', '-', 'TextColor', '-',
'LrnUnderlinedIndicator', '-', 'RemoveFormat', 'FontSize']
},
{
'name': 'list',
'items': ['NumberedList', 'BulletedList', '-', 'Indent', 'Outdent']
},
{
'name': 'justify',
'items': ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock']
},
{
'name': 'link',
'items': ['Link', 'Unlink']
},
{
'name': 'insert',
'items': [
'Image', 'ckeditor_wiris_formulaEditor', 'ckeditor_wiris_formulaEditorChemistry',
'Table', 'Blockquote', 'SpecialChar'
]
},
{
'name': 'simplefeature',
'items': ['LrnSimpleFeature']
},
{
'name': 'resource',
'items': ['LrnResource']
},
{
'name': 'clipboard',
'items': ['Undo', 'Redo']
},
{
'name': 'style',
'items': ['Styles']
},
{
'name': 'mode',
'items': ['Sourcedialog']
},
{
'name': 'data',
'items': ['lrn_datatable']
}
]

Code sample 1: default CKEditor toolbar settings.

 

If you define customButtons, they are added at the end of the toolbar in a group named custombuttons.

 

Default settings for right-to-left

The default settings for the right-to-left toolbar are slightly different from the left-to-right settings:

'rtl_toolbar': [
{
'name': 'basicstyles',
'items': ['Bold', 'Italic', 'Underline', '-', 'TextColor', '-',
'LrnUnderlinedIndicator', '-', 'RemoveFormat', 'FontSize']
},
{
'name': 'list',
'items': ['NumberedList', 'BulletedList', '-', 'Indent', 'Outdent']
},
{
'name': 'justify',
'items': ['JustifyRight', 'JustifyCenter', 'JustifyLeft', 'JustifyBlock']
},
{
'name': 'link',
'items': ['Link', 'Unlink']
},
{
'name': 'insert',
'items': [
'Image', 'ckeditor_wiris_formulaEditor', 'ckeditor_wiris_formulaEditorChemistry',
'Table', 'Blockquote', 'SpecialChar'
]
},
{
'name': 'clipboard',
'items': ['Undo', 'Redo']
},
{
'name': 'style',
'items': ['Styles']
},
{
'name': 'mode',
'items': ['Sourcedialog']
},
{
'name': 'data',
'items': ['lrn_datatable']
},
{
'name': 'bidi',
'items': ['BidiLtr', 'BidiRtl']
}
]

Code sample 2: default CKEditor toolbar settings for right-to-left mode.

 

As for left-to-right, if you define customButtons, they are added at the end of the toolbar in a group named custombuttons.

 

Customization

To customize your toolbar, you can pick any of the buttons defined in the items and add them to groups as you please. Except for two special cases described further below, group names can be chosen arbitrarily. A dash - will add a vertical separator between two buttons. 

In order to display font sizes, italic, bold (separated by a vertical line) and underline only, you can define the following settings:

'toolbar_settings': {
'ltr_toolbar': [{
'name': 'mystyles',
'items': ['FontSize', 'Italic', '-', 'Bold', 'Underline']
}]
}

Code sample 3: configuration to show text formatting buttons.

 

The result will look like this:

Screen_Shot_2020-10-22_at_1.26.26_pm.png

(Note that the font size buttons is always displayed separately from its group. That's a CKEditor setting which cannot be changed.)

 

Special cases

Two special cases are worth noting when customizing the toolbar:

  1. If you define a group named basicstyles, the FontSize button will be added to the end of that group unless it is part of another group or font_sizes.enabled is set to false
  2. If you want to customize the location of custom buttons, you need to add a group named custombuttons at your desired location. There is no need to set the items of this group. A group namedcustombuttons can only be added, if you actually define custom buttons in your init options, otherwise an error is thrown. For example, if you have defined custom buttons and want to to display them as the first group, the following settings would work:
'ltr_toolbar': [
{
'name': 'custombuttons',
},
{
'name': 'basicstyles',
'items': ['Bold', 'Italic', 'Underline', '-', 'TextColor']
}
]

Code sample 4: customizing the location of custom buttons.

Was this article helpful?
0 out of 0 found this helpful

Did you arrive here by accident? If so, learn more about Learnosity by clicking here.