Skip to content

[1.13] Dialog: Add icons option to support titlebar icons #1791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 0 additions & 54 deletions tests/unit/dialog/common-deprecated.js

This file was deleted.

3 changes: 3 additions & 0 deletions tests/unit/dialog/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ common.testWidget( "dialog", {
draggable: true,
height: "auto",
hide: null,
icons: {
title: null
},
maxHeight: null,
maxWidth: null,
minHeight: 150,
Expand Down
34 changes: 0 additions & 34 deletions tests/unit/dialog/deprecated.html

This file was deleted.

61 changes: 0 additions & 61 deletions tests/unit/dialog/deprecated.js

This file was deleted.

24 changes: 24 additions & 0 deletions tests/unit/dialog/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,30 @@ QUnit.test( "height", function( assert ) {
element.remove();
} );

QUnit.test( "icons", function( assert ) {
assert.expect( 5 );

var element = $( "<div></div>" ).dialog( {
icons: {
title: "ui-icon-disk"
}
} );
var titleBar = element.dialog( "widget" ).find( ".ui-dialog-titlebar" );

var icon = titleBar.find( ".ui-dialog-title-icon" );
assert.equal( 1, icon.length, "title icon exists after init" );
assert.hasClasses( icon, "ui-icon-disk", "correct icon after init" );

element.dialog( "option", "icons.title", null );
icon = titleBar.find( ".ui-dialog-title-icon" );
assert.equal( 0, icon.length, "title icon removed when null" );

element.dialog( "option", "icons.title", "ui-icon-gear" );
icon = titleBar.find( ".ui-dialog-title-icon" );
assert.equal( 1, icon.length, "title icon exists after update" );
assert.hasClasses( icon, "ui-icon-gear", "correct icon after update" );
} );

QUnit.test( "maxHeight", function( assert ) {
assert.expect( 3 );

Expand Down
13 changes: 11 additions & 2 deletions themes/base/dialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,26 @@
outline: 0;
}
.ui-dialog .ui-dialog-titlebar {
padding: .4em 1em;
padding: .4em 2em .4em 1em;
position: relative;
}
.ui-dialog .ui-dialog-title {
float: left;
margin: .1em 0;
white-space: nowrap;
width: 90%;
width: 100%;
overflow: hidden;
text-overflow: ellipsis;
}
.ui-dialog .ui-dialog-title-icon {
position: absolute;
left: 0.3em;
top: 50%;
margin-top: -10px;
}
.ui-dialog-title-icon + .ui-dialog-title {
padding-left: 10px;
}
.ui-dialog .ui-dialog-titlebar-close {
position: absolute;
right: .3em;
Expand Down
51 changes: 24 additions & 27 deletions ui/widgets/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}
}( function( $ ) {

$.widget( "ui.dialog", {
return $.widget( "ui.dialog", {
version: "@VERSION",
options: {
appendTo: "body",
Expand All @@ -58,6 +58,9 @@ $.widget( "ui.dialog", {
draggable: true,
hide: null,
height: "auto",
icons: {
title: null
},
maxHeight: null,
maxWidth: null,
minHeight: 150,
Expand Down Expand Up @@ -446,6 +449,8 @@ $.widget( "ui.dialog", {
this._addClass( uiDialogTitle, "ui-dialog-title" );
this._title( uiDialogTitle );

this._titleIcon( this.options.icons.title );

this.uiDialogTitlebar.prependTo( this.uiDialog );

this.uiDialog.attr( {
Expand All @@ -461,6 +466,20 @@ $.widget( "ui.dialog", {
}
},

_titleIcon: function( icon ) {
if ( this.uiDialogTitleIcon ) {
this.uiDialogTitleIcon.remove();
delete this.uiDialogTitleIcon;
}

if ( icon ) {
this.uiDialogTitleIcon = $( "<span>" );
this._addClass( this.uiDialogTitleIcon, "ui-dialog-title-icon",
"ui-icon " + this.options.icons.title );
this.uiDialogTitleIcon.prependTo( this.uiDialogTitlebar );
}
},

_createButtonPane: function() {
this.uiDialogButtonPane = $( "<div>" );
this._addClass( this.uiDialogButtonPane, "ui-dialog-buttonpane",
Expand Down Expand Up @@ -742,6 +761,10 @@ $.widget( "ui.dialog", {
}
}

if ( key === "icons" ) {
this._titleIcon( value.title );
}

if ( key === "position" ) {
this._position();
}
Expand Down Expand Up @@ -911,30 +934,4 @@ $.widget( "ui.dialog", {
}
} );

// DEPRECATED
// TODO: switch return back to widget declaration at top of file when this is removed
if ( $.uiBackCompat !== false ) {

// Backcompat for dialogClass option
$.widget( "ui.dialog", $.ui.dialog, {
options: {
dialogClass: ""
},
_createWrapper: function() {
this._super();
this.uiDialog.addClass( this.options.dialogClass );
},
_setOption: function( key, value ) {
if ( key === "dialogClass" ) {
this.uiDialog
.removeClass( this.options.dialogClass )
.addClass( value );
}
this._superApply( arguments );
}
} );
}

return $.ui.dialog;

} ) );