2017-09-24 67 views
0

我需要自動添加類到每個img我在CKEditor中發佈自動添加類到插入到文本的每個img - CKEditor

例如,

class="simple-class"每IMG我添加

現在我只能通過在源手動鍵入類做手工,但它是有問題的,尤其是從源模式回來當這個類我加爲dissapearing。

搜索這一切可能的議題,並不能找到這個合適的解決方案:/

+0

的可能的複製[CKEditor的:在插入圖像定製HTML(HTTPS: //stackoverflow.com/questions/5024371/ckeditor-customized-html-on-inserting-an-image) – gaetanoM

回答

0
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; 
     var editor = ev.editor; 
     if (dialogName == 'image') { 
      dialogDefinition.onOk = function(e) { 
       var imageSrcUrl = e.sender.originalElement.$.src; 
       var imgHtml = CKEDITOR.dom.element.createFromHtml("<img src=" + imageSrcUrl + " alt='' align='right'" + "class=className/>"); 
       editor.insertElement(imgHtml); 
      }; 
     } 
    } 

來源:https://stackoverflow.com/a/5071771/4925026

相關問題