开发者

CKeditor select the upload tab in image dialog by default

开发者 https://www.devze.com 2023-03-19 20:44 出处:网络
Is there a way to modify the image dialog of CKEditor to display the upload tab by default instead of the Image info tab?

Is there a way to modify the image dialog of CKEditor to display the upload tab by default instead of the Image info tab?

I've tried doing this by adding a line of code to 开发者_如何学Cthe onload of the dialog:

onLoad: function() {
    this.getDialog().selectPage('Upload');
}

this seems to work fine, I'm able to upload the image to the server, but as soon as I hit the ok button I get a permission denied error.

I've also tried it the way CKSource describes but this gives me an exception since it overrides the onShow method.


Fixed this by adding this.selectPage('Upload'); to the end of the onShow function of the image plugin


As you noticed, the example in the docs is broken because the Image plugin already has an onShow() method.

The trick is to chain the methods like this:

CKEDITOR.on('dialogDefinition', function(e) {
    if (e.data.name == 'image') {
        var dialog = e.data.definition;
        oldOnShow = dialog.onShow;
        dialog.onShow = function() {
             oldOnShow.apply(this, arguments);
             this.selectPage('Upload');
        };
    }
});


This doc explains how to set a dialog tab by default in your ckeditor config:

http://docs.cksource.com/CKEditor_3.x/Howto/Default_Dialog_Tab


Can user following script.

<script type="text/javascript">

    CKEDITOR.on('dialogDefinition', function(ev) {

    var dialogName = ev.data.name;
    var dialogDefinition = ev.data.definition;

    if (dialogName == 'image') {
        dialogDefinition.onShow = function () {
            // This code will open the Upload tab.
            this.selectPage('Upload');
        };
    }
});
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消