diff options
author | Adam Baratz <adam.baratz@gmail.com> | 2011-05-02 18:03:14 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-05-02 18:03:14 -0400 |
commit | 51df02ee4ea02e91919842a169463612176682d5 (patch) | |
tree | 10c7f3f59015d00c62e43ac304d3605edaa83987 /ui/jquery.ui.dialog.js | |
parent | 3d5d58d85437ae11688c0407200fd36bed7c9426 (diff) | |
download | jquery-ui-51df02ee4ea02e91919842a169463612176682d5.tar.gz jquery-ui-51df02ee4ea02e91919842a169463612176682d5.zip |
Dialog: remove unneeded DOM manipulations. Fixed #7258 - optimize initialization.
Diffstat (limited to 'ui/jquery.ui.dialog.js')
-rw-r--r-- | ui/jquery.ui.dialog.js | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index c14237b6a..8423d1164 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -86,16 +86,14 @@ $.widget("ui.dialog", { titleId = $.ui.dialog.getTitleId( self.element ), uiDialog = ( self.uiDialog = $( "<div>" ) ) - .appendTo( document.body ) - .hide() .addClass( uiDialogClasses + options.dialogClass ) .css({ + display: "none", + outline: 0, // TODO: move to stylesheet zIndex: options.zIndex }) // setting tabIndex makes the div focusable .attr( "tabIndex", -1) - // TODO: move to stylesheet - .css( "outline", 0 ) .keydown(function( event ) { if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && event.keyCode === $.ui.keyCode.ESCAPE ) { @@ -156,6 +154,8 @@ $.widget("ui.dialog", { self._createButtons( options.buttons ); self._isOpen = false; + uiDialog.appendTo( document.body ); + if ( $.fn.bgiframe ) { uiDialog.bgiframe(); } @@ -310,9 +310,14 @@ $.widget("ui.dialog", { // set focus to the first tabbable element in the content area or the first button // if there are no tabbable elements, set focus on the dialog itself - $( self.element.find( ":tabbable" ).get().concat( - uiDialog.find( ".ui-dialog-buttonpane :tabbable" ).get().concat( - uiDialog.get() ) ) ).eq( 0 ).focus(); + var hasFocus = self.element.find( ":tabbable" ); + if ( !hasFocus.length ) { + hasFocus = uiDialog.find( ".ui-dialog-buttonpane :tabbable" ); + if ( !hasFocus.length ) { + hasFocus = uiDialog; + } + } + hasFocus.eq( 0 ).focus(); self._isOpen = true; self._trigger( "open" ); @@ -322,12 +327,7 @@ $.widget("ui.dialog", { _createButtons: function( buttons ) { var self = this, - hasButtons = false, - uiDialogButtonPane = $( "<div>" ) - .addClass( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ), - uiButtonSet = $( "<div>" ) - .addClass( "ui-dialog-buttonset" ) - .appendTo( uiDialogButtonPane ); + hasButtons = false; // if we already have a button pane, remove it self.uiDialog.find( ".ui-dialog-buttonpane" ).remove(); @@ -338,6 +338,12 @@ $.widget("ui.dialog", { }); } if ( hasButtons ) { + var 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 } : |