Skip to content

Commit b306e59

Browse files
committed
make minimizable feature can be disabled and enabled and add test case
make minimizable feature can be disabled and enabled and add test case
1 parent de7e529 commit b306e59

File tree

2 files changed

+74
-45
lines changed

2 files changed

+74
-45
lines changed

demos/dialog/minimizable.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery UI Dialog - Minimizable dialog</title>
7+
<link rel="stylesheet" href="../../themes/base/all.css">
8+
<link rel="stylesheet" href="../demos.css">
9+
<script src="../../external/requirejs/require.js"></script>
10+
<script src="../bootstrap.js">
11+
$( "#dialog" ).dialog({
12+
minimizable: true
13+
});
14+
</script>
15+
</head>
16+
<body>
17+
18+
<div id="dialog" title="Minimizable dialog">
19+
<p>This is the dialog which can be minimized and restored.</p>
20+
</div>
21+
22+
<div class="demo-description">
23+
<p>This is the dialog which can be minimized and restored.</p>
24+
</div>
25+
</body>
26+
</html>

ui/widgets/dialog.js

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ $.widget( "ui.dialog", {
6161
minimizeText: "Minimize",
6262
restoreText: "Restore",
6363
draggable: true,
64+
minimizable: false,
6465
hide: null,
6566
height: "auto",
6667
maxHeight: null,
@@ -448,53 +449,55 @@ $.widget( "ui.dialog", {
448449
}
449450
} );
450451

451-
this.uiDialogTitlebarMinimize = $( "<button type='button'></button>" )
452-
.button( {
453-
label: $( "<a>" ).text( this.options.minimizeText ).html(),
454-
icon: "ui-icon ui-icon-minimize",
455-
showLabel: false
456-
} )
457-
.appendTo( this.uiDialogTitlebar );
458-
this._addClass( this.uiDialogTitlebarMinimize, "ui-dialog-titlebar-minimize" );
459-
this._on( this.uiDialogTitlebarMinimize, {
460-
click: function( event ) {
461-
event.preventDefault();
462-
this.options.restoreWidth = this.options.width;
463-
this.options.restoreHeight = this.options.height;
464-
this.uiDialog.width( this.uiDialogTitlebar.outerWidth() > 300 ? 300 : this.uiDialogTitlebar.outerWidth() );
465-
this.uiDialog.height( this.uiDialogTitlebar.outerHeight() );
466-
this.element.hide();
467-
this.uiDialogButtonPane.hide();
468-
this.uiDialogTitlebarRestore.button( "enable" );
469-
this.uiDialogTitlebarMinimize.button( "disable" );
470-
}
471-
} );
472-
this.uiDialogTitlebarRestore = $( "<button type='button'></button>" )
473-
.button( {
474-
label: $( "<a>" ).text( this.options.restoreText ).html(),
475-
icon: "ui-icon ui-icon-restore",
476-
showLabel: false
477-
} )
478-
.appendTo( this.uiDialogTitlebar );
479-
this._addClass( this.uiDialogTitlebarRestore, "ui-dialog-titlebar-restore" );
480-
this._on( this.uiDialogTitlebarRestore, {
481-
click: function( event ) {
482-
event.preventDefault();
483-
if ( this.options.restoreWidth !== undefined &&
484-
this.options.restoreWidth !== null && this.options.restoreWidth !== "" ) {
485-
this.uiDialog.width( this.options.restoreWidth );
452+
if ( this.options.minimizable ) {
453+
this.uiDialogTitlebarMinimize = $( "<button type='button'></button>" )
454+
.button( {
455+
label: $( "<a>" ).text( this.options.minimizeText ).html(),
456+
icon: "ui-icon ui-icon-minimize",
457+
showLabel: false
458+
} )
459+
.appendTo( this.uiDialogTitlebar );
460+
this._addClass( this.uiDialogTitlebarMinimize, "ui-dialog-titlebar-minimize" );
461+
this._on( this.uiDialogTitlebarMinimize, {
462+
click: function( event ) {
463+
event.preventDefault();
464+
this.options.restoreWidth = this.options.width;
465+
this.options.restoreHeight = this.options.height;
466+
this.uiDialog.width( this.uiDialogTitlebar.outerWidth() > 300 ? 300 : this.uiDialogTitlebar.outerWidth() );
467+
this.uiDialog.height( this.uiDialogTitlebar.outerHeight() );
468+
this.element.hide();
469+
this.uiDialogButtonPane.hide();
470+
this.uiDialogTitlebarRestore.button( "enable" );
471+
this.uiDialogTitlebarMinimize.button( "disable" );
486472
}
487-
if ( this.options.restoreHeight !== undefined &&
488-
this.options.restoreHeight !== null && this.options.restoreHeight !== "" ) {
489-
this.uiDialog.height( this.options.restoreHeight );
473+
} );
474+
this.uiDialogTitlebarRestore = $( "<button type='button'></button>" )
475+
.button( {
476+
label: $( "<a>" ).text( this.options.restoreText ).html(),
477+
icon: "ui-icon ui-icon-restore",
478+
showLabel: false
479+
} )
480+
.appendTo( this.uiDialogTitlebar );
481+
this._addClass( this.uiDialogTitlebarRestore, "ui-dialog-titlebar-restore" );
482+
this._on( this.uiDialogTitlebarRestore, {
483+
click: function( event ) {
484+
event.preventDefault();
485+
if ( this.options.restoreWidth !== undefined &&
486+
this.options.restoreWidth !== null && this.options.restoreWidth !== "" ) {
487+
this.uiDialog.width( this.options.restoreWidth );
488+
}
489+
if ( this.options.restoreHeight !== undefined &&
490+
this.options.restoreHeight !== null && this.options.restoreHeight !== "" ) {
491+
this.uiDialog.height( this.options.restoreHeight );
492+
}
493+
this.element.show();
494+
this.uiDialogButtonPane.show();
495+
this.uiDialogTitlebarMinimize.button( "enable" );
496+
this.uiDialogTitlebarRestore.button( "disable" );
490497
}
491-
this.element.show();
492-
this.uiDialogButtonPane.show();
493-
this.uiDialogTitlebarMinimize.button( "enable" );
494-
this.uiDialogTitlebarRestore.button( "disable" );
495-
}
496-
} );
497-
this.uiDialogTitlebarRestore.button( "disable" );
498+
} );
499+
this.uiDialogTitlebarRestore.button( "disable" );
500+
}
498501

499502
uiDialogTitle = $( "<span>" ).uniqueId().prependTo( this.uiDialogTitlebar );
500503
this._addClass( uiDialogTitle, "ui-dialog-title" );

0 commit comments

Comments
 (0)