From: Scott González Date: Tue, 31 Aug 2010 14:17:53 +0000 (-0400) Subject: Dialog: Added additional syntax for creating buttons. Fixes #4344 - Dialog: Enhanced... X-Git-Tag: 1.8.5~38 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=95a34593f98217e3a99f223e2ef3ca0a0fa8343b;p=jquery-ui.git Dialog: Added additional syntax for creating buttons. Fixes #4344 - Dialog: Enhanced Button Option. --- diff --git a/tests/unit/dialog/dialog_options.js b/tests/unit/dialog/dialog_options.js index d20f1d764..2d0cbe907 100644 --- a/tests/unit/dialog/dialog_options.js +++ b/tests/unit/dialog/dialog_options.js @@ -71,6 +71,31 @@ test("buttons", function() { el.remove(); }); +test("buttons - advanced", function() { + expect(5); + + el = $("
").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() { el = $('
').dialog({ closeOnEscape: false }); ok(true, 'closeOnEscape: false'); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index ff2375164..17300b178 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -357,10 +357,15 @@ $.widget("ui.dialog", { }); } if (hasButtons) { - $.each(buttons, function(name, fn) { - var button = $('') - .text(name) - .click(function() { fn.apply(self.element[0], arguments); }) + $.each(buttons, function(name, props) { + props = $.isFunction( props ) ? + { click: props, text: name } : + props; + var button = $('', props) + .unbind('click') + .click(function() { + props.click.apply(self.element[0], arguments); + }) .appendTo(uiButtonSet); if ($.fn.button) { button.button();