Dialog
jQuery UI Dialog
Overview
A dialog is a floating window that contains a title bar and a content area. The dialog window can be moved, resized and closed with the 'x' icon by default.
If the content length exceeds the maximum height, a scrollbar will automatically appear.
A bottom button bar and semi-transparent modal overlay layer are common options that can be added.
A call to $(foo).dialog()
will initialize a dialog instance and will auto-open the dialog by default. If you want to reuse a dialog, the easiest way is to disable the "auto-open" option with: $(foo).dialog({ autoOpen: false })
and open it with $(foo).dialog('open')
. To close it, use $(foo).dialog('close')
. A more in-depth explanation with a full demo is available on the Nemikor blog.
Dependencies
- UI Core
- UI Position
- UI Widget
- UI Mouse (Optional; only needed if using UI Draggable or UI Resizable)
- UI Draggable (Optional)
- UI Resizable (Optional)
Example
$("#dialog").dialog();
<!DOCTYPE html> <html> <head> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> <script> $(document).ready(function() { $("#dialog").dialog(); }); </script> </head> <body style="font-size:62.5%;"> <div id="dialog" title="Dialog Title">I'm in a dialog</div> </body> </html>
Options
Events
Methods
-
destroy
- Signature:
- .dialog( "destroy" )
Remove the dialog functionality completely. This will return the element back to its pre-init state.
-
disable
- Signature:
- .dialog( "disable" )
Disable the dialog.
-
enable
- Signature:
- .dialog( "enable" )
Enable the dialog.
-
option
- Signature:
- .dialog( "option" , optionName , [value] )
Get or set any dialog option. If no value is specified, will act as a getter.
-
option
- Signature:
- .dialog( "option" , options )
Set multiple dialog options at once by providing an options object.
-
widget
- Signature:
- .dialog( "widget" )
Returns the .ui-dialog element.
-
close
- Signature:
- .dialog( "close" )
Close the dialog.
-
isOpen
- Signature:
- .dialog( "isOpen" )
Returns true if the dialog is currently open.
-
moveToTop
- Signature:
- .dialog( "moveToTop" )
Move the dialog to the top of the dialogs stack.
-
open
- Signature:
- .dialog( "open" )
Open the dialog.
Theming
The jQuery UI Dialog plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
If a deeper level of customization is needed, there are widget-specific classes referenced within the jquery.ui.dialog.css stylesheet that can be modified. These classes are highlighed in bold below.
Sample markup with jQuery UI CSS Framework classes
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-draggable ui-resizable"><div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-dialog-title-dialog" class="ui-dialog-title">Dialog title</span>
<a class="ui-dialog-titlebar-close ui-corner-all" ><span class="ui-icon ui-icon-closethick">close</span></a>
</div>
<div style="height: 200px; min-height: 109px; width: auto;" class="ui-dialog-content ui-widget-content" id="dialog">
<p>Dialog content goes here.</p>
</div>
</div>
Note: This is a sample of markup generated by the dialog plugin, not markup you should use to create a dialog. The only markup needed for that is <div></div>.