Skip to content

Commit

Permalink
Dialog: Only create the button pane once and store a reference to it.…
Browse files Browse the repository at this point in the history
… Fixes #8343 - _createButtons removes all elements with .ui-dialog-buttonpane class.
  • Loading branch information
scottgonzalez committed May 22, 2012
1 parent c42bdce commit 286941e
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions ui/jquery.ui.dialog.js
Expand Up @@ -143,7 +143,14 @@ $.widget("ui.dialog", {
.addClass( "ui-dialog-title" )
.attr( "id", titleId )
.html( title )
.prependTo( uiDialogTitlebar );
.prependTo( uiDialogTitlebar ),

uiDialogButtonPane = ( this.uiDialogButtonPane = $( "<div>" ) )
.addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ),

uiButtonSet = ( this.uiButtonSet = $( "<div>" ) )
.addClass( "ui-dialog-buttonset" )
.appendTo( uiDialogButtonPane );

uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
this._hoverable( uiDialogTitlebarClose );
Expand Down Expand Up @@ -326,7 +333,7 @@ $.widget("ui.dialog", {
// if there are no tabbable elements, set focus on the dialog itself
hasFocus = this.element.find( ":tabbable" );
if ( !hasFocus.length ) {
hasFocus = uiDialog.find( ".ui-dialog-buttonpane :tabbable" );
hasFocus = this.uiDialogButtonPane.find( ":tabbable" );
if ( !hasFocus.length ) {
hasFocus = uiDialog;
}
Expand All @@ -345,20 +352,15 @@ $.widget("ui.dialog", {
hasButtons = false;

// if we already have a button pane, remove it
this.uiDialog.find( ".ui-dialog-buttonpane" ).remove();
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();

if ( typeof buttons === "object" && buttons !== null ) {
$.each( buttons, function() {
return !(hasButtons = true);
});
}
if ( hasButtons ) {
uiDialogButtonPane = $( "<div>" )
.addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" );
uiButtonSet = $( "<div>" )
.addClass( "ui-dialog-buttonset" )
.appendTo( uiDialogButtonPane );

$.each( buttons, function( name, props ) {
props = $.isFunction( props ) ?
{ click: props, text: name } :
Expand All @@ -369,13 +371,13 @@ $.widget("ui.dialog", {
.click(function() {
props.click.apply( that.element[0], arguments );
})
.appendTo( uiButtonSet );
.appendTo( that.uiButtonSet );
if ( $.fn.button ) {
button.button();
}
});
this.uiDialog.addClass( "ui-dialog-buttons" );
uiDialogButtonPane.appendTo( this.uiDialog );
this.uiDialogButtonPane.appendTo( this.uiDialog );
} else {
this.uiDialog.removeClass( "ui-dialog-buttons" );
}
Expand Down

0 comments on commit 286941e

Please sign in to comment.