views:

836

answers:

2

I need to programmatically maximize / resize a CKEditor IFrame dialog (i.e. a CKEditor dialog with an "ok" and "cancel" button, and an iframe in it for the rest). I would need the dialog to stay centered on the screen.

I can see only functions to resize and re-position the window, but to use those, I'd have to calculate the window dimensions first to re-center it. This is stupid for a number of reasons, the API should handle that completely.

Is there an official API function to do this, or a safe workaround?

I can use JQuery but would really like to use native functions for this.

+1  A: 

I'm using CKEditor myself but have opted to use jquery's UI dialog for my custom dialogs as it is a lot more flexible and feature-rich out of the box, it's available at:

http://docs.jquery.com/UI/Dialog

But if you prefer on using a custom CKEditor dialog then jQuery's position():

http://api.jquery.com/position/

height(), width() and offset() are invaluable in determining the size and position of the dialog:

http://api.jquery.com/category/manipulation/style-properties/

mythz
Cheers @mythz, this sounds very interesting. For the moment, I have so much already invested into the CKEditor dialog system that I don't want to change with the project at hand, but for the next project I will definitely look at this.
Pekka
A: 

If you have both resize AND re-position, it can't be that hard do one function:

(it's pseudo javascript, since i don't have time to polish it, so basically idea)

function dialogResizeCentered (d,w,h){ //d-dialog, w,h-width, height
  var sw,sh; //screenwidth, screenheight
  var rx,ry; //null atm, for resize x, resize y
  get sw, sh from window. object
  rx = parseInt(sw/2-w/2);
  ry = parseInt(sh/2-h/2);
  d.call resize (w,h);
  d.call reposition(rx,ry);
}

and then anytime you can just call dialogResizeCentered(d,600,400);

or?

Or if you want your dialog to stay centered, i'm sure there is something like window.onResize event to call this function.

I hope I understand correctly :)

Adam Kiss
@Adam, resizing the dialog has a number of side-effects (I need to resize the embedded iframe as well, it has an absolute height because of some cross-browser issues, and possibly reposition some buttons). I would like to keep this as native as possible, as I'm developing a plug-in that I may want to put into (and distribute as) a stand-alone product. That's why I'm hoping to find a native function in the (still not very well documented) CKEditor API. Otherwise, I may well use something like this.
Pekka
@Pekka - Also, it seems that all dialogs are extended from basic editor. Couldn't you extend it to something like `nativePekkaDialog` and then use it as base for the dialogues you really want to use? Also, there must be way to stick `iframe` to bottom with `margin` `40px` for buttons.
Adam Kiss