Question

I want to add one element (button, dropdown etc) to the standard toolbar of the CKEditor. Creating the item is simple (check this example). However all of the samples then go on and define their own toolbar.

I want to add the new element to an existing toolbar. How do I do that?

Was it helpful?

Solution

2 Steps are required:

  • get the current toolbar name (e.g. default)
  • modify the array of objects in that variable (e.h. toolbar_default)

Ideally you put that code into the init function which gets the editor object of the CKEditor as parameter:

 var config = editor.config;
 var toolbarName = config.toolbar;
 config["toolbar_"+toolbarName].push({"name" : "ANewName", "items" : ["yourCustomFunction"] });

name and items are fixed, while ANewName and yourCustomFunction is what you created. push appends your items at the end of the toolbar, but you can put them anywhere using standard array manipulation methods.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top