How to add class or attribute automatically to img tags in CKEditor?

前端 未结 5 1841
眼角桃花
眼角桃花 2020-12-31 21:20

I\'m using CKEditor version 3.6

I want to automatically add class=\"newsleft\" to any image tag added through the WYSIWYG.

I\'ve seen a few post

5条回答
  •  灰色年华
    2020-12-31 22:09

    this worked for me in 3.6

    add the following code to 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';
        }
    });
    

提交回复
热议问题