Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit Size Of JQuery UI Dialog Widget?

A JQuery UI Dialog widget with lots of text in it is too big, the dialog doesn't fit in the window (user has to scroll browser window; user experience: "that's a bug"):

$("#div_dialog").dialog({title: "Header"});

http://jsfiddle.net/w92TY/83/

Setting the height option to 'auto' does not help, the dialog still doesn't fit in the window:

$("#div_dialog").dialog({title: "Header", width: 'auto', height: 'auto'});

http://jsfiddle.net/w92TY/84/

Setting the initial size to a fixed value would work...

$("#div_dialog").dialog({title: "Header", width: 100, height: 100});

http://jsfiddle.net/w92TY/85/ ... but that's not what I want either.
The widget should just grow in size if necessary (based on contents) but not outgrow the window.

Basically I'm looking for something like this ('90%' does not work because a numeric value in pixels is expected):

$("#div_dialog").dialog({title: "Header", maxHeight: '90%'});

http://jsfiddle.net/w92TY/87/

This is probably really simple but I can't seem to find the right option...

like image 865
basic6 Avatar asked Oct 20 '22 11:10

basic6


1 Answers

You can use $(window).height() * 0.9 to get 90% of a window, and also set max height dynamically when dialog opens (in case window was resized/rotated).

And.. looks like it does not respect maxHeight property when dialog does not have fixed height (height:auto), so you can set it via max-height css property, after you resize dialog first time it should obtain fixed height and maxHeight will work from that time

$("#div_dialog").dialog({
    title: "Header", 
    maxHeight:$(window).height() * 0.9,
    open:function(event, ui){
        $(this).css("max-height", $(window).height() * 0.9);
    }
});
like image 95
paulitto Avatar answered Oct 23 '22 06:10

paulitto