Search code examples
javascriptckeditor

CKeditor select the upload tab in image dialog by default


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 the 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.


Solution

  • 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');
            };
        }
    });