2013-07-06 105 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+'" />'); 
    } 
}); 

而现在,当此按钮将被添加到工具栏,功能将被自动启用和图像将被允许。