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

其他-CKEditor:是否可以限制TextColor和BGColor的颜色选择?

(其他 - CKEditor: Is it possible to limit the color choices for TextColor and BGColor?)

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

我实际上是在使用django-ckeditor,但是在问了与它直接相关的问题后,建议我在CKEditor文档(我没有找到)或CKEditor论坛中进行查找。

我要做的是将TextColor和BGColor的颜色选择限制为白色,黑色,黄色,绿色,蓝色,红色,青色和品红色,然后删除按钮以选择更多颜色。我确定一旦知道如何进行颜色选择就无关紧要,但我只是出于特定性而添加它。

在CKEditor中可以吗?

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

是的,这很容易做到:

在你settings.py,你有

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

请注意,这两行是你需要添加的内容。

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

广泛使用的django-ckeditor基于ckeditor4。如果要修改默认行为,请搜索ckeditor 4文档。

例如,你对文本和背景色感兴趣,你在google搜索中 ckeditor4 text background color有关文本颜色的文档将显示在搜索结果中。在那里,你会看到:

# 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