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

送分小仙女□ 提交于 2019-12-09 04:35:10

问题


I'm using the latest CKeditor with jQuery adapter.

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 jQuery method?

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 properties etc using the jQuery adapter?


回答1:


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

Here is the html:

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

and here is the 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);   }



回答2:


I passed an empty function...

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



回答3:


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



回答4:


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 ":"




回答5:


 $(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;
     });
 });



回答6:


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):

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

... and my config looks like this (simply copied the default 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' ] }
    ];  
};    



回答7:


There is an official documentation for it, see jQuery Adapter

The ckeditor() method accepts two optional parameters:

  • A callback function to be executed when the editor is ready.
  • Configuration options specific to the created editor instance:
    $( 'textarea' ).ckeditor({
        uiColor: '#9AB8F3'
    });


来源:https://stackoverflow.com/questions/2189700/how-do-i-pass-in-config-info-to-ckeditor-using-the-jquery-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!