]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Added additional syntax for creating buttons. Fixes #4344 - Dialog: Enhanced...
authorScott González <scott.gonzalez@gmail.com>
Tue, 31 Aug 2010 14:17:53 +0000 (10:17 -0400)
committerScott González <scott.gonzalez@gmail.com>
Tue, 31 Aug 2010 14:17:53 +0000 (10:17 -0400)
tests/unit/dialog/dialog_options.js
ui/jquery.ui.dialog.js

index d20f1d764ffa918ca01bd97aac71579185db3128..2d0cbe9071f38494179c951b53c182727cd06b8d 100644 (file)
@@ -71,6 +71,31 @@ test("buttons", function() {
        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() {
        el = $('<div></div>').dialog({ closeOnEscape: false });
        ok(true, 'closeOnEscape: false');
index ff23751643cf52e842addc77cafea7ed6f357c3e..17300b178b870d6c995d241aa727756a8ec32372 100644 (file)
@@ -357,10 +357,15 @@ $.widget("ui.dialog", {
                        });
                }
                if (hasButtons) {
-                       $.each(buttons, function(name, fn) {
-                               var button = $('<button type="button"></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 = $('<button></button>', props)
+                                       .unbind('click')
+                                       .click(function() {
+                                               props.click.apply(self.element[0], arguments);
+                                       })
                                        .appendTo(uiButtonSet);
                                if ($.fn.button) {
                                        button.button();