mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Dialog: Added additional syntax for creating buttons. Fixes #4344 - Dialog: Enhanced Button Option.
This commit is contained in:
parent
dea2f8a7fc
commit
95a34593f9
@ -71,6 +71,31 @@ test("buttons", function() {
|
|||||||
el.remove();
|
el.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("buttons - advanced", function() {
|
||||||
|
expect(5);
|
||||||
|
|
||||||
|
el = $("<div></div>").dialog({
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
text: "a button",
|
||||||
|
"class": "additional-class",
|
||||||
|
id: "my-button-id",
|
||||||
|
click: function() {
|
||||||
|
equals(this, el[0], "correct context");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
var buttons = dlg().find("button");
|
||||||
|
equals(buttons.length, 1, "correct number of buttons");
|
||||||
|
equals(buttons.attr("id"), "my-button-id", "correct id");
|
||||||
|
equals(buttons.text(), "a button", "correct label");
|
||||||
|
ok(buttons.hasClass("additional-class"), "additional classes added");
|
||||||
|
buttons.click();
|
||||||
|
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
|
||||||
test("closeOnEscape", function() {
|
test("closeOnEscape", function() {
|
||||||
el = $('<div></div>').dialog({ closeOnEscape: false });
|
el = $('<div></div>').dialog({ closeOnEscape: false });
|
||||||
ok(true, 'closeOnEscape: false');
|
ok(true, 'closeOnEscape: false');
|
||||||
|
13
ui/jquery.ui.dialog.js
vendored
13
ui/jquery.ui.dialog.js
vendored
@ -357,10 +357,15 @@ $.widget("ui.dialog", {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (hasButtons) {
|
if (hasButtons) {
|
||||||
$.each(buttons, function(name, fn) {
|
$.each(buttons, function(name, props) {
|
||||||
var button = $('<button type="button"></button>')
|
props = $.isFunction( props ) ?
|
||||||
.text(name)
|
{ click: props, text: name } :
|
||||||
.click(function() { fn.apply(self.element[0], arguments); })
|
props;
|
||||||
|
var button = $('<button></button>', props)
|
||||||
|
.unbind('click')
|
||||||
|
.click(function() {
|
||||||
|
props.click.apply(self.element[0], arguments);
|
||||||
|
})
|
||||||
.appendTo(uiButtonSet);
|
.appendTo(uiButtonSet);
|
||||||
if ($.fn.button) {
|
if ($.fn.button) {
|
||||||
button.button();
|
button.button();
|
||||||
|
Loading…
Reference in New Issue
Block a user