Dialog Widgetversion added: 1.0
Description: Open content in an interactive overlay.
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.
Focus
Upon opening a dialog, focus is automatically moved to the first item that matches the following:
- The first element within the dialog with the
autofocus
attribute - The first
:tabbable
element within the dialog's content - The first
:tabbable
element within the dialog's buttonpane - The dialog's close button
- The dialog itself
While open, the dialog widget ensures that tabbing cycles focus between elements within the dialog itself, not elements outside of it. Modal dialogs additionally prevent mouse users from clicking on elements outside of the dialog.
Upon closing a dialog, focus is automatically returned to the element that had focus when the dialog was opened.
Hiding the close button
In some cases, you may want to hide the close button, for instance, if you have a close button in the button pane. The best way to accomplish this is via CSS. As an example, you can define a simple rule, such as:
1
2
3
|
|
Then, you can simply add the no-close
class to any dialog in order to hide its close button:
1
2
3
4
5
6
7
8
9
10
11
|
|
Theming
The dialog widget uses the jQuery UI CSS framework to style its look and feel. If dialog specific styling is needed, the following CSS class names can be used:
-
ui-dialog
: The outer container of the dialog.-
ui-dialog-titlebar
: The title bar containing the dialog's title and close button.-
ui-dialog-title
: The container around the textual title of the dialog. -
ui-dialog-titlebar-close
: The dialog's close button.
-
-
ui-dialog-content
: The container around the dialog's content. This is also the element the widget was instantiated with. -
ui-dialog-buttonpane
: The pane that contains the dialog's buttons. This will only be present if thebuttons
option is set.-
ui-dialog-buttonset
: The container around the buttons themselves.
-
-
Additionally, when the modal
option is set, an element with a ui-widget-overlay
class name is appended to the <body>
.
Dependencies
Additional Notes:
- This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point.
Options
appendTo
"body"
Which element the dialog (and overlay, if modal) should be appended to.
appendTo
option should not be changed while the dialog is open.Initialize the dialog with the appendTo
option specified:
1
2
3
|
|
Get or set the appendTo
option, after initialization:
1
2
3
4
5
|
|
autoOpen
true
true
, the dialog will automatically open upon initialization. If false
, the dialog will stay hidden until the open()
method is called.Initialize the dialog with the autoOpen
option specified:
1
2
3
|
|
Get or set the autoOpen
option, after initialization:
1
2
3
4
5
|
|
closeOnEscape
true
Initialize the dialog with the closeOnEscape
option specified:
1
2
3
|
|
Get or set the closeOnEscape
option, after initialization:
1
2
3
4
5
|
|
closeText
"close"
Initialize the dialog with the closeText
option specified:
1
2
3
|
|
Get or set the closeText
option, after initialization:
1
2
3
4
5
|
|
dialogClass
""
Initialize the dialog with the dialogClass
option specified:
1
2
3
|
|
Get or set the dialogClass
option, after initialization:
1
2
3
4
5
|
|
draggable
true
true
, the dialog will be draggable by the title bar. Requires the jQuery UI Draggable widget to be included.Initialize the dialog with the draggable
option specified:
1
2
3
|
|
Get or set the draggable
option, after initialization:
1
2
3
4
5
|
|
height
"auto"
- Number: The height in pixels.
-
String: The only supported string value is
"auto"
which will allow the dialog height to adjust based on its content.
Initialize the dialog with the height
option specified:
1
2
3
|
|
Get or set the height
option, after initialization:
1
2
3
4
5
|
|
hide
null
-
Boolean:
When set to
false
, no animation will be used and the dialog will be hidden immediately. When set totrue
, the dialog will fade out with the default duration and the default easing. - Number: The dialog will fade out with the specified duration and the default easing.
-
String:
The dialog will be hidden using the specified effect.
The value can either be the name of a built-in jQuery animation method, such as
"slideUp"
, or the name of a jQuery UI effect, such as"fold"
. In either case the effect will be used with the default duration and the default easing. -
Object: If the value is an object, then
effect
,delay
,duration
, andeasing
properties may be provided. If theeffect
property contains the name of a jQuery method, then that method will be used; otherwise it is assumed to be the name of a jQuery UI effect. When using a jQuery UI effect that supports additional settings, you may include those settings in the object and they will be passed to the effect. Ifduration
oreasing
is omitted, then the default values will be used. Ifeffect
is omitted, then"fadeOut"
will be used. Ifdelay
is omitted, then no delay is used.
Initialize the dialog with the hide
option specified:
1
2
3
|
|
Get or set the hide
option, after initialization:
1
2
3
4
5
|
|
maxHeight
false
Initialize the dialog with the maxHeight
option specified:
1
2
3
|
|
Get or set the maxHeight
option, after initialization:
1
2
3
4
5
|
|
maxWidth
false
Initialize the dialog with the maxWidth
option specified:
1
2
3
|
|
Get or set the maxWidth
option, after initialization:
1
2
3
4
5
|
|
minHeight
150
Initialize the dialog with the minHeight
option specified:
1
2
3
|
|
Get or set the minHeight
option, after initialization:
1
2
3
4
5
|
|
minWidth
150
Initialize the dialog with the minWidth
option specified:
1
2
3
|
|
Get or set the minWidth
option, after initialization:
1
2
3
4
5
|
|
modal
false
true
, the dialog will have modal behavior; other items on the page will be disabled, i.e., cannot be interacted with. Modal dialogs create an overlay below the dialog but above other page elements.Initialize the dialog with the modal
option specified:
1
2
3
|
|
Get or set the modal
option, after initialization:
1
2
3
4
5
|
|
position
{ my: "center", at: "center", of: window }
Specifies where the dialog should be displayed. The dialog will handle collisions such that as much of the dialog is visible as possible.
Note: The String
and Array
forms are deprecated.
-
Object: Identifies the position of the dialog when opened. The
of
option defaults to the window, but you can specify another element to position against. You can refer to the jQuery UI Position utility for more details about the various options. -
String: A string representing the position within the viewport. Possible values:
"center"
,"left"
,"right"
,"top"
,"bottom"
. - Array: An array containing an x, y coordinate pair in pixel offset from the top left corner of the viewport or the name of a possible string value.
Initialize the dialog with the position
option specified:
1
2
3
|
|
Get or set the position
option, after initialization:
1
2
3
4
5
|
|
resizable
true
true
, the dialog will be resizable. Requires the jQuery UI Resizable widget to be included.Initialize the dialog with the resizable
option specified:
1
2
3
|
|
Get or set the resizable
option, after initialization:
1
2
3
4
5
|
|
show
null
-
Boolean:
When set to
false
, no animation will be used and the dialog will be shown immediately. When set totrue
, the dialog will fade in with the default duration and the default easing. - Number: The dialog will fade in with the specified duration and the default easing.
-
String:
The dialog will be shown using the specified effect.
The value can either be the name of a built-in jQuery animation method, such as
"slideDown"
, or the name of a jQuery UI effect, such as"fold"
. In either case the effect will be used with the default duration and the default easing. -
Object: If the value is an object, then
effect
,delay
,duration
, andeasing
properties may be provided. If theeffect
property contains the name of a jQuery method, then that method will be used; otherwise it is assumed to be the name of a jQuery UI effect. When using a jQuery UI effect that supports additional settings, you may include those settings in the object and they will be passed to the effect. Ifduration
oreasing
is omitted, then the default values will be used. Ifeffect
is omitted, then"fadeIn"
will be used. Ifdelay
is omitted, then no delay is used.
Initialize the dialog with the show
option specified:
1
2
3
|
|
Get or set the show
option, after initialization:
1
2
3
4
5
|
|
title
null
null
, the title
attribute on the dialog source element will be used.Initialize the dialog with the title
option specified:
1
2
3
|
|
Get or set the title
option, after initialization:
1
2
3
4
5
|
|
width
300
Initialize the dialog with the width
option specified:
1
2
3
|
|
Get or set the width
option, after initialization:
1
2
3
4
5
|
|
Methods
close()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the close method:
1
|
|
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
isOpen()Returns: Boolean
- This method does not accept any arguments.
Invoke the isOpen method:
1
|
|
moveToTop()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the moveToTop method:
1
|
|
open()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the open method:
1
|
|
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
widget()Returns: jQuery
jQuery
object containing the generated wrapper.
- This method does not accept any arguments.
Invoke the widget method:
1
|
|
Extension Points
The dialog widget is built with the widget factory and can be extended. When extending widgets, you have the ability to override or add to the behavior of existing methods. The following methods are provided as extension points with the same API stability as the plugin methods listed above. For more information on widget extensions, see Extending Widgets with the Widget Factory.
_allowInteraction( event )Returns: Boolean
_allowInteraction()
method determines whether the user should be allowed to interact with a given target element; therefore, it can be used to whitelist elements that are not children of the dialog but you want users to be able to use.
-
eventType: Event
Allow the Select2 plugin to be used within modal dialogs. The _super()
call ensures elements within the dialog can still be interacted with.
1
2
3
|
|
Events
beforeClose( event, ui )Type: dialogbeforeclose
Note: The ui
object is empty but included for consistency with other events.
Initialize the dialog with the beforeClose callback specified:
1
2
3
|
|
Bind an event listener to the dialogbeforeclose event:
1
|
|
close( event, ui )Type: dialogclose
Note: The ui
object is empty but included for consistency with other events.
Initialize the dialog with the close callback specified:
1
2
3
|
|
Bind an event listener to the dialogclose event:
1
|
|
create( event, ui )Type: dialogcreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the dialog with the create callback specified:
1
2
3
|
|
Bind an event listener to the dialogcreate event:
1
|
|
drag( event, ui )Type: dialogdrag
Initialize the dialog with the drag callback specified:
1
2
3
|
|
Bind an event listener to the dialogdrag event:
1
|
|
dragStart( event, ui )Type: dialogdragstart
Initialize the dialog with the dragStart callback specified:
1
2
3
|
|
Bind an event listener to the dialogdragstart event:
1
|
|
dragStop( event, ui )Type: dialogdragstop
Initialize the dialog with the dragStop callback specified:
1
2
3
|
|
Bind an event listener to the dialogdragstop event:
1
|
|
focus( event, ui )Type: dialogfocus
Note: The ui
object is empty but included for consistency with other events.
Initialize the dialog with the focus callback specified:
1
2
3
|
|
Bind an event listener to the dialogfocus event:
1
|
|
open( event, ui )Type: dialogopen
Note: The ui
object is empty but included for consistency with other events.
Initialize the dialog with the open callback specified:
1
2
3
|
|
Bind an event listener to the dialogopen event:
1
|
|
resize( event, ui )Type: dialogresize
Initialize the dialog with the resize callback specified:
1
2
3
|
|
Bind an event listener to the dialogresize event:
1
|
|
resizeStart( event, ui )Type: dialogresizestart
Initialize the dialog with the resizeStart callback specified:
1
2
3
|
|
Bind an event listener to the dialogresizestart event:
1
|
|
resizeStop( event, ui )Type: dialogresizestop
Initialize the dialog with the resizeStop callback specified:
1
2
3
|
|
Bind an event listener to the dialogresizestop event:
1
|
|
Example:
A simple jQuery UI Dialog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
|