无法自定义django-ckeditor工具栏

时间:2016-11-25 15:05:39

标签: javascript python django ckeditor

我正在尝试自定义django-ckeditor工具栏。

我的模型字段是:

answer = RichTextField(
    verbose_name    = "Answer presented to user",
    config_name     = 'answer_ckeditor',
    )

settings.py 中,我有

CKEDITOR_CONFIGS = {
    'answer_ckeditor': {
        'skin': 'moono',
        #'skin': 'office2013',
        'toolbar': [
            {'name': 'basicstyles',
             'items': ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat']},
            {'name': 'paragraph',
             'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-',
                       'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl',
                       'Language']},
            {'name': 'styles', 'items': ['Styles', 'Format', 'Font', 'FontSize']},
            {'name': 'colors', 'items': ['TextColor', 'BGColor']},
        ],
    }
}

我的 HTML 是:

<textarea id="answer_1" name="answer_1" required class="form-control quiz-search-box" placeholder="Option 1"></textarea>
<script>
    CKEDITOR.replace( 'answer_1' );
</script>

我只是得到标准的ckeditor菜单。我尝试使用默认值并从字段定义中删除config_name但没有区别。

我需要在JavaScript CKEDITOR.replace( 'answer_1' );中做些什么不同才能让它拿起我的工具栏?

2 个答案:

答案 0 :(得分:0)

这是我的解决方案。

我将CKEDITOR.replace( 'answer_1' );更改为CKEDITOR.replace( 'answer_1', {customConfig: "{% static 'js/custom/config.js' %}"});

config.js文件如下所示:

CKEDITOR.editorConfig = function( config ) {
    config.toolbarGroups = [
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
        { name: 'styles', groups: [ 'styles' ] },
        { name: 'colors', groups: [ 'colors' ] },
    ];

    config.removeButtons = 'Underline,Subscript,Superscript,Cut,Undo,Scayt,Link,Image,Maximize,Source,About';
};

它正在工作,所以我很满意。

答案 1 :(得分:0)

您是否尝试过documentation

CKEDITOR_CONFIGS = {
    'answer_ckeditor': {
        'skin': 'moono',
        #'skin': 'office2013',
        'toolbar': 'Custom',
        'toolbar_Custom': [
            ['Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat'],
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-',
                       'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl',
                       'Language'],
            ['Styles', 'Format', 'Font', 'FontSize'],
            ['TextColor', 'BGColor']
        ]
    }
}