ckeditor dialog positioning

This may be way you're looking for:

Programatically set the position of CKEditor's dialogs


I just had the same issue as Yehonatan and found this question really fast via Google. But after using the answer provided by zaf I still didn't get a dialog to appear in the proper position when the editor is loaded within an iframe.

In stead of the position() method I used the offset() method to place a dialog right under the toolbar. Together with the response of jonespm I came to this code that seems to work very good, also with existing dialogs.

CKEDITOR.on('dialogDefinition', function(e) {
 var dialogName = e.data.name;
 var dialogDefinition = e.data.definition;
 var onShow = dialogDefinition.onShow;

 dialogDefinition.onShow = function() {

    this.move(this.getPosition().x, jQuery(this.getParentEditor().container.$).offset().top);

    if (typeof onShow !== 'undefined' && typeof onShow.call === 'function')
    {
        return onShow.call(this);
    }

 }  
});

Hopefully this code can help others with the same issue as me.


Yes, the link MDaubs gives will guide you to do what you want.

I've had to do this in the past and the following snippet will demonstrate a solution for your problem:

CKEDITOR.on('dialogDefinition', function(e) {
    var dialogName = e.data.name;
    var dialogDefinition = e.data.definition;
    dialogDefinition.onShow = function() {
            this.move(this.getPosition().x,0); // Top center
    }
})

You can place this in the config file or the ready function for jQuery.


The solution by zaf works in that it helps to position the dialog, but I've found it to produce a bunch of side effects as to how the dialog functions (failing to display the URL of the image in the image dialog is one example).

It turned out that the original onShow() method that is being overridden returns a meaningful value that we should keep. This could be due to a plugin or something, but here's the code that ultimately worked for me:

CKEDITOR.on('dialogDefinition', function(e) {
  var dialogName = e.data.name;
  var dialogDefinition = e.data.definition;
  var onShow = dialogDefinition.onShow;
  dialogDefinition.onShow = function() {
    var result = onShow.call(this);
    this.move(this.getPosition().x, $(e.editor.container.$).position().top);
    return result;
  }
});