views:

42

answers:

2

Using jQueryUI's dialog boxes, I want to popup information. My problem is I want to set the height of the dialog to however high the content is. If I don't specify a height, this works perfect. The height is automatically calculated based on the height of the content. Problem then is if the content is very tall, the dialog gets very tall too and goes below the window... maxHeight doesn't work well in this case either.

So I've been able to somewhat resolve this by adjusting the height and position after displaying the popup. However, while the content is being loaded (through ajax), it goes well below the screen. It's only after finishing that I can readjust the window. I'd rather not have that awkward delay.

UPDATE: Turns out I want something even more than just a maxHeight. I want a max INITIAL height. So after loading the dialog with data, it can only grow to a certain height. But after, you're allowed to expand the window. It's pretty easy to accomplish this:

$('<div><div></div></div>').attr('title', options.title).appendTo('body').dialog({
    open: function() {
        $(this).children().css('maxHeight', maxInitialHeight).load(url, function() {
            thisDialog.$dialog.dialog('option', 'position', 'center');
        });
    }
});

That will dynamically load a dialog from 'url' with content up to a maxInitialHeight height. The 2 divs nested are necessary.

A: 

You could insert your content inside a <div class="dialog-data" /> and make that div the content of your dialog.

Then you could, with CSS, specify a max-height and overflow: auto to your div.dialog-data.

Bertrand Marron
Interesting suggestion because at first thought this would cause an inner div that would be awkwardly smaller than the dialog when the dialog was expanded. But then I realize I wanted the overall dialog to have a max-height anyway. So I just make them above have equivalent (dialog has to be 52 pixels or so taller for the title bar) max-heights. So without testing it seems that your solution works. But I guess my workaround is more desirable even with the crazy expanding window in the beginning because it allows for an INITIAL max-height. Thinking how I could do the same for your solution.
at
I'm posting my solution above which turned out to be somewhat simple. Your suggestion gave me the idea though and is close to the solution, so I'll credit you with the correct answer.
at
A: 

maybe like this

options.open = function() {
    var dialog = $(this).dialog('widget');
    var content = dialog.find('.ui-dialog-content');
    $.ajax({
        url: 'this your url',
        success: function(result, status, xhr) {
            content.empty().append(result);
            content.dialog(
                'option',
                {
                    // this your options
                }
            );
        };
    });
};
vitaly.batonov
I don't understand what you're trying to do. Is $content the same as $(this)? Or is it just content? In that case are you making a dialog within a dialog?
at
Returns the .ui-dialog element. http://jqueryui.com/demos/dialog/#method-widget
vitaly.batonov
ok, so if I understand this correctly, basically you're suggesting to load the ajax completely and then append it and the maxHeight option will work properly? Maybe, but I've got I think a better solution above.
at