2

外部画像のみを挿入するカスタム画像プラグインを作成しました。しかし、デフォルトの画像プラグインを無効にすると、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'
        } );
    }
} );
4

2 に答える 2

3

CKEditor 4.1 で導入された ACF - Advanced Content Filter とプラグインを統合する必要があります。

これは便利なガイドです - Plugins integration with ACF .

基本的に、エディタに機能を導入しています。この機能は、HTML でどのように表現されるかをエディターに伝える必要があるため、この機能が有効になっているときに何が許可される必要があります。

最も単純なケースでは、コマンドを実行するボタンがある場合、CKEDITOR.featureインターフェイスの 2 つのプロパティを定義するだけで済みます: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+'" />');
    }
} );

そして、このボタンがツールバーに追加されると、機能が自動的に有効になり、画像が許可されます。

于 2013-07-08T08:28:09.573 に答える
0

addButton 設定で間違ったコマンド名を設定しました。以下を設定する必要があります。

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

の構成の名前と同様commandeditor.ui.addButton()

UPD: フィドル: http://jsfiddle.net/kreeg/2Jzpr/522/

于 2013-07-07T05:54:10.173 に答える