我无法将Source按钮添加到CKEditor 4的工具栏

Sam*_*off 5 javascript ckeditor

我在将源按钮添加到CKEditor 4的工具栏时遇到问题.我今天刚刚下载了新的CKEditor.

我正在使用名为oConfig的配置对象:

oConfig.toolbar = 'Custom';
oConfig.toolbar_Custom = [
  ['Bold', 'Source', 'Italic']
];
Run Code Online (Sandbox Code Playgroud)

工具栏仅显示Bold和Italic按钮.来自CKEditor文档的这个例子告诉我它应该正常工作.

Wik*_*alc 13

它可能发生的原因有两个:

  1. 您已下载基本软件包,其中未包含sourcearea插件.

  2. 您在内联模式下使用CKEditor.源模式尚未在内联模式下可用.

  • 很可能在下一个主要版本(4.1)中,所以在大约3个月内.但是,如果我们发现社区确实需要它,我们就有可能更快地添加它.这是票:https://dev.ckeditor.com/ticket/9713 (3认同)

Erg*_*gec 12

未来的googlers,对于CKEditor v4.2,现在有一个插件可以在内联编辑模式下查看源代码.

http://ckeditor.com/addon/sourcedialog


小智 8

这是我制作的一个插件:

首先,在里面ckeditor/plugins/创建一个名为"htmlSource"的新文件夹,在里面创建一个名为"plugin.js"的文件,在这个文件里面粘贴下面的代码:

//-----------------------------Start Plugin Code-------------------------



plugInName = 'htmlSource';

CKEDITOR.plugins.add(plugInName,
{  
  init: function (editor) {

    editor.addCommand('htmlDialog', new CKEDITOR.dialogCommand('htmlDialog'));
    editor.ui.addButton(plugInName, {
        label: 'Html Source',
        icon: 'http://www.example.com/images/btn_html.png',
        command: 'htmlDialog'
    });

    CKEDITOR.dialog.add('htmlDialog', function (editor) {
        return {
            title: 'Fuente Html',
            minWidth: 600,
            minHeight: 400,
            contents: [
                        {
                            id: 'general',
                            label: 'Settings',
                            elements:
                            [
                            // UI elements of the Settings tab.
                                {
                                type: 'textarea',
                                id: 'contents',
                                rows: 25,
                                onShow: function () {
                                    this.setValue(editor.container.$.innerHTML);

                                },
                                commit: function (data) {              //--I get only the body part in case I paste a complete html
                                    data.contents = this.getValue().replace(/^[\S\s]*<body[^>]*?>/i, "").replace(/<\/body[\S\s]*$/i, "");
                                }

                            }
                                ]
                        }
                    ],

            onOk: function () {
                var data = {};
                this.commitContent(data);
                $(editor.container.$).html(data.contents);
            },
            onCancel: function () {
                //  console.log('Cancel');
            }
        };
    });
}


});

//--------------------Plugin Code Ends Here--------------------
Run Code Online (Sandbox Code Playgroud)

请注意,有一个名为icon的参数,你必须设置插件按钮图像的URL,我只是举一个例子url(' http://www.example.com/images/btn_html.png ')你必须使用一个有效的一个看到插件按钮.

要在ckeditor工具栏中设置此插件,必须在config.js文件中对其进行配置,例如:

CKEDITOR.editorConfig = function (config) {
    config.plugins =
    'htmlSource,' +    //Here is the plugin
    'about,' +
    'a11yhelp,' +
    'basicstyles,' +
    'bidi,' +
    .....;
config.toolbar = 'Full';   //Add the plugin to the full toolbar

config.toolbar_Full =      //Note that our plugin will be the first button in the toolbar
        [
        ['htmlSource', '-', 'Save', 'NewPage', 'Preview', '-', 'Templates'],
        ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print',    'SpellChecker', 'Scayt'],
        ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
        ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
        ['BidiLtr', 'BidiRtl'],
        '/',
        ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'],
        ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote', 'CreateDiv'],
        ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
        ['Link', 'Unlink', 'Anchor'],
        ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],
        '/',
        ['Styles', 'Format', 'Font', 'FontSize'],
        ['TextColor', 'BGColor'],
        ['Maximize', 'ShowBlocks', '-', 'About']
   ]; 
};
Run Code Online (Sandbox Code Playgroud)

我知道这是有效的,所以如果你遇到麻烦请告诉我.