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.
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
appendToType: Selector
"body"
Initialize the dialog with the appendTo option specified:
$( ".selector" ).dialog({ appendTo: "#someElem" }); |
Get or set the appendTo option, after initialization:
// getter var appendTo = $( ".selector" ).dialog( "option" , "appendTo" ); // setter $( ".selector" ).dialog( "option" , "appendTo" , "#someElem" ); |
autoOpenType: Boolean
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:
$( ".selector" ).dialog({ autoOpen: false }); |
Get or set the autoOpen option, after initialization:
// getter var autoOpen = $( ".selector" ).dialog( "option" , "autoOpen" ); // setter $( ".selector" ).dialog( "option" , "autoOpen" , false ); |
closeOnEscapeType: Boolean
true
Initialize the dialog with the closeOnEscape option specified:
$( ".selector" ).dialog({ closeOnEscape: false }); |
Get or set the closeOnEscape option, after initialization:
// getter var closeOnEscape = $( ".selector" ).dialog( "option" , "closeOnEscape" ); // setter $( ".selector" ).dialog( "option" , "closeOnEscape" , false ); |
closeTextType: String
"close"
Initialize the dialog with the closeText option specified:
$( ".selector" ).dialog({ closeText: "hide" }); |
Get or set the closeText option, after initialization:
// getter var closeText = $( ".selector" ).dialog( "option" , "closeText" ); // setter $( ".selector" ).dialog( "option" , "closeText" , "hide" ); |
dialogClassType: String
""
Initialize the dialog with the dialogClass option specified:
$( ".selector" ).dialog({ dialogClass: "alert" }); |
Get or set the dialogClass option, after initialization:
// getter var dialogClass = $( ".selector" ).dialog( "option" , "dialogClass" ); // setter $( ".selector" ).dialog( "option" , "dialogClass" , "alert" ); |
draggableType: Boolean
true
true
, the dialog will be draggable by the title bar. Requires the jQuery UI Draggable wiget to be included.Initialize the dialog with the draggable option specified:
$( ".selector" ).dialog({ draggable: false }); |
Get or set the draggable option, after initialization:
// getter var draggable = $( ".selector" ).dialog( "option" , "draggable" ); // setter $( ".selector" ).dialog( "option" , "draggable" , false ); |
heightType: Number or String
"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:
$( ".selector" ).dialog({ height: 400 }); |
Get or set the height option, after initialization:
// getter var height = $( ".selector" ).dialog( "option" , "height" ); // setter $( ".selector" ).dialog( "option" , "height" , 400 ); |
hideType: Number or String or Object
null
- Number: The dialog will fade out while animating the height and width for the specified duration.
- String: The dialog will be hidden using the specified jQuery UI effect. See the list of effects for possible values.
-
Object: If the value is an object, then
effect
,duration
, andeasing
properties may be provided. Theeffect
property must 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.
Initialize the dialog with the hide option specified:
$( ".selector" ).dialog({ hide: "explode" }); |
Get or set the hide option, after initialization:
// getter var hide = $( ".selector" ).dialog( "option" , "hide" ); // setter $( ".selector" ).dialog( "option" , "hide" , "explode" ); |
maxHeightType: Number
false
Initialize the dialog with the maxHeight option specified:
$( ".selector" ).dialog({ maxHeight: 600 }); |
Get or set the maxHeight option, after initialization:
// getter var maxHeight = $( ".selector" ).dialog( "option" , "maxHeight" ); // setter $( ".selector" ).dialog( "option" , "maxHeight" , 600 ); |
maxWidthType: Number
false
Initialize the dialog with the maxWidth option specified:
$( ".selector" ).dialog({ maxWidth: 600 }); |
Get or set the maxWidth option, after initialization:
// getter var maxWidth = $( ".selector" ).dialog( "option" , "maxWidth" ); // setter $( ".selector" ).dialog( "option" , "maxWidth" , 600 ); |
minHeightType: Number
150
Initialize the dialog with the minHeight option specified:
$( ".selector" ).dialog({ minHeight: 200 }); |
Get or set the minHeight option, after initialization:
// getter var minHeight = $( ".selector" ).dialog( "option" , "minHeight" ); // setter $( ".selector" ).dialog( "option" , "minHeight" , 200 ); |
minWidthType: Number
150
Initialize the dialog with the minWidth option specified:
$( ".selector" ).dialog({ minWidth: 200 }); |
Get or set the minWidth option, after initialization:
// getter var minWidth = $( ".selector" ).dialog( "option" , "minWidth" ); // setter $( ".selector" ).dialog( "option" , "minWidth" , 200 ); |
modalType: Boolean
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:
$( ".selector" ).dialog({ modal: true }); |
Get or set the modal option, after initialization:
// getter var modal = $( ".selector" ).dialog( "option" , "modal" ); // setter $( ".selector" ).dialog( "option" , "modal" , true ); |
positionType: Object or String or Array
{ 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:
$( ".selector" ).dialog({ position: { my: "left top" , at: "left bottom" , of: button } }); |
Get or set the position option, after initialization:
// getter var position = $( ".selector" ).dialog( "option" , "position" ); // setter $( ".selector" ).dialog( "option" , "position" , { my: "left top" , at: "left bottom" , of: button } ); |
resizableType: Boolean
true
true
, the dialog will be resizable. Requires the jQuery UI Resizable widget to be included.Initialize the dialog with the resizable option specified:
$( ".selector" ).dialog({ resizable: false }); |
Get or set the resizable option, after initialization:
// getter var resizable = $( ".selector" ).dialog( "option" , "resizable" ); // setter $( ".selector" ).dialog( "option" , "resizable" , false ); |
showType: Number or String or Object
null
- Number: The dialog will fade in while animating the height and width for the specified duration.
- String: The dialog will be shown using the specified jQuery UI effect. See the list of effects for possible values.
-
Object: If the value is an object, then
effect
,duration
, andeasing
properties may be provided. Theeffect
property must 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.
Initialize the dialog with the show option specified:
$( ".selector" ).dialog({ show: "slow" }); |
Get or set the show option, after initialization:
// getter var show = $( ".selector" ).dialog( "option" , "show" ); // setter $( ".selector" ).dialog( "option" , "show" , "slow" ); |
titleType: String
null
title
attribute on the dialog source element.Initialize the dialog with the title option specified:
$( ".selector" ).dialog({ title: "Dialog Title" }); |
Get or set the title option, after initialization:
// getter var title = $( ".selector" ).dialog( "option" , "title" ); // setter $( ".selector" ).dialog( "option" , "title" , "Dialog Title" ); |
widthType: Number
300
Initialize the dialog with the width option specified:
$( ".selector" ).dialog({ width: 500 }); |
Get or set the width option, after initialization:
// getter var width = $( ".selector" ).dialog( "option" , "width" ); // setter $( ".selector" ).dialog( "option" , "width" , 500 ); |
Methods
close()
- This method does not accept any arguments.
Invoke the close method:
$( ".selector" ).dialog( "close" ); |
destroy()
- This method does not accept any arguments.
Invoke the destroy method:
$( ".selector" ).dialog( "destroy" ); |
isOpen()Returns: Boolean
- This method does not accept any arguments.
Invoke the isOpen method:
var isOpen = $( ".selector" ).dialog( "isOpen" ); |
moveToTop()
- This method does not accept any arguments.
Invoke the moveToTop method:
$( ".selector" ).dialog( "moveToTop" ); |
open()
- This method does not accept any arguments.
Invoke the open method:
$( ".selector" ).dialog( "open" ); |
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
var isDisabled = $( ".selector" ).dialog( "option" , "disabled" ); |
option()Returns: PlainObject
- This method does not accept any arguments.
Invoke the method:
var options = $( ".selector" ).dialog( "option" ); |
option( optionName, value )
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
$( ".selector" ).dialog( "option" , "disabled" , true ); |
option( options )
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
$( ".selector" ).dialog( "option" , { disabled: true } ); |
widget()Returns: jQuery
jQuery
object containing the generated wrapper.
- This method does not accept any arguments.
Invoke the widget method:
var widget = $( ".selector" ).dialog( "widget" ); |
Events
beforeClose( event, ui )Type: dialogbeforeclose
Initialize the dialog with the beforeClose callback specified:
$( ".selector" ).dialog({ beforeClose: function ( event, ui ) {} }); |
Bind an event listener to the dialogbeforeclose event:
$( ".selector" ).on( "dialogbeforeclose" , function ( event, ui ) {} ); |
close( event, ui )Type: dialogclose
Initialize the dialog with the close callback specified:
$( ".selector" ).dialog({ close: function ( event, ui ) {} }); |
Bind an event listener to the dialogclose event:
$( ".selector" ).on( "dialogclose" , function ( event, ui ) {} ); |
create( event, ui )Type: dialogcreate
Initialize the dialog with the create callback specified:
$( ".selector" ).dialog({ create: function ( event, ui ) {} }); |
Bind an event listener to the dialogcreate event:
$( ".selector" ).on( "dialogcreate" , function ( event, ui ) {} ); |
drag( event, ui )Type: dialogdrag
Initialize the dialog with the drag callback specified:
$( ".selector" ).dialog({ drag: function ( event, ui ) {} }); |
Bind an event listener to the dialogdrag event:
$( ".selector" ).on( "dialogdrag" , function ( event, ui ) {} ); |
dragStart( event, ui )Type: dialogdragstart
Initialize the dialog with the dragStart callback specified:
$( ".selector" ).dialog({ dragStart: function ( event, ui ) {} }); |
Bind an event listener to the dialogdragstart event:
$( ".selector" ).on( "dialogdragstart" , function ( event, ui ) {} ); |
dragStop( event, ui )Type: dialogdragstop
Initialize the dialog with the dragStop callback specified:
$( ".selector" ).dialog({ dragStop: function ( event, ui ) {} }); |
Bind an event listener to the dialogdragstop event:
$( ".selector" ).on( "dialogdragstop" , function ( event, ui ) {} ); |
focus( event, ui )Type: dialogfocus
Initialize the dialog with the focus callback specified:
$( ".selector" ).dialog({ focus: function ( event, ui ) {} }); |
Bind an event listener to the dialogfocus event:
$( ".selector" ).on( "dialogfocus" , function ( event, ui ) {} ); |
open( event, ui )Type: dialogopen
Initialize the dialog with the open callback specified:
$( ".selector" ).dialog({ open: function ( event, ui ) {} }); |
Bind an event listener to the dialogopen event:
$( ".selector" ).on( "dialogopen" , function ( event, ui ) {} ); |
resize( event, ui )Type: dialogresize
Initialize the dialog with the resize callback specified:
$( ".selector" ).dialog({ resize: function ( event, ui ) {} }); |
Bind an event listener to the dialogresize event:
$( ".selector" ).on( "dialogresize" , function ( event, ui ) {} ); |
resizeStart( event, ui )Type: dialogresizestart
Initialize the dialog with the resizeStart callback specified:
$( ".selector" ).dialog({ resizeStart: function ( event, ui ) {} }); |
Bind an event listener to the dialogresizestart event:
$( ".selector" ).on( "dialogresizestart" , function ( event, ui ) {} ); |
resizeStop( event, ui )Type: dialogresizestop
Initialize the dialog with the resizeStop callback specified:
$( ".selector" ).dialog({ resizeStop: function ( event, ui ) {} }); |
Bind an event listener to the dialogresizestop event:
$( ".selector" ).on( "dialogresizestop" , function ( event, ui ) {} ); |
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 | <!doctype html> < html lang = "en" > < head > < meta charset = "utf-8" > < title >dialog demo</ title > </ head > < body > < button id = "opener" >open the dialog</ button > < div id = "dialog" title = "Dialog Title" >I'm a dialog</ div > < script > $( "#dialog" ).dialog({ autoOpen: false }); $( "#opener" ).click(function() { $( "#dialog" ).dialog( "open" ); }); </ script > </ body > </ html > |