Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh jquery ui dialog position

I'm using a jquery dialog. The content of this dialog is dynamic so the height change when the dialog is open.

$("#a_div").dialog({ width: 400 });

The dialog initially appears center in the page. but when the height change is no more center.

How can i refresh the dialog's position without close and reopen it?

thanks

like image 998
Luca Romagnoli Avatar asked Mar 28 '11 08:03

Luca Romagnoli


People also ask

How can I fix the position of dialog box in jquery?

dialog({ autoOpen: true, title: user_str, height: 200, stack: true, sticky: true //uses ui dialog extension to keep it fixed });

How do you check if jquery dialog is initialized?

dialog( { ... } ); Then check for the class when needed: if ($("selector"). hasClass("initialized")) { ... }


1 Answers

If you want to use the exact position settings as used by jquery ui for the initial positioning, you can grab the options from the jquery ui code and use them again any time you want to reposition your dialog.

function refreshDialogPosition(id) {
    $("#" + id).position({
                        my: "center",
                        at: "center",
                        of: window,
                        collision: "fit",
                        // Ensure the titlebar is always visible
                        using: function (pos) {
                            var topOffset = $(this).css(pos).offset().top;
                            if (topOffset < 0) {
                                $(this).css("top", pos.top - topOffset);
                            }
                        }
                    });
}

Use:

refreshDialogPosition("YourDialogId");

This will also make sure your title bar is always visible. Otherwise your title bar will be outside your screen when using dialogs with large content. (content height > window height)

Have a nice day.

like image 141
ThdK Avatar answered Sep 23 '22 20:09

ThdK