我使用的是 CKEditor 版本 3.6
我想自动添加class="newsleft"
到通过所见即所得添加的任何图像标签。
我看过一些提到 dataProcessor 的帖子,但不知道应该添加哪个文件或如何添加。
有人可以告诉我在哪里放置以下代码吗?
editor.dataProcessor.htmlFilter.addRules(
{
elements:
{
img: function( element )
{
if ( !element.attributes.alt )
element.attributes.alt = 'An image';
}
}
} );
基本上放进去instanceReady监听器,那就没问题了(3.x 和 4.x)(fiddle):
CKEDITOR.replace( 'editor', {
plugins: 'wysiwygarea,toolbar,sourcearea,image,basicstyles',
on: {
instanceReady: function() {
this.dataProcessor.htmlFilter.addRules( {
elements: {
img: function( el ) {
// Add an attribute.
if ( !el.attributes.alt )
el.attributes.alt = 'An image';
// Add some class.
el.addClass( 'newsleft' );
}
}
} );
}
}
} );
CKEDITOR.htmlParser.element.addClass自 CKEditor 4.4 起可用。您可以使用this.attributes[ 'class' ]
在该版本之前。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)