javascript config.js 不适用于 CKEditor

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14095139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:41:54  来源:igfitidea点击:

config.js doesn't work for CKEditor

javascriptruby-on-railsckeditor

提问by marcamillion

I have the following in my config.jsfor CKEditor:

我的config.jsCKEditor 中有以下内容:

CKEDITOR.editorConfig = function( config )
{
    config.toolbar =
    [
        [ 'Source', '-', 'Bold', 'Italic' ]
    ];
    // config.toolbar_Basic =
    // [
    //     [ 'Source', '-', 'Bold', 'Italic' ]
    // ];
    // config.toolbar = 'Basic';
}

The editor is still showing with all the options in the toolbar.

编辑器仍然显示工具栏中的所有选项。

It is also loading the JS files in the right order:

它还以正确的顺序加载 JS 文件:

<script src="/assets/ckeditor/init.js?body=1" type="text/javascript"></script>
<script src="/assets/ckeditor/ckeditor.js?body=1" type="text/javascript"></script>
<script src="/assets/ckeditor/config.js?body=1" type="text/javascript"></script>

So I am not sure what is happening here. Any thoughts?

所以我不确定这里发生了什么。有什么想法吗?

Also important to note that I tried the alternative way of declaring that Basictoolbar (see the commented out code in the snippet above) and it didn't work either.

同样重要的是要注意,我尝试了声明该Basic工具栏的替代方法(请参阅上面代码段中注释掉的代码),但它也不起作用。

After every change, I restart my server.

每次更改后,我都会重新启动服务器。

采纳答案by Jeroen K

How do you load you ckeditor in place of the textarea? Maybe the toolbar is overridden there.

你如何加载 ckeditor 来代替 textarea?也许工具栏在那里被覆盖。

回答by Reinmar

Your config.jsfile looks OK (both versions of it).

您的config.js文件看起来不错(它的两个版本)。

What may be wrong is how you load CKEditor. First of all - you don't need to load config.js - CKEditor will do that. Second, what's in the init.jsfile?

可能有问题的是您加载 CKEditor 的方式。首先 - 你不需要加载 config.js - CKEditor 会这样做。第二,init.js文件里有什么?

Have you cleared a cache in your browser? On some it can be really hard to do that automatically.

您是否清除了浏览器中的缓存?在某些情况下,很难自动做到这一点。

回答by Jignesh.Raj

Download CKEditor 3.2.1 here: http://ckeditor.com/download

在此处下载 CKEditor 3.2.1:http: //ckeditor.com/download

Extract the downloaded .tar.gz file.

提取下载的 .tar.gz 文件。

Copy the contents of the ckeditor folder into /sites/all/modules/contrib/ckeditor/ckeditor

将ckeditor文件夹的内容复制到/sites/all/modules/contrib/ckeditor/ckeditor

At this point you may want to edit the available toolbar options removing any unnecessary items. In most cases, I prefer the following configuration as it allows maximum fanciness while minimizing the types of markup which could override the site's styling

此时,您可能需要编辑可用的工具栏选项以删除所有不必要的项目。在大多数情况下,我更喜欢以下配置,因为它允许最大程度的幻想,同时最大限度地减少可能覆盖网站样式的标记类型

edit /sites/all/modules/contrib/ckeditor/ckeditor.config.js

编辑/sites/all/modules/contrib/ckeditor/ckeditor.config.js

Create a new toolbar by adding the following configuration to ckeditor.config.js:

通过将以下配置添加到 ckeditor.config.js 来创建一个新工具栏:

**

**

config.toolbar_DrupalCustom = [
      ['Source'],
      ['Cut','Copy','Paste','PasteText','-','SpellChecker', 'Scayt'],
      ['Undo','Redo','Find','Replace','-','SelectAll','RemoveFormat'],
      ['Image','HorizontalRule','Smiley','SpecialChar'],
      ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
      ['NumberedList','BulletedList','-','Blockquote'],
      ['Link','Unlink','Anchor','LinkToNode', 'LinkToMenu'],      
      ['Format','Font','FontSize'],
      ['TextColor','BGColor'],
      ['Maximize', 'ShowBlocks'],
      ['DrupalBreak', 'DrupalPageBreak']
     ];

** You can now select this option within the CKEditor Appearance section at /admin/settings/ckeditor/edit/Advanced

** 您现在可以在 /admin/settings/ckeditor/edit/Advanced 的 CKEditor Appearance 部分中选择此选项

回答by Shaakir

I too had problems with CKEditor and the "caching" issue. Cleared cache, loaded a custom config file... and timestamps...

我也遇到了 CKEditor 和“缓存”问题。清除缓存,加载自定义配置文件...和时间戳...

http://ckeditor.com/forums/CKEditor/Problem-with-config.js-not-updating

http://ckeditor.com/forums/CKEditor/Problem-with-config.js-not-updating

Nothing worked. Then i simply added it as options when instantiating the editor:

没有任何效果。然后我在实例化编辑器时简单地将它添加为选项:

CKEDITOR.replace( 'controls_' + int_control_cnt + '_label_text' ,
            {
            toolbar: [
                ['Bold', 'Italic', 'Underline', '-', 'TextColor', '-', 'RemoveFormat'],
                ['Cut', 'Copy', 'Paste', '-', 'Undo', 'Redo']
            ]
            });

This did the trick

这成功了

回答by jungleAl

use only: <script src="ckeditor/ckeditor.js"></script>

仅使用: <script src="ckeditor/ckeditor.js"></script>

and be sure to clear your browser cache!

并确保清除浏览器缓存!