Skip to content

Commit 43b1d7c

Browse files
committed
Dialog: Add icons option to support titlebar icons
Fixes #15121
1 parent d64a626 commit 43b1d7c

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

tests/unit/dialog/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ common.testWidget( "dialog", {
1818
draggable: true,
1919
height: "auto",
2020
hide: null,
21+
icons: {
22+
title: null
23+
},
2124
maxHeight: null,
2225
maxWidth: null,
2326
minHeight: 150,

tests/unit/dialog/options.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,30 @@ QUnit.test( "height", function( assert ) {
269269
element.remove();
270270
} );
271271

272+
QUnit.test( "icons", function( assert ) {
273+
assert.expect( 5 );
274+
275+
var element = $( "<div></div>" ).dialog( {
276+
icons: {
277+
title: "ui-icon-disk"
278+
}
279+
} );
280+
var titleBar = element.dialog( "widget" ).find( ".ui-dialog-titlebar" );
281+
282+
var icon = titleBar.find( ".ui-dialog-title-icon" );
283+
assert.equal( 1, icon.length, "title icon exists after init" );
284+
assert.hasClasses( icon, "ui-icon-disk", "correct icon after init" );
285+
286+
element.dialog( "option", "icons.title", null );
287+
icon = titleBar.find( ".ui-dialog-title-icon" );
288+
assert.equal( 0, icon.length, "title icon removed when null" );
289+
290+
element.dialog( "option", "icons.title", "ui-icon-gear" );
291+
icon = titleBar.find( ".ui-dialog-title-icon" );
292+
assert.equal( 1, icon.length, "title icon exists after update" );
293+
assert.hasClasses( icon, "ui-icon-gear", "correct icon after update" );
294+
} );
295+
272296
QUnit.test( "maxHeight", function( assert ) {
273297
assert.expect( 3 );
274298

themes/base/dialog.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
overflow: hidden;
2828
text-overflow: ellipsis;
2929
}
30+
.ui-dialog .ui-dialog-title-icon {
31+
position: absolute;
32+
left: 0.3em;
33+
top: 50%;
34+
margin-top: -10px;
35+
}
36+
.ui-dialog-title-icon + .ui-dialog-title {
37+
padding-left: 10px;
38+
}
3039
.ui-dialog .ui-dialog-titlebar-close {
3140
position: absolute;
3241
right: .3em;

ui/widgets/dialog.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ return $.widget( "ui.dialog", {
5858
draggable: true,
5959
hide: null,
6060
height: "auto",
61+
icons: {
62+
title: null
63+
},
6164
maxHeight: null,
6265
maxWidth: null,
6366
minHeight: 150,
@@ -446,6 +449,8 @@ return $.widget( "ui.dialog", {
446449
this._addClass( uiDialogTitle, "ui-dialog-title" );
447450
this._title( uiDialogTitle );
448451

452+
this._titleIcon( this.options.icons.title );
453+
449454
this.uiDialogTitlebar.prependTo( this.uiDialog );
450455

451456
this.uiDialog.attr( {
@@ -461,6 +466,20 @@ return $.widget( "ui.dialog", {
461466
}
462467
},
463468

469+
_titleIcon: function( icon ) {
470+
if ( this.uiDialogTitleIcon ) {
471+
this.uiDialogTitleIcon.remove();
472+
delete this.uiDialogTitleIcon;
473+
}
474+
475+
if ( icon ) {
476+
this.uiDialogTitleIcon = $( "<span>" );
477+
this._addClass( this.uiDialogTitleIcon, "ui-dialog-title-icon",
478+
"ui-icon " + this.options.icons.title );
479+
this.uiDialogTitleIcon.prependTo( this.uiDialogTitlebar );
480+
}
481+
},
482+
464483
_createButtonPane: function() {
465484
this.uiDialogButtonPane = $( "<div>" );
466485
this._addClass( this.uiDialogButtonPane, "ui-dialog-buttonpane",
@@ -742,6 +761,10 @@ return $.widget( "ui.dialog", {
742761
}
743762
}
744763

764+
if ( key === "icons" ) {
765+
this._titleIcon( value.title );
766+
}
767+
745768
if ( key === "position" ) {
746769
this._position();
747770
}

0 commit comments

Comments
 (0)