2013-07-06 104 views
2

我已經創建了只插入外部圖像的自定義圖像插件。但是,如果我禁用默認圖像插件,那麼img標籤不會出現在窗體中。爲什麼?如何允許img標籤?

這是我的插件:

CKEDITOR.plugins.add('img', 
{ 
    init: function(editor) 
    { 
     editor.addCommand('insertImg', 
      { 
       exec : function(editor) 
       {  
        var imgurl=prompt("Insert url image"); 
        editor.insertHtml('<img src="'+imgurl+'" />'); 
       } 
      }); 
     editor.ui.addButton('img', 
     { 

      label: 'Insert img', 
      command: 'insertImg', 
      icon: this.path + 'images/aaa.png' 
     }); 
    } 
}); 

回答

0

你設置你的Add按鈕配置錯誤的命令名稱。您需要設置:

editor.addCommand('insertImg', { 
     ... 
    } 
); 

以及command配置的名稱editor.ui.addButton()

UPD: 一些小提琴:http://jsfiddle.net/kreeg/2Jzpr/522/

+0

您的權利,但img標籤不工作:( – xRobot

+0

會顯示您的jsfiddle PLZ –

+0

我創造了一些搗鼓你一切正常:?http://jsfiddle.net/kreeg/2Jzpr/522/ –

3

你需要你的插件與ACF整合 - 高級內容在CKEditor 4.1中引入的過濾器。

這裏有一個有用的指南 - Plugins integration with ACF

基本上,你正在向編輯介紹一個功能。此功能需要告訴編輯器如何以HTML表示,因此啓用此功能時應該允許該功能。

在最簡單的情況下,當你有一個按鈕,它執行你只需要定義CKEDITOR.feature接口的兩個屬性的命令:allowedContentrequiredContent

例如爲:

editor.addCommand('insertImg', { 
    requiredContent: 'img[src]', // Minimal HTML which this feature requires to be enabled. 
    allowedContent: 'img[!src,alt,width,height]', // Maximum HTML which this feature may create. 
    exec: function(editor) {  
     var imgurl=prompt("Insert url image"); 
     editor.insertHtml('<img src="'+imgurl+'" />'); 
    } 
}); 

而現在,當此按鈕將被添加到工具欄,功能將被自動啓用和圖像將被允許。