CKEditor 4 - how to add font family and font size controls to the toolbar

允我心安 提交于 2019-12-08 15:47:08

问题


I have a config.toolbarGroups setting in config.js but I don't know what name to use for the groups to add font family/font size controls. (It seems the documentation is lacking in this regard). I've found some suggestion that I should use CKBuilder to create a package that already includes it, but I can't redeploy the entire ckeditor just to add a couple of buttons.

Edit: My CKEditor is version 4

Any advise?

Thanks!


回答1:


There are two (mutually exclusive) ways to configure the toolbar. Check out the following:

http://ckeditor.com/latest/samples/plugins/toolbar/toolbar.html

I tried to use config.toolbarGroups first, but ended up using config.toolbar instead. Here's what I ended up using:

config.toolbar = [
                { name: 'save', items: [ 'savebtn','Undo','Redo' ] },
                { name: 'clipboard', items: [ 'Cut','Copy','Paste','PasteText','PasteFromWord'] },
                { name: 'document', items: [ 'Find','Replace'] },
                '/',
                { name: 'lists', items: [ 'NumberedList','BulletedList','Outdent','Indent'] },
                { name: 'insert', items: [ 'Image','Table','Smiley','SpecialChar'] },
                { name: 'link', items: ['Link','Unlink'] },
                '/',
                { name: 'basicstyles', items: [ 'Font','FontSize','Bold','Italic','Underline','Strike','Subscript','Superscript'] },
                //'/',
                { name: 'align', items: [ 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'] }
        ];

Note that I am using a save plugin that was generously contributed by kasper Taeymans, which can be found at the following location:

How to add an ajax save button with loading gif to CKeditor 4.2.1. [Working Sample Plugin]

I also found the following document to be really useful, even though it related to version 3:

http://docs.cksource.com/CKEditor_3.x/Developers_Guide/Toolbar

I used the information in this article to produce my configuration (I'm using version 4.2.1), specifically the names of the items (e.g. Cut, Copy, Paste), as this was the missing link in my case.




回答2:


config.extraPlugins = 'font';

You have to add the plugin...




回答3:


This can be used to add font family and font size in the CkEditor.

This is to be done in config.js.

Also see docs

    config.font_names = 'Arial;Times New Roman;Verdana;' +  CKEDITOR.config.font_names;

config.toolbar_Full =
[
     { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },

    { name: 'paragraph', items : [ 'Outdent','Indent','-','Blockquote','CreateDiv','-',
                'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }    

];

config.toolbar = 'Full';



回答4:


Took me a long time to figure out that I explicitly had to add FontSize to the toolbar, too - doesn't seem to work with Font only.



来源:https://stackoverflow.com/questions/16184236/ckeditor-4-how-to-add-font-family-and-font-size-controls-to-the-toolbar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!