Warm tip: This article is reproduced from serverfault.com, please click

CKEditor: Is it possible to limit the color choices for TextColor and BGColor?

发布于 2020-12-06 11:09:56

I am actually using django-ckeditor but, after asking this question relating it directly to it, I was advised to look it up in the CKEditor documentation—which I haven't found—or in a CKEditor forum.

What I want to do is to limit the color choices for TextColor and BGColor to white, black, yellow, green, blue, red, cyan, and magenta, and remove the button to select more colors. I'm sure the color selection is irrelevant once I know how to do it, but I'm just adding it for specificity.

Is this possible in CKEditor?

Questioner
TheSprinter
Viewed
0
ha-neul 2020-12-08 09:01:08

Yes, this is easy to do:

in your settings.py, you have

CKEDITOR_CONFIGS = {
     'default':{
        toolbar': 'default',
        'colorButton_colors': '008000,454545,FFF', #to set specific colors
        'colorButton_enableMore': False, # to remove more color button
},

Note these two lines are what you need to add.

        'colorButton_colors': '008000,454545,FFF', #to set specific colors
        'colorButton_enableMore': False, # to remove more color button

The widely used django-ckeditor is based on ckeditor4. If you want to modify default behavior, you search for ckeditor 4 doc.

For example, you are interested in text and background color, you google search ckeditor4 text background color, doc about text color will show up on your search result. There you see:

# this is a javascript code, you need to convert to python code.

config.colorButton_colors = 'CF5D4E,454545,FFF,DDD,CCEAEE,66AB16';

#change to :

'colorButton_colors': 'CF5D4E,454545,FFF,DDD,CCEAEE,66AB16', 

#and put into CKEDITOR_CONFIGS in settings.py