Javascript 如何使用 jQuery 适配器将配置信息传递给 CKEditor?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2189700/
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-08-22 23:09:58  来源:igfitidea点击:

How do I pass in config info to CKEditor using the jQuery adapter?

javascriptjqueryckeditor

提问by alex

I'm using the latest CKeditorwith jQuery adapter.

我正在使用最新的CKeditorjQuery 适配器

I have successfully got it to work, and display.

我已经成功地让它工作并显示出来。

However, as I am completely new to CKeditor, how do I pass in config variables using the jQuerymethod?

但是,由于我对CKeditor完全陌生,我如何使用jQuery方法传入配置变量?

This is what I've got

这就是我所拥有的

$( '#input-content' ).ckeditor('', {
    toolbar: 'basic'
});

I think from what I've read, the first argument is meant to be a callback, and the 2nd the config. But doing this has not changed the editor at all.

我认为从我读过的内容来看,第一个参数是回调,第二个参数是配置。但是这样做并没有改变编辑器。

How do I use these config propertiesetc using the jQueryadapter?

如何使用jQuery适配器使用这些配置属性等?

采纳答案by alex

I passed an empty function...

我传递了一个空函数...

$('textarea#my').ckeditor($.noop, {
    property: 'value'
});

回答by Greg Randall

I have accomplished this using this code. Hopefully this helps.

我已经使用此代码完成了此操作。希望这会有所帮助。

Here is the html:

这是html:

<textarea id="txtMessage" class="editor"></textarea>

and here is the javascript:

这是javascript:

try {
        var config =
            {
                height: 180,
                width: 515,
                linkShowAdvancedTab: false,
                scayt_autoStartup: true,
                enterMode: Number(2),
                toolbar_Full: [['Styles', 'Bold', 'Italic', 'Underline', 'SpellChecker', 'Scayt', '-', 'NumberedList', 'BulletedList'],
                                ['Link', 'Unlink'], ['Undo', 'Redo', '-', 'SelectAll']]

            };

        $('textarea.editor').ckeditor(config);   }

回答by Rodrigo

jQuery(function(){
        var config = {
            toolbar:
            [
                ['Bold', 'Italic', 'Underline', '-', 'NumberedList', 'BulletedList', '-', 'Undo', 'Redo', '-', 'SelectAll'],
                ['UIColor']
            ]
        };      
        jQuery('#textAreaElement').ckeditor(config);
    });

回答by tim

var config = {
    toolbar:
    [
        ['Source','-','Save','NewPage','Preview','-','Templates'],
        ['Maximize', 'ShowBlocks','-','About']
    ],
    coreStyles_bold: { element : 'b', overrides : 'strong' }
};

Simply add the respective config object, above I added coreStyles_bold, All I did is change the "=" from the CK API documentation to a ":"

只需添加相应的配置对象,上面我添加了coreStyles_bold,我所做的就是将CK API文档中的“=”更改为“:”

回答by anonimo

 $(document).ready(function(){
     $('.reply').click(
     function(event){
         // Event click Off Default
         event.preventDefault();
         // CKEditor
         $(function(){
             var config = {toolbar:[['Bold', 'Italic', '-', 'Link', 'Unlink']]};
            //<?php /*echo"var config = {toolbar:[['Bold', 'Italic', '-', 'Link', 'Unlink']]};" ;*/ ?>
             // DOM class = "cke"
             $('textarea.cke').ckeditor(function(){}, config);                
         });
         return false;
     });
 });

回答by nokturnal

Not sure if this is a new feature of CKEDITOR, but just want to share my solution (in case it helps anyone looking for this now):

不确定这是否是 CKEDITOR 的新功能,但只是想分享我的解决方案(以防它可以帮助现在寻找此功能的任何人):

$("textarea.youreditor").ckeditor
(
    {
        customConfig: "/path/to/custom/config.js"
    }
);

... and my config looks like this (simply copied the default config.js):

...我的配置看起来像这样(简单地复制了默认的 config.js):

CKEDITOR.editorConfig = function(config)
{
    config.toolbar_Full =
    [
        { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
        { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'] },
        { name: 'insert', items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe' ] },
        { name: 'colors', items : [ 'TextColor','BGColor' ] }
    ];  
};    

回答by Wiktor Walc

There is an official documentation for it, see jQuery Adapter

有一个官方文档,请参阅jQuery Adapter

The ckeditor() method accepts two optional parameters:

ckeditor() 方法接受两个可选参数:

  • A callback function to be executed when the editor is ready.
  • Configuration options specific to the created editor instance:
  • 当编辑器准备好时要执行的回调函数。
  • 特定于创建的编辑器实例的配置选项:
    $( 'textarea' ).ckeditor({
        uiColor: '#9AB8F3'
    });