简体   繁体   English

无法自定义django-ckeditor工具栏

[英]Cannot customise django-ckeditor toolbar

I'm trying to customise a django-ckeditor toolbar. 我正在尝试自定义django-ckeditor工具栏。

My model field is: 我的模型字段是:

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

Within settings.py I have 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']},
        ],
    }
}

My HTML is: 我的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>

I just get the standard ckeditor menu. 我只是得到标准的ckeditor菜单。 I've tried using default and removing the config_name from the field definition but no difference. 我尝试使用默认值并从字段定义中删除config_name,但没有区别。

Is there something different I need to do in the JavaScript CKEDITOR.replace( 'answer_1' ); 我需要在JavaScript CKEDITOR.replace( 'answer_1' ); to get it to pick up my toolbar? 拿起我的工具栏?

Here's my solution. 这是我的解决方案。

I changed CKEDITOR.replace( 'answer_1' ); 我更改了CKEDITOR.replace( 'answer_1' ); to CKEDITOR.replace( 'answer_1', {customConfig: "{% static 'js/custom/config.js' %}"}); CKEDITOR.replace( 'answer_1', {customConfig: "{% static 'js/custom/config.js' %}"});

The config.js file looks like: 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';
};

It's working so I'm satisfied. 工作正常,我很满意。

Have you tried it like the 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']
        ]
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM