diff --git a/tests/unit/dialog/common-deprecated.js b/tests/unit/dialog/common-deprecated.js deleted file mode 100644 index 1efdcb03018..00000000000 --- a/tests/unit/dialog/common-deprecated.js +++ /dev/null @@ -1,54 +0,0 @@ -define( [ - "lib/common", - "ui/widgets/dialog" -], function( common ) { - -common.testWidget( "dialog", { - defaults: { - appendTo: "body", - autoOpen: true, - buttons: [], - classes: { - "ui-dialog": "ui-corner-all", - "ui-dialog-titlebar": "ui-corner-all" - }, - closeOnEscape: true, - closeText: "Close", - dialogClass: "", - disabled: false, - draggable: true, - height: "auto", - hide: null, - maxHeight: null, - maxWidth: null, - minHeight: 150, - minWidth: 150, - modal: false, - position: { - my: "center", - at: "center", - of: window, - collision: "fit", - using: $.ui.dialog.prototype.options.position.using - }, - resizable: true, - show: null, - title: null, - width: 300, - - // Callbacks - beforeClose: null, - close: null, - create: null, - drag: null, - dragStart: null, - dragStop: null, - focus: null, - open: null, - resize: null, - resizeStart: null, - resizeStop: null - } -} ); - -} ); diff --git a/tests/unit/dialog/common.js b/tests/unit/dialog/common.js index c8d885ad03f..b8a06b1c841 100644 --- a/tests/unit/dialog/common.js +++ b/tests/unit/dialog/common.js @@ -18,6 +18,9 @@ common.testWidget( "dialog", { draggable: true, height: "auto", hide: null, + icons: { + title: null + }, maxHeight: null, maxWidth: null, minHeight: 150, diff --git a/tests/unit/dialog/deprecated.html b/tests/unit/dialog/deprecated.html deleted file mode 100644 index 50bab180ddf..00000000000 --- a/tests/unit/dialog/deprecated.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - jQuery UI Dialog Test Suite - - - - - - - -
-
-
-
-
- -
...
-
- Please share some personal information - - -
-
-

Some more (optional) information

- -
-
-
-
-
- - diff --git a/tests/unit/dialog/deprecated.js b/tests/unit/dialog/deprecated.js deleted file mode 100644 index 973a90893a1..00000000000 --- a/tests/unit/dialog/deprecated.js +++ /dev/null @@ -1,61 +0,0 @@ -define( [ - "qunit", - "jquery", - "ui/widgets/dialog" -], function( QUnit, $ ) { - -QUnit.module( "dialog (deprecated): options" ); - -QUnit.test( "dialogClass", function( assert ) { - assert.expect( 5 ); - - var element = $( "
" ).dialog(), - widget = element.dialog( "widget" ); - assert.lacksClasses( widget, "foo", "dialogClass not specified. class not added" ); - element.remove(); - - element = $( "
" ).dialog( { dialogClass: "foo" } ); - widget = element.dialog( "widget" ); - assert.hasClasses( widget, "foo", "dialogClass in init, foo class added" ); - element.dialog( "option", "dialogClass", "foobar" ); - assert.lacksClasses( widget, "foo", "dialogClass changed, previous one was removed" ); - assert.hasClasses( widget, "foobar", "dialogClass changed, new one was added" ); - element.remove(); - - element = $( "
" ).dialog( { dialogClass: "foo bar" } ); - widget = element.dialog( "widget" ); - assert.hasClasses( widget, "foo bar", "dialogClass in init, two classes." ); - element.remove(); -} ); - -QUnit.test( "buttons - deprecated options", function( assert ) { - assert.expect( 7 ); - - var buttons, - element = $( "
" ).dialog( { - buttons: [ - { - html: "a button", - "class": "additional-class", - id: "my-button-id", - click: function() { - assert.equal( this, element[ 0 ], "correct context" ); - }, - icons: { primary: "ui-icon-cancel" }, - text: false - } - ] - } ); - - buttons = element.dialog( "widget" ).find( ".ui-dialog-buttonpane button" ); - assert.equal( buttons.length, 1, "correct number of buttons" ); - assert.equal( buttons.attr( "id" ), "my-button-id", "correct id" ); - assert.equal( $.trim( buttons.text() ), "a button", "correct label" ); - assert.hasClasses( buttons, "additional-class" ); - assert.deepEqual( buttons.button( "option", "icon" ), "ui-icon-cancel" ); - assert.equal( buttons.button( "option", "showLabel" ), false ); - buttons.trigger( "click" ); - - element.remove(); -} ); -} ); diff --git a/tests/unit/dialog/options.js b/tests/unit/dialog/options.js index 1be2888e340..2928ab9e4a4 100644 --- a/tests/unit/dialog/options.js +++ b/tests/unit/dialog/options.js @@ -269,6 +269,30 @@ QUnit.test( "height", function( assert ) { element.remove(); } ); +QUnit.test( "icons", function( assert ) { + assert.expect( 5 ); + + var element = $( "
" ).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 ); diff --git a/themes/base/dialog.css b/themes/base/dialog.css index 7146fe95364..48edac9548c 100644 --- a/themes/base/dialog.css +++ b/themes/base/dialog.css @@ -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; diff --git a/ui/widgets/dialog.js b/ui/widgets/dialog.js index c8829331f2a..b1bbd7d2def 100644 --- a/ui/widgets/dialog.js +++ b/ui/widgets/dialog.js @@ -43,7 +43,7 @@ } }( function( $ ) { -$.widget( "ui.dialog", { +return $.widget( "ui.dialog", { version: "@VERSION", options: { appendTo: "body", @@ -58,6 +58,9 @@ $.widget( "ui.dialog", { draggable: true, hide: null, height: "auto", + icons: { + title: null + }, maxHeight: null, maxWidth: null, minHeight: 150, @@ -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( { @@ -461,6 +466,20 @@ $.widget( "ui.dialog", { } }, + _titleIcon: function( icon ) { + if ( this.uiDialogTitleIcon ) { + this.uiDialogTitleIcon.remove(); + delete this.uiDialogTitleIcon; + } + + if ( icon ) { + this.uiDialogTitleIcon = $( "" ); + this._addClass( this.uiDialogTitleIcon, "ui-dialog-title-icon", + "ui-icon " + this.options.icons.title ); + this.uiDialogTitleIcon.prependTo( this.uiDialogTitlebar ); + } + }, + _createButtonPane: function() { this.uiDialogButtonPane = $( "
" ); this._addClass( this.uiDialogButtonPane, "ui-dialog-buttonpane", @@ -742,6 +761,10 @@ $.widget( "ui.dialog", { } } + if ( key === "icons" ) { + this._titleIcon( value.title ); + } + if ( key === "position" ) { this._position(); } @@ -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; - } ) );