简体   繁体   English

CKEditor工具栏配置不起作用

[英]CKEditor toolbar configuration not working

I recently started working with CKEditor, but the toolbar has functions we will not be using. 我最近开始使用CKEditor,但工具栏中有我们不会使用的功能。

I tried copying the code from the online toolbar configuration, but the toolbar doesn't change. 我尝试从在线工具栏配置中复制代码,但工具栏不会更改。

my config.js file looks like this: 我的config.js文件如下所示:

CKEDITOR.editorConfig = function( config ) {
    config.toolbarGroups = [
        { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
        { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
        { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
        { name: 'forms', groups: [ 'forms' ] },
        '/',
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
        { name: 'links', groups: [ 'links' ] },
        { name: 'insert', groups: [ 'insert' ] },
        '/',
        { name: 'styles', groups: [ 'styles' ] },
        { name: 'colors', groups: [ 'colors' ] },
        { name: 'tools', groups: [ 'tools' ] },
        { name: 'others', groups: [ 'others' ] },
        { name: 'about', groups: [ 'about' ] }
    ];

    config.removeButtons = 'Save,NewPage,Preview,Print,Replace,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Superscript,Subscript,Language,Anchor,Flash,PageBreak,About';
};

which was copies directly from the configuration tool. 这是直接从配置工具复制的。 After the above, I tried pasting the code into the initialization function like the following block: 在上面之后,我尝试将代码粘贴到初始化函数中,如下面的块:

jQuery(function() 
{   
    var editor = CKEDITOR.replace( 'message',
    {
        extraPlugins : 'stylesheetparser',
        extraPlugins : 'filebrowser',
        extraPlugins : 'popup',
        //contentsCss : '<?= base_url(); ?>css/layout.css',
         config.toolbarGroups = [
            { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
            { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
            { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
            { name: 'forms', groups: [ 'forms' ] },
            '/',
            { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
            { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
            { name: 'links', groups: [ 'links' ] },
            { name: 'insert', groups: [ 'insert' ] },
            '/',
            { name: 'styles', groups: [ 'styles' ] },
            { name: 'colors', groups: [ 'colors' ] },
            { name: 'tools', groups: [ 'tools' ] },
            { name: 'others', groups: [ 'others' ] },
            { name: 'about', groups: [ 'about' ] }
        ],
        config.removeButtons = 'Save,NewPage,Preview,Print,Replace,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Superscript,Subscript,Language,Anchor,Flash,PageBreak,About'
    });

    CKFinder.setupCKEditor(editor);
});

I also tried simply to show one part of the toolbar like this: 我也尝试过简单地显示工具栏的一部分,如下所示:

CKEDITOR.editorConfig = function( config ) {
         config.toolbar = [
        { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] }
    ];

    // Toolbar groups configuration.
    config.toolbarGroups = [
        { name: 'clipboard', groups: [ 'clipboard', 'undo' ] }
    ];
};

None of the above changed anything in the toolbar, so I am not sure if I overlooked something. 以上都没有改变工具栏中的任何内容,因此我不确定是否忽略了某些内容。

Any help will be appreciated. 任何帮助将不胜感激。

Please make sure you properly define your configuration - check the Setting CKEditor Configuration article for some code examples. 请确保正确定义配置 - 有关一些代码示例,请查看“ 设置CKEditor配置”一文。 Some of the mistakes you are doing: 你正在做的一些错误:

  • Mixing up config.optionName and optionName . 混合config.optionNameoptionName
  • Declaring extraPlugins multiple times - you should put all extra plugins into one declaration: config.extraPlugins = 'myplugin,anotherplugin'; 多次声明extraPlugins - 你应该把所有额外的插件放到一个声明中: config.extraPlugins = 'myplugin,anotherplugin';

Also check some of the CKEditor SDK samples for examples - if you open any of them (like this one ), scroll down to the "Get Sample Source Code" section and grab the source code to copy. 另请参阅一些CKEditor SDK示例以获取示例 - 如果您打开其中任何一个( 如此 ),请向下滚动到“获取示例源代码”部分并获取要复制的源代码。

Last but not least, use the JavaScript console of your browser to check for errors and clear the cache after each change! 最后但同样重要的是,使用浏览器的JavaScript控制台检查错误并在每次更改后清除缓存!

And finally, it makes little sense to download a bloated CKEditor package and then remove plugins/buttons in your configuration - better create a custom build in CKBuilder . 最后,下载一个膨胀的CKEditor包然后删除配置中的插件/按钮是没有意义的 - 更好地在CKBuilder中创建自定义构建。

include:
<script type="text/javascript" src="js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="js/ckeditor/config.js"></script>

<textarea id="user_message"></textarea>
<script type="text/javascript">
var toolbarGroups = [
    { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
    { name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
    { name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
    { name: 'forms', groups: [ 'forms' ] },
    '/',
    { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
    { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
    { name: 'links', groups: [ 'links' ] },
    { name: 'insert', groups: [ 'insert' ] },
    '/',
    { name: 'styles', groups: [ 'styles' ] },
    { name: 'colors', groups: [ 'colors' ] },
    { name: 'tools', groups: [ 'tools' ] },
    { name: 'others', groups: [ 'others' ] },
    { name: 'about', groups: [ 'about' ] }
];

var initEditor = function() {
  return CKEDITOR.replace( 'user_message',{
    toolbar : 'Basic',
    uiColor : '#9AB8F3',
    toolbarGroups,
   });
}
initEditor();
</script>

Demo 演示 在此输入图像描述

my CKEditor config.js changes were not reflected in my toolbar until i put matched the same path as the Samples had. 我的CKEditor config.js更改没有反映在我的工具栏中,直到我将匹配的路径与Samples相同。 ex: the working sample has this path: 例如:工作样本有这条路径:

ckeditor\samples\index.html
ckeditor\config.js

so i made my working web page app with ckeditor this: 所以我用ckeditor制作了我的工作网页应用程序:

rootwebfolder/ckeditor/config.js
rootwebfolder/mywebpage.php

before, i had ckeditor on the same level as root, but i moved it into root. 之前,我把ckeditor放在与root相同的级别上,但我把它移到了root中。 of course i had to change the relative path statements, which are now this[and showing the other code that enables the div to show the CKEditor toolbar]: 当然我必须更改相对路径语句,现在这是[并显示使div能够显示CKEditor工具栏的其他代码]:

echo "<script type='text/javascript'> window.CKEDITOR_BASEPATH ='mydomain/mainfolder/rootwebfolder/ckeditor/';</script>";
echo "<script type='text/javascript' src='mydomain/mainfolder/rootwebfolder/ckeditor/ckeditor.js'></script>";
echo "<script type='text/javascript' src='mydomain/mainfolder/rootwebfolder/ckeditor/config.js'></script>";
echo "<div id = 'divname' name = 'divname' class = 'ckeditor' style='visibility:hidden; height:415px'></div>";
echo "<script type='text/javascript'>CKEDITOR.replace('divname');</script>";

i hope this helps someone! 我希望这可以帮助别人!

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

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