mdupls
mdupls

Reputation: 2012

Programmatically change font size of text selection using CKEditor

I'm trying to use CKEditor simply as an API that I can drive with my own UI.

Firstly, is this the right use of CKEditor?

If so, how could I modify the font size of a text selection programmatically?

Upvotes: 0

Views: 1421

Answers (1)

Marek Lewandowski
Marek Lewandowski

Reputation: 3401

Creating own UI for CKEditor

It's a doable approach, but for some cases it might be tough and require some code duplication.

There are older parts of CKE that encapsulate many useful things, so you have no convenient API to access it from outside.

Adding a font size

The minimal effort would be to simply use CKEDITOR.style objects.

var editor = CKEDITOR.instances.editor1;
var style = new CKEDITOR.style( {
    element: 'span',
    styles: { 'font-size': '20px' }
} );

editor.applyStyle( style );

For more examples see font plugin, you're interested in fontSize combobox.

Upvotes: 2

Related Questions