CKeditor 给 img 标签添加 class

4
我正在尝试将类添加到CKeditor中插入的任何img标签中。我已经尝试了各种方法,但似乎无法弄清楚此插件设置的工作方式。虽然有大量文档,但它只提到需要添加代码,但没有说明应该在哪里添加,有很多文件。
我尝试将其添加到config.js底部。
/**
 * @license Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
 * For licensing, see LICENSE.md or http://ckeditor.com/license
 */

CKEDITOR.editorConfig = function( config ) {
    // Define changes to default configuration here.
    // For complete reference see:
    // http://docs.ckeditor.com/#!/api/CKEDITOR.config

    // The toolbar groups arrangement, optimized for two toolbar rows.
    config.toolbarGroups = [
        { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
        { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
        { name: 'links' },
        { name: 'insert' },
        { name: 'forms' },
        { name: 'tools' },
        { name: 'document',    groups: [ 'mode', 'document', 'doctools' ] },
        { name: 'others' },
        '/',
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
        { name: 'styles' },
        { name: 'colors' },
        { name: 'about' }
    ];

    // Remove some buttons provided by the standard plugins, which are
    // not needed in the Standard(s) toolbar.
    config.removeButtons = 'Underline,Subscript,Superscript';

    // Set the most common block elements.
    config.format_tags = 'p;h1;h2;h3;pre';

    // Simplify the dialog windows.
    config.removeDialogTabs = 'image:advanced;link:advanced';
    config.extraPlugins = 'confighelper';   

    config.stylesSet = 'my_styles';

};

CKEDITOR.stylesSet.add( 'my_styles', [

    { name: 'Custom Image', element: 'img', attributes: { 'class': 'myClass' }}
]);

这行不起作用

所以我尝试将其添加到实际的HTML页面中

<script>
CKEDITOR.stylesSet.add( 'my_styles', [

    { name: 'Custom Image', element: 'img', attributes: { 'class': 'myClass' }}
]);
</script>

那也行不通

看了他们的文档,我完全看不懂。 http://docs.ckeditor.com/#!/guide/dev_howtos_styles

如何在编辑器中添加类到任何img标签?

1个回答

0

我没有使用CKEDITOR,但问题可能是在CKEDITOR调用时未声明stylesSet,因为它稍后定义。尝试将CKEDITOR.stylesSet.add移动到editorConfig之前。

或者将您的样式放入第一个代码块中:

CKEDITOR.editorConfig = function( config ) {

   ...
   ...

   config.stylesSet = [
      { name: 'Custom Image', element: 'img', attributes: { 'class': 'myClass' }}
   ];

};
</script>

还有一些关于使用的文档http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-stylesSet


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接