将选项添加到ckeditor内联工具栏不起作用

时间:2013-01-28 23:23:58

标签: ckeditor

我在向CKEditor4内联工具栏选项添加工具栏选项时遇到了一些麻烦。我一直在阅读文档,但仍然无法弄清楚我的问题在哪里。

我正在创建一个div,然后将CKEditor添加到div中。一切正常,但我想删除一些工具栏选项并添加其他一些。当我向inline()调用添加参数时没有任何变化?

以下是我如何动态创建实例:

.on('dblclick', function(e){

    e.preventDefault();
    e.stopPropagation();
    ed.ck_restore();
    ed.ck_active_block = $(this).attr("id");
    ed.ck_block_data = $(this).html();
    var block_width = $(this).css("width"); 
    var block_height = $(this).css("height")+20;
    var block_padding_top = $(this).css("padding-top");
    var block_padding_right = $(this).css("padding-right");
    var block_padding_bottom = $(this).css("padding-bottom");
    var block_padding_left = $(this).css("padding-left");
    var padding = 'padding-top: '+block_padding_top+';padding-right: '+block_padding_right+';padding-bottom: '+block_padding_bottom+';padding-left: '+block_padding_left+';';

    var editor = '<div id="edit" contenteditable="true" style="margin-top: -'+block_padding_top+'; margin-left: -'+block_padding_left+';'+padding+' width: '+block_width+'; height: '+block_height+';background-color: #fff;position: absolute;">'+ed.ck_block_data+'</div>';

    $("#"+ed.ck_active_block).prepend(editor);

    if(CKEDITOR.instances.edit)
    {
        CKEDITOR.instances.edit.destroy(); //remove any previously created instances 
    }

    CKEDITOR.inline("edit",
                    [CKEDITOR.config.fontSize_style = {
                        element: 'span',
                        styles: { 'font-size': '#(size)' },
                        overrides: [ {
                            element: 'font', attributes: { 'size': null }
                        }]
                    }]
                    );

    $("#edit").click(function(e){e.stopPropagation();}).focus();
    $("w_save").text("1");
});  

http://docs.ckeditor.com/#!/api/CKEDITOR-method-inline

文档暗示我可以传递配置参数来更改选项,但我遗漏了一些东西,经过3个小时的尝试后我需要一些帮助。

感谢任何帮助。

感谢。

2 个答案:

答案 0 :(得分:0)

我不知道那意味着什么:

 CKEDITOR.inline("edit",
                [CKEDITOR.config.fontSize_style = {
                    element: 'span',
                    styles: { 'font-size': '#(size)' },
                    overrides: [ {
                        element: 'font', attributes: { 'size': null }
                    }]
                }]
                );

这是无效的JavaScript代码。你检查过JS控制台了吗?

无论如何,CKEDITOR.inline接受两个参数 - name和config object

CKEDITOR.inline( 'edit', {
    fontSize_style: {
        element: 'span',
        styles: { 'font-size': '#(size)' },
        overrides: [
            { element: 'font', attributes: { 'size': null } }
        ]
    },
    language: 'pl',
    removeButtons: 'Bold,Italic' // or set toolbar or toolbarGroups.
} );

答案 1 :(得分:0)

感谢Reinmar的回复。我能够找到另一种解决方案。以下是其他人的代码:

CKEDITOR.inline(“edit”,{customConfig:“mycustomConfig.js”});

这引用了一个自定义配置文件,我只是从CKEditor站点上的示例配置中提取它并更改了一些选项。立即行动。