Skip to content

Commit d0c11e9

Browse files
committed
fixed #3025 - dialog should have an autoResize option; default value: true
1 parent b07cac1 commit d0c11e9

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

tests/dialog.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
var defaults = {
1010
autoOpen: true,
11+
autoResize: true,
1112
buttons: {},
1213
disabled: false,
1314
dialogClass: null,
@@ -200,6 +201,25 @@ test("autoOpen", function() {
200201
el.remove();
201202
});
202203

204+
test("autoResize", function() {
205+
expect(2);
206+
el = $('<div>content<br>content<br>content<br>content<br>content</div>').dialog({ autoResize: false });
207+
var expected = { height: el.height() };
208+
var handle = $(".ui-resizable-se", dlg());
209+
drag(handle, 50, 50);
210+
var actual = { height: el.height() };
211+
compare2(actual, expected, '.dialog({ autoResize: false })');
212+
el.remove();
213+
el = $('<div>content<br>content<br>content<br>content<br>content</div>').dialog({ autoResize: true });
214+
var before = { width: el.width(), height: el.height() };
215+
var handle = $(".ui-resizable-se", dlg());
216+
drag(handle, 50, 50);
217+
var expected = { width: before.width + 50, height: before.height + 50 };
218+
var actual = { width: el.width(), height: el.height() };
219+
compare2(actual, expected, '.dialog({ autoResize: true })');
220+
el.remove();
221+
});
222+
203223
test("buttons", function() {
204224
expect(14);
205225
var buttons = {

ui/ui.dialog.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ $.widget("ui.dialog", {
4040
.wrap('<div/>')
4141
.wrap('<div/>'),
4242

43-
uiDialogContainer = uiDialogContent.parent()
43+
uiDialogContainer = (this.uiDialogContainer = uiDialogContent.parent()
4444
.addClass('ui-dialog-container')
45-
.css({position: 'relative'}),
45+
.css({position: 'relative', width: '100%', height: '100%'})),
4646

4747
title = options.title || uiDialogContent.attr('title') || '',
4848
uiDialogTitlebar = (this.uiDialogTitlebar =
@@ -139,10 +139,12 @@ $.widget("ui.dialog", {
139139
(options.resizeStart && options.resizeStart.apply(self.element[0], arguments));
140140
},
141141
resize: function(e, ui) {
142+
(options.autoResize && self.size.apply(self));
142143
(options.resize && options.resize.apply(self.element[0], arguments));
143144
},
144145
handles: resizeHandles,
145146
stop: function(e, ui) {
147+
(options.autoResize && self.size.apply(self));
146148
(options.resizeStop && options.resizeStop.apply(self.element[0], arguments));
147149
$.ui.dialog.overlay.resize();
148150
}
@@ -231,12 +233,23 @@ $.widget("ui.dialog", {
231233
pTop = Math.max(pTop, minTop);
232234
this.uiDialog.css({top: pTop, left: pLeft});
233235
},
236+
237+
size: function() {
238+
var container = this.uiDialogContainer,
239+
titlebar = this.uiDialogTitlebar,
240+
content = this.element,
241+
tbMargin = parseInt(content.css('margin-top')) + parseInt(content.css('margin-bottom')),
242+
lrMargin = parseInt(content.css('margin-left')) + parseInt(content.css('margin-right'));
243+
content.height(container.height() - titlebar.outerHeight() - tbMargin);
244+
content.width(container.width() - lrMargin);
245+
},
234246

235247
open: function() {
236248
this.overlay = this.options.modal ? new $.ui.dialog.overlay(this) : null;
237249
this.uiDialog.appendTo('body');
238250
this.position(this.options.position);
239251
this.uiDialog.show(this.options.show);
252+
this.options.autoResize && this.size();
240253
this.moveToTop(true);
241254

242255
// CALLBACK: open
@@ -289,6 +302,7 @@ $.widget("ui.dialog", {
289302
$.extend($.ui.dialog, {
290303
defaults: {
291304
autoOpen: true,
305+
autoResize: true,
292306
bgiframe: false,
293307
buttons: {},
294308
closeOnEscape: true,

0 commit comments

Comments
 (0)