1

CKEditor プラグインをコーディングしたい。パネルにボタンを追加し、それを押すとダイアログが表示されます。このダイアログでテキストを設定し、[OK] を押すと、このテキストがエディターに挿入されます。

しかし、私は機能を追加したい。エディターでテキストを選択してこのボタンを押すと、そのダイアログ フィールドに選択したテキストが表示されます。編集後、[OK] を押して、選択したテキストを新しいテキストに置き換える必要があります。

ありがとう!

4

2 に答える 2

3

これは 100% 機能していません。最初の部分は機能していますが、最終的な交換は機能していません..

CKEDITOR.plugins.add( 'example',
{
    init: function( editor )
    {
        editor.addCommand( 'exampleDialog', new CKEDITOR.dialogCommand( 'exampleDialog' ) );

        editor.ui.addButton( 'example',
        {
            label: 'Insert a Link',
            command: 'exampleDialog'//,
            //icon: this.path + 'images/icon.png'
        } );

        CKEDITOR.dialog.add( 'exampleDialog', function( editor )
        {
            return {
                title : 'example Properties',
                minWidth : 400,
                minHeight : 200,
                contents :
                [
                    {
                        id : 'general',
                        label : 'Settings',
                        elements :
                        [
                            {
                                type : 'text',
                                id : 'mystring',
                                label : 'text',                             
                                commit : function( data )
                                {
                                    data.text = this.getValue();
                                }
                            }
                        ]
                    }
                ],

                onShow : function() {
                    //this._ranges = editor.getSelection().getRanges()
                    var mySelection = editor.getSelection().getSelectedText();
                    this.setValueOf("general","mystring",mySelection);

                },

                onOk : function()
                {
                    var data = {};
                    this.commitContent( data );
                    var txt = data.text;


                    editor.insertText(txt);  //this is not correct, since selection is being cleared...
                }
            };
        });
    }
});
于 2013-09-12T18:07:18.063 に答える
1

私の解決策は、単に onShow 関数内に設定することでした:

    onShow: function () {
        this.setValueOf('my-tab-id', 'my-element-id', editor.getSelection().getSelectedText());

        // ...
    },

完全なコード スケルトン:

(function () {
    CKEDITOR.dialog.add('mySelectorDialog', function (editor) {

        return {
            contents: [
                {
                    id: 'my-tab-id',
                    label: 'My Tab Label',
                    elements: [
                        {
                            id: 'my-element-id',
                            type: 'text',
                            label: 'My Element Label'
                        }
                        // ...
                    ]
                }
            ],

            onShow: function () {
                this.setValueOf('my-tab-id', 'my-element-id', editor.getSelection().getSelectedText());

                // ...
            },

            onOk: function () {
                // ...
            }

            // ...
        };
    });
})();
于 2016-06-09T13:30:36.390 に答える