3

I open jquery ui dialog and load some content in it. But when I resize browser jq dialog doesn't change it's width/height. I have tried a few thing but no luck. Here how I open it:

$(document).ready(function () {
    var wWidth = $(window).width();
            var dWidth = wWidth * 0.9;
            var wHeight = $(window).height();
            var dHeight = wHeight * 0.9;

            $(".openDialog").live("click", function (e) {
                e.preventDefault();
                $("<div></div>")
                    .addClass("dialog")
                    .attr("id", $(this).attr("data-dialog-id"))
                    .appendTo("body")
                    .dialog({
                        title: $(this).attr("data-dialog-title"),
                        close: function () { $(this).remove() },
                        modal: true,
                        resizable: false,
                        show: 'fade',
                        width: dWidth,
                        height: dHeight,                    
                        create: function (event, ui) {
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("display", "none");

                            $(this).parents(".ui-dialog").css("padding", 0);
                            $(this).parents(".ui-dialog").css("border", 0);
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("padding", 0);

                            $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("background", "#000000");
                            $(this).parents(".ui-dialog:first").find(".ui-dialog-content").css("overflow", "hidden");

                        }  

                    })
                    .load(this.href);
            });
$(window).resize(function () {
            var wWidth = $(window).width();
            var dWidth = wWidth * 0.9;
            var wHeight = $(window).height();
            var dHeight = wHeight * 0.9;
            $(".openDialog").dialog("option", "width", dWidth);
            $(".openDialog").dialog("option", "height", dHeight);
        });
});
0

3 Answers 3

11

After the dialog has been opened the width and height are static unless resized. Bind an event to the window resize that will change it instead.

$(window).resize(function() {
    var wWidth = $(window).width();
    var dWidth = wWidth * 0.9;
    var wHeight = $(window).height();
    var dHeight = wHeight * 0.9;
    $("#data-dialog-id").dialog("option", "width", dWidth);
    $("#data-dialog-id").dialog("option", "height", dHeight);
});
Sign up to request clarification or add additional context in comments.

7 Comments

I put whole my function for loading ui dialog in resize function that you provided. And I get dialog resized on browser resize but then I ui dialog is not modal it's displayed as a page and I get error: Uncaught ReferenceError: $ is not defined (anonymous function)
I would leave them as two separate functions. That way the resize isn't messing with the dialog's init. Just put the window resize function after your code in the document ready function.
I have updated question. I must do something wrong because it doesn't resize :(
I updated the function above. the dialog was actually attached to a new div element you are creating not openDialog. I should have read a little closer. Whatever you end up calling that new div is what you need in the resize function.
Wired I debug this function it gets value on resize but dialog stay the same :/
|
0

I think that if you trigger the event resize off the dialog it should do it.

$( ".selector" ).dialog( "resize");

1 Comment

That doesn't work. "Uncaught Error: no such method 'resize' for dialog widget instance"
0

It appears @jasonday has a nice script that amends the JQuery UI dialog functionality - seems to be working fairly well for me.

Here's his SO answer

Here's his script on github: jQuery-UI-Dialog-extended

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.