use*_*483 7 javascript ckeditor
我正在使用CKEditor版本3.6
我想自动添加class="newsleft"到通过WYSIWYG 添加的任何图像标签.
我看过几篇提到dataProcessor的帖子,但不知道应该添加哪个文件或者怎么做.
有人能告诉我在哪里放置以下代码吗?
editor.dataProcessor.htmlFilter.addRules(
{
elements:
{
img: function( element )
{
if ( !element.attributes.alt )
element.attributes.alt = 'An image';
}
}
} );
Run Code Online (Sandbox Code Playgroud)
ole*_*leq 11
基本上把它放在instanceReady听众中它会很好(3.x和4.x)(小提琴):
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' );
}
}
} );
}
}
} );
Run Code Online (Sandbox Code Playgroud)
CKEDITOR.htmlParser.element.addClass自CKEditor 4.4起可用.您可以this.attributes[ 'class' ]在该版本之前使用.
这是另一种方法:
CKEDITOR.on( 'instanceReady', function( evt ) {
evt.editor.dataProcessor.htmlFilter.addRules( {
elements: {
img: function(el) {
el.addClass('img-responsive');
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
这在3.6中对我有用
将以下代码添加到config.js
CKEDITOR.on('dialogDefinition', function (ev) {
// Take the dialog name and its definition from the event data.
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
// Check if the definition is image dialog window
if (dialogName == 'image') {
// Get a reference to the "Advanced" tab.
var advanced = dialogDefinition.getContents('advanced');
// Set the default value CSS class
var styles = advanced.get('txtGenClass');
styles['default'] = 'newsleft';
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9507 次 |
| 最近记录: |