2016-11-25 103 views
0

我试图自定义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');中做,让它拿起我的工具栏?

回答

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'; 
}; 

它的工作,所以我很满意。

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'] 
     ] 
    } 
} 
+0

是的,我试过了,它没有工作。我的解决方案是有效的 – HenryM