Reputation: 6829
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);
});
});
Upvotes: 3
Views: 9803
Reputation: 2097
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 script on github: jQuery-UI-Dialog-extended
Upvotes: 0
Reputation: 11
I think that if you trigger the event resize off the dialog it should do it.
$( ".selector" ).dialog( "resize");
Upvotes: 0
Reputation: 372
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);
});
Upvotes: 11