Dialog: Pass through icons and showText (as 'text') options to button. Fixes #6830 - Allow Icons to be specified for Dialog buttons.

This commit is contained in:
Jörn Zaefferer 2012-11-16 19:26:22 +01:00
parent d8b98ec3bb
commit 999617343f
3 changed files with 24 additions and 5 deletions

View File

@ -81,7 +81,7 @@ test("buttons", function() {
}); });
test("buttons - advanced", function() { test("buttons - advanced", function() {
expect(5); expect( 7 );
var buttons, var buttons,
el = $("<div></div>").dialog({ el = $("<div></div>").dialog({
@ -92,7 +92,11 @@ test("buttons - advanced", function() {
id: "my-button-id", id: "my-button-id",
click: function() { click: function() {
equal(this, el[0], "correct context"); equal(this, el[0], "correct context");
} },
icons: {
primary: "ui-icon-cancel"
},
showText: false
} }
] ]
}); });
@ -102,6 +106,8 @@ test("buttons - advanced", function() {
equal(buttons.attr("id"), "my-button-id", "correct id"); equal(buttons.attr("id"), "my-button-id", "correct id");
equal(buttons.text(), "a button", "correct label"); equal(buttons.text(), "a button", "correct label");
ok(buttons.hasClass("additional-class"), "additional classes added"); ok(buttons.hasClass("additional-class"), "additional classes added");
deepEqual( buttons.button("option", "icons"), { primary: "ui-icon-cancel", secondary: null } );
equal( buttons.button( "option", "text" ), false );
buttons.click(); buttons.click();
el.remove(); el.remove();

View File

@ -28,10 +28,21 @@
width: 500, width: 500,
buttons: [ buttons: [
{ {
click: $.noop,
icons: {
primary: "ui-icon-check"
},
text: "Ok" text: "Ok"
}, },
{ {
text: "Cancel" click: function() {
$( this ).dialog( "close" );
},
icons: {
primary: "ui-icon-cancel"
},
text: "Cancel",
showText: false
} }
] ]
}), }),

View File

@ -383,8 +383,10 @@ $.widget("ui.dialog", {
click.apply( that.element[0], arguments ); click.apply( that.element[0], arguments );
}; };
$( "<button></button>", props ) $( "<button></button>", props )
// TODO allow passing through button options .button({
.button() icons: props.icons,
text: props.showText
})
.appendTo( that.uiButtonSet ); .appendTo( that.uiButtonSet );
}); });
this.uiDialog.addClass( "ui-dialog-buttons" ); this.uiDialog.addClass( "ui-dialog-buttons" );