CKEditor #3 - Add your own toolbar plugin
Fri 8 Jun 2018, 11:50 AMTweet
by Ben Langhinrichs
This is the third in a series of short posts on configuring CKEditor, the web editor included with Domino. It is used by default for rich text fields in XPages, and in the second post, I showed how to use it for rich text fields in Classic Domino web design. I also showed how to configure the toolbar to include only the actions you want. In this post, I'll show how you can include your own actions, termed plugins, into the toolbar in both XPages and Classic.
1) A simple toolbar plugin
Toolbar actions can do a number of things. They can add content, they can manipulate existing content, and they can use content for some action outside of the rich text (like a button on a Notes form). I decided to build the classic Hello World action, represented by a globe icon. But in this case, when you say Hello, World!, it says Hello back to you. Here's how it will work:
2) Building the plugin
If you look at the directories under the data directory, you will find data\domino\html\ckeditor\plugins which has all sorts of existing plugins. I started by adding a subdirectory called hello, which will be the name of my plugin.
The plugin.js code is very simple, though plugins can be much more extensive:
3) Adding the plugin to XPages
We add a dojo attribute called extraPlugins with a value of "hello", and the modify the dojo attribute for toolbar to include the plugin. Here is the end result when seen in the source of the custom control:
When we open it up and hover over the globe icon, we see "Hello, World!" (the label from plugin.js):
and when we click on the action, it inserts the HTML we want at the insertion point:
4) Adding the plugin to Classic
The only code we need to change is in the doLoadCKEditor function in JS Header. We need to add that same extraPlugins value, and we need to modify toolbar. Here is the modified functionto get the toolbar seen in the animated GIF at the beginning of this post:
All topics in the series
Copyright © 2018 Genii Software Ltd.
What has been said: