File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,31 @@ test("buttons", function() {
7171 el . remove ( ) ;
7272} ) ;
7373
74+ test ( "buttons - advanced" , function ( ) {
75+ expect ( 5 ) ;
76+
77+ el = $ ( "<div></div>" ) . dialog ( {
78+ buttons : [
79+ {
80+ text : "a button" ,
81+ "class" : "additional-class" ,
82+ id : "my-button-id" ,
83+ click : function ( ) {
84+ equals ( this , el [ 0 ] , "correct context" ) ;
85+ }
86+ }
87+ ]
88+ } ) ;
89+ var buttons = dlg ( ) . find ( "button" ) ;
90+ equals ( buttons . length , 1 , "correct number of buttons" ) ;
91+ equals ( buttons . attr ( "id" ) , "my-button-id" , "correct id" ) ;
92+ equals ( buttons . text ( ) , "a button" , "correct label" ) ;
93+ ok ( buttons . hasClass ( "additional-class" ) , "additional classes added" ) ;
94+ buttons . click ( ) ;
95+
96+ el . remove ( ) ;
97+ } ) ;
98+
7499test ( "closeOnEscape" , function ( ) {
75100 el = $ ( '<div></div>' ) . dialog ( { closeOnEscape : false } ) ;
76101 ok ( true , 'closeOnEscape: false' ) ;
Original file line number Diff line number Diff line change @@ -357,10 +357,15 @@ $.widget("ui.dialog", {
357357 } ) ;
358358 }
359359 if ( hasButtons ) {
360- $ . each ( buttons , function ( name , fn ) {
361- var button = $ ( '<button type="button"></button>' )
362- . text ( name )
363- . click ( function ( ) { fn . apply ( self . element [ 0 ] , arguments ) ; } )
360+ $ . each ( buttons , function ( name , props ) {
361+ props = $ . isFunction ( props ) ?
362+ { click : props , text : name } :
363+ props ;
364+ var button = $ ( '<button></button>' , props )
365+ . unbind ( 'click' )
366+ . click ( function ( ) {
367+ props . click . apply ( self . element [ 0 ] , arguments ) ;
368+ } )
364369 . appendTo ( uiButtonSet ) ;
365370 if ( $ . fn . button ) {
366371 button . button ( ) ;
You can’t perform that action at this time.
0 commit comments