2014-10-03 90 views
3

我想添加一个类到CKeditor中的任何插入的img标记。我尝试了各种方法,但似乎无法弄清楚这个插件的设置是如何工作的。虽然有大量的文档,但它只提到了需要添加代码,但不是应该添加的地方,还有大量文件。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标签?

回答

0

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

或者把你的风格为第一码块:

CKEDITOR.editorConfig = function(config) { 

    ... 
    ... 

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

}; 
</script> 

也有一些使用方法的更多文档http://docs.ckeditor.com/#!/api/CKEDITOR.config-cfg-stylesSet