How to add default classname on the images i uploa

2019-08-30 04:08发布

问题:

Like the topic says: How to add default classname on the images i upload with CKEditor? Cant relly find any information regarding this

回答1:

CKEDITOR.on( 'instanceReady', function( ev )
{
	var editor = ev.editor;
 	var dataProcessor = editor.dataProcessor,
	            htmlFilter = dataProcessor && dataProcessor.htmlFilter;
	            htmlFilter.addRules(
	            {
	                elements:
	                {
	                    $: function (element) {
	                         if (element.name == 'img') {
	                            if (!element.attributes['class']){
	                                	element.attributes['class'] = "helloworld";
	                            }
	                        }
	                        return element;
	                    }
	                }
	            });
	
});

http://jsfiddle.net/z6y8q6rm/2/