jquery-ui/ui/jquery.ui.dialog.js

776 lines
19 KiB
JavaScript
Raw Normal View History

/*!
* jQuery UI Dialog @VERSION
2012-07-04 13:08:08 +00:00
* http://jqueryui.com
2008-06-04 02:34:33 +00:00
*
2013-01-10 13:52:20 +00:00
* Copyright 2013 jQuery Foundation and other contributors
2012-08-09 14:13:24 +00:00
* Released under the MIT license.
* http://jquery.org/license
*
2012-09-26 23:06:20 +00:00
* http://api.jqueryui.com/dialog/
2008-06-04 02:34:33 +00:00
*
* Depends:
* jquery.ui.core.js
2010-02-03 23:30:37 +00:00
* jquery.ui.widget.js
* jquery.ui.button.js
* jquery.ui.draggable.js
* jquery.ui.mouse.js
* jquery.ui.position.js
* jquery.ui.resizable.js
2008-06-04 02:34:33 +00:00
*/
(function( $, undefined ) {
2008-06-04 02:34:33 +00:00
2012-12-11 21:23:18 +00:00
var sizeRelatedOptions = {
buttons: true,
height: true,
maxHeight: true,
maxWidth: true,
minHeight: true,
minWidth: true,
width: true
},
resizableRelatedOptions = {
maxHeight: true,
maxWidth: true,
minHeight: true,
minWidth: true
};
2008-06-04 02:34:33 +00:00
2012-12-11 21:23:18 +00:00
$.widget( "ui.dialog", {
version: "@VERSION",
options: {
appendTo: "body",
autoOpen: true,
2012-12-11 21:23:18 +00:00
buttons: [],
closeOnEscape: true,
2010-12-18 00:53:22 +00:00
closeText: "close",
dialogClass: "",
draggable: true,
hide: null,
2010-12-18 00:53:22 +00:00
height: "auto",
maxHeight: null,
maxWidth: null,
minHeight: 150,
minWidth: 150,
modal: false,
position: {
2010-12-18 00:53:22 +00:00
my: "center",
at: "center",
of: window,
2010-12-18 00:53:22 +00:00
collision: "fit",
2012-12-11 21:23:18 +00:00
// Ensure the titlebar is always visible
2010-12-18 00:53:22 +00:00
using: function( pos ) {
var topOffset = $( this ).css( pos ).offset().top;
if ( topOffset < 0 ) {
$( this ).css( "top", pos.top - topOffset );
}
}
},
resizable: true,
show: null,
title: null,
2012-10-27 15:07:13 +00:00
width: 300,
// callbacks
beforeClose: null,
close: null,
drag: null,
dragStart: null,
dragStop: null,
focus: null,
open: null,
resize: null,
resizeStart: null,
resizeStop: null
},
2010-07-16 12:54:50 +00:00
_create: function() {
this.originalCss = {
display: this.element[0].style.display,
width: this.element[0].style.width,
minHeight: this.element[0].style.minHeight,
maxHeight: this.element[0].style.maxHeight,
height: this.element[0].style.height
};
2012-12-11 21:23:18 +00:00
this.originalPosition = {
2012-04-19 01:57:51 +00:00
parent: this.element.parent(),
index: this.element.parent().children().index( this.element )
};
2012-12-12 13:47:05 +00:00
this.originalTitle = this.element.attr("title");
2012-12-11 21:23:18 +00:00
this.options.title = this.options.title || this.originalTitle;
this._createWrapper();
this.element
.show()
2012-12-12 13:47:05 +00:00
.removeAttr("title")
.addClass("ui-dialog-content ui-widget-content")
.appendTo( this.uiDialog );
2010-12-18 00:53:22 +00:00
this._createTitlebar();
this._createButtonPane();
if ( this.options.draggable && $.fn.draggable ) {
this._makeDraggable();
2010-03-12 01:10:57 +00:00
}
if ( this.options.resizable && $.fn.resizable ) {
this._makeResizable();
2010-03-12 01:10:57 +00:00
}
this._isOpen = false;
},
2010-07-16 12:54:50 +00:00
_init: function() {
if ( this.options.autoOpen ) {
this.open();
}
2008-06-04 02:34:33 +00:00
},
_appendTo: function() {
var element = this.options.appendTo;
if ( element && (element.jquery || element.nodeType) ) {
return $( element );
}
return this.document.find( element || "body" ).eq( 0 );
},
_destroy: function() {
var next,
2012-12-11 21:23:18 +00:00
originalPosition = this.originalPosition;
this._destroyOverlay();
this.element
.removeUniqueId()
2012-12-12 13:47:05 +00:00
.removeClass("ui-dialog-content ui-widget-content")
.css( this.originalCss )
2012-12-11 21:23:18 +00:00
// Without detaching first, the following becomes really slow
.detach();
this.uiDialog.stop( true, true ).remove();
if ( this.originalTitle ) {
this.element.attr( "title", this.originalTitle );
2010-03-12 01:10:57 +00:00
}
2012-04-19 01:57:51 +00:00
2012-12-11 21:23:18 +00:00
next = originalPosition.parent.children().eq( originalPosition.index );
// Don't try to place the dialog next to itself (#8613)
2012-12-12 13:47:05 +00:00
if ( next.length && next[0] !== this.element[0] ) {
next.before( this.element );
} else {
2012-12-11 21:23:18 +00:00
originalPosition.parent.append( this.element );
2012-04-19 01:57:51 +00:00
}
2008-09-14 14:49:28 +00:00
},
2010-07-16 12:54:50 +00:00
widget: function() {
return this.uiDialog;
},
disable: $.noop,
enable: $.noop,
2010-12-18 00:53:22 +00:00
close: function( event ) {
var that = this;
2012-12-11 21:23:18 +00:00
if ( !this._isOpen || this._trigger( "beforeClose", event ) === false ) {
return;
}
this._isOpen = false;
this._destroyOverlay();
2012-12-12 13:47:05 +00:00
if ( !this.opener.filter(":focusable").focus().length ) {
// Hiding a focused element doesn't trigger blur in WebKit
// so in case we have nothing to focus on, explicitly blur the active element
// https://bugs.webkit.org/show_bug.cgi?id=47182
2012-12-12 13:47:05 +00:00
$( this.document[0].activeElement ).blur();
}
this._hide( this.uiDialog, this.options.hide, function() {
that._trigger( "close", event );
});
2008-09-14 14:49:28 +00:00
},
2008-09-14 14:49:28 +00:00
isOpen: function() {
return this._isOpen;
},
moveToTop: function() {
this._moveToTop();
},
_moveToTop: function( event, silent ) {
2012-12-12 13:47:05 +00:00
var moved = !!this.uiDialog.nextAll(":visible").insertBefore( this.uiDialog ).length;
2012-12-11 21:23:18 +00:00
if ( moved && !silent ) {
this._trigger( "focus", event );
2010-03-12 01:10:57 +00:00
}
return moved;
2008-09-29 13:08:14 +00:00
},
open: function() {
var that = this;
2010-12-18 00:53:22 +00:00
if ( this._isOpen ) {
if ( this._moveToTop() ) {
this._focusTabbable();
}
2010-12-18 00:53:22 +00:00
return;
}
this._isOpen = true;
2012-12-12 13:47:05 +00:00
this.opener = $( this.document[0].activeElement );
this._size();
this._position();
this._createOverlay();
this._moveToTop( null, true );
this._show( this.uiDialog, this.options.show, function() {
that._focusTabbable();
that._trigger("focus");
});
2012-12-12 13:47:05 +00:00
this._trigger("open");
},
_focusTabbable: function() {
2012-12-11 21:23:18 +00:00
// Set focus to the first match:
// 1. First element inside the dialog matching [autofocus]
// 2. Tabbable element inside the content element
// 3. Tabbable element inside the buttonpane
// 4. The close button
// 5. The dialog itself
2012-12-12 13:47:05 +00:00
var hasFocus = this.element.find("[autofocus]");
if ( !hasFocus.length ) {
2012-12-12 13:47:05 +00:00
hasFocus = this.element.find(":tabbable");
2012-12-11 21:23:18 +00:00
}
if ( !hasFocus.length ) {
2012-12-12 13:47:05 +00:00
hasFocus = this.uiDialogButtonPane.find(":tabbable");
2012-12-11 21:23:18 +00:00
}
if ( !hasFocus.length ) {
2012-12-12 13:47:05 +00:00
hasFocus = this.uiDialogTitlebarClose.filter(":tabbable");
2012-12-11 21:23:18 +00:00
}
if ( !hasFocus.length ) {
hasFocus = this.uiDialog;
}
hasFocus.eq( 0 ).focus();
2008-09-14 14:49:28 +00:00
},
_keepFocus: function( event ) {
function checkFocus() {
2012-12-12 13:47:05 +00:00
var activeElement = this.document[0].activeElement,
isActive = this.uiDialog[0] === activeElement ||
$.contains( this.uiDialog[0], activeElement );
if ( !isActive ) {
this._focusTabbable();
}
}
event.preventDefault();
checkFocus.call( this );
// support: IE
// IE <= 8 doesn't prevent moving focus even with event.preventDefault()
// so we check again later
this._delay( checkFocus );
},
_createWrapper: function() {
2012-12-12 13:47:05 +00:00
this.uiDialog = $("<div>")
2012-12-11 21:23:18 +00:00
.addClass( "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front " +
this.options.dialogClass )
.hide()
.attr({
2012-12-11 21:23:18 +00:00
// Setting tabIndex makes the div focusable
tabIndex: -1,
role: "dialog"
})
.appendTo( this._appendTo() );
this._on( this.uiDialog, {
keydown: function( event ) {
if ( this.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
event.keyCode === $.ui.keyCode.ESCAPE ) {
event.preventDefault();
this.close( event );
return;
}
// prevent tabbing out of dialogs
if ( event.keyCode !== $.ui.keyCode.TAB ) {
return;
}
2012-12-12 13:47:05 +00:00
var tabbables = this.uiDialog.find(":tabbable"),
first = tabbables.filter(":first"),
last = tabbables.filter(":last");
2012-12-12 13:47:05 +00:00
if ( ( event.target === last[0] || event.target === this.uiDialog[0] ) && !event.shiftKey ) {
first.focus( 1 );
2012-12-11 21:23:18 +00:00
event.preventDefault();
2012-12-12 13:47:05 +00:00
} else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) {
last.focus( 1 );
2012-12-11 21:23:18 +00:00
event.preventDefault();
}
},
mousedown: function( event ) {
if ( this._moveToTop( event ) ) {
this._focusTabbable();
}
}
});
// We assume that any existing aria-describedby attribute means
// that the dialog content is marked up properly
// otherwise we brute force the content as the description
2012-12-12 13:47:05 +00:00
if ( !this.element.find("[aria-describedby]").length ) {
this.uiDialog.attr({
2012-12-12 13:47:05 +00:00
"aria-describedby": this.element.uniqueId().attr("id")
});
}
},
_createTitlebar: function() {
var uiDialogTitle;
2012-12-12 13:47:05 +00:00
this.uiDialogTitlebar = $("<div>")
.addClass("ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix")
.prependTo( this.uiDialog );
this._on( this.uiDialogTitlebar, {
mousedown: function( event ) {
// Don't prevent click on close button (#8838)
// Focusing a dialog that is partially scrolled out of view
// causes the browser to scroll it into view, preventing the click event
2012-12-12 13:47:05 +00:00
if ( !$( event.target ).closest(".ui-dialog-titlebar-close") ) {
// Dialog isn't getting focus when dragging (#8063)
this.uiDialog.focus();
}
}
});
2012-12-12 13:47:05 +00:00
this.uiDialogTitlebarClose = $("<button></button>")
.button({
label: this.options.closeText,
icons: {
primary: "ui-icon-closethick"
},
text: false
})
2012-12-12 13:47:05 +00:00
.addClass("ui-dialog-titlebar-close")
.appendTo( this.uiDialogTitlebar );
this._on( this.uiDialogTitlebarClose, {
2012-12-11 21:23:18 +00:00
click: function( event ) {
event.preventDefault();
this.close( event );
}
});
2012-12-12 13:47:05 +00:00
uiDialogTitle = $("<span>")
.uniqueId()
2012-12-12 13:47:05 +00:00
.addClass("ui-dialog-title")
.prependTo( this.uiDialogTitlebar );
this._title( uiDialogTitle );
this.uiDialog.attr({
2012-12-12 13:47:05 +00:00
"aria-labelledby": uiDialogTitle.attr("id")
});
},
_title: function( title ) {
if ( !this.options.title ) {
2012-12-12 13:47:05 +00:00
title.html("&#160;");
}
title.text( this.options.title );
},
_createButtonPane: function() {
2012-12-12 13:47:05 +00:00
this.uiDialogButtonPane = $("<div>")
.addClass("ui-dialog-buttonpane ui-widget-content ui-helper-clearfix");
2012-12-12 13:47:05 +00:00
this.uiButtonSet = $("<div>")
.addClass("ui-dialog-buttonset")
2012-12-11 21:23:18 +00:00
.appendTo( this.uiDialogButtonPane );
this._createButtons();
},
_createButtons: function() {
var that = this,
buttons = this.options.buttons;
// if we already have a button pane, remove it
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();
if ( $.isEmptyObject( buttons ) || ($.isArray( buttons ) && !buttons.length) ) {
2012-12-12 13:47:05 +00:00
this.uiDialog.removeClass("ui-dialog-buttons");
2012-12-11 21:23:18 +00:00
return;
2008-09-14 14:49:28 +00:00
}
2012-12-11 21:23:18 +00:00
$.each( buttons, function( name, props ) {
var click, buttonOptions;
props = $.isFunction( props ) ?
{ click: props, text: name } :
props;
// Default to a non-submitting button
props = $.extend( { type: "button" }, props );
// Change the context for the click callback to be the main element
click = props.click;
props.click = function() {
click.apply( that.element[0], arguments );
};
buttonOptions = {
icons: props.icons,
text: props.showText
};
delete props.icons;
delete props.showText;
$( "<button></button>", props )
.button( buttonOptions )
.appendTo( that.uiButtonSet );
});
2012-12-12 13:47:05 +00:00
this.uiDialog.addClass("ui-dialog-buttons");
2012-12-11 21:23:18 +00:00
this.uiDialogButtonPane.appendTo( this.uiDialog );
2008-09-14 14:49:28 +00:00
},
2008-09-14 14:49:28 +00:00
_makeDraggable: function() {
var that = this,
options = this.options;
2010-12-18 00:53:22 +00:00
function filteredUi( ui ) {
return {
position: ui.position,
offset: ui.offset
};
}
this.uiDialog.draggable({
2010-12-18 00:53:22 +00:00
cancel: ".ui-dialog-content, .ui-dialog-titlebar-close",
handle: ".ui-dialog-titlebar",
containment: "document",
start: function( event, ui ) {
2012-12-12 13:47:05 +00:00
$( this ).addClass("ui-dialog-dragging");
that._trigger( "dragStart", event, filteredUi( ui ) );
2008-09-14 14:49:28 +00:00
},
2010-12-18 00:53:22 +00:00
drag: function( event, ui ) {
that._trigger( "drag", event, filteredUi( ui ) );
2008-09-14 14:49:28 +00:00
},
2010-12-18 00:53:22 +00:00
stop: function( event, ui ) {
options.position = [
ui.position.left - that.document.scrollLeft(),
ui.position.top - that.document.scrollTop()
2010-12-18 00:53:22 +00:00
];
2012-12-12 13:47:05 +00:00
$( this ).removeClass("ui-dialog-dragging");
that._trigger( "dragStop", event, filteredUi( ui ) );
2008-09-14 14:49:28 +00:00
}
});
},
_makeResizable: function() {
var that = this,
options = this.options,
handles = options.resizable,
// .ui-resizable has position: relative defined in the stylesheet
// but dialogs have to use absolute or fixed positioning
2012-12-12 13:47:05 +00:00
position = this.uiDialog.css("position"),
resizeHandles = typeof handles === "string" ?
2010-03-12 01:10:57 +00:00
handles :
2010-12-18 00:53:22 +00:00
"n,e,s,w,se,sw,ne,nw";
2010-12-18 00:53:22 +00:00
function filteredUi( ui ) {
return {
originalPosition: ui.originalPosition,
originalSize: ui.originalSize,
position: ui.position,
size: ui.size
};
}
this.uiDialog.resizable({
2010-12-18 00:53:22 +00:00
cancel: ".ui-dialog-content",
containment: "document",
alsoResize: this.element,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
minWidth: options.minWidth,
minHeight: this._minHeight(),
handles: resizeHandles,
2010-12-18 00:53:22 +00:00
start: function( event, ui ) {
2012-12-12 13:47:05 +00:00
$( this ).addClass("ui-dialog-resizing");
that._trigger( "resizeStart", event, filteredUi( ui ) );
},
2010-12-18 00:53:22 +00:00
resize: function( event, ui ) {
that._trigger( "resize", event, filteredUi( ui ) );
},
2010-12-18 00:53:22 +00:00
stop: function( event, ui ) {
options.height = $( this ).height();
options.width = $( this ).width();
2012-12-12 13:47:05 +00:00
$( this ).removeClass("ui-dialog-resizing");
that._trigger( "resizeStop", event, filteredUi( ui ) );
}
})
2012-12-11 21:23:18 +00:00
.css( "position", position );
},
_minHeight: function() {
var options = this.options;
2012-12-11 21:23:18 +00:00
return options.height === "auto" ?
options.minHeight :
Math.min( options.minHeight, options.height );
},
_position: function() {
2012-12-11 21:23:18 +00:00
// Need to show the dialog to get the actual offset in the position plugin
2012-12-12 13:47:05 +00:00
var isVisible = this.uiDialog.is(":visible");
2010-12-18 00:53:22 +00:00
if ( !isVisible ) {
2010-01-07 04:47:17 +00:00
this.uiDialog.show();
}
this.uiDialog.position( this.options.position );
2010-12-18 00:53:22 +00:00
if ( !isVisible ) {
2010-01-07 04:47:17 +00:00
this.uiDialog.hide();
}
2008-06-04 02:34:33 +00:00
},
_setOptions: function( options ) {
var that = this,
2012-12-11 21:23:18 +00:00
resize = false,
resizableOptions = {};
2010-07-16 12:54:50 +00:00
$.each( options, function( key, value ) {
that._setOption( key, value );
if ( key in sizeRelatedOptions ) {
resize = true;
}
if ( key in resizableRelatedOptions ) {
resizableOptions[ key ] = value;
}
});
if ( resize ) {
this._size();
this._position();
}
2012-12-12 13:47:05 +00:00
if ( this.uiDialog.is(":data(ui-resizable)") ) {
this.uiDialog.resizable( "option", resizableOptions );
}
},
2010-12-18 00:53:22 +00:00
_setOption: function( key, value ) {
/*jshint maxcomplexity:15*/
2012-04-02 23:12:21 +00:00
var isDraggable, isResizable,
uiDialog = this.uiDialog;
if ( key === "dialogClass" ) {
uiDialog
.removeClass( this.options.dialogClass )
.addClass( value );
}
if ( key === "disabled" ) {
return;
}
this._super( key, value );
if ( key === "appendTo" ) {
this.uiDialog.appendTo( this._appendTo() );
}
if ( key === "buttons" ) {
this._createButtons();
}
if ( key === "closeText" ) {
this.uiDialogTitlebarClose.button({
2012-12-11 21:23:18 +00:00
// Ensure that we always pass a string
label: "" + value
});
}
if ( key === "draggable" ) {
2012-12-12 13:47:05 +00:00
isDraggable = uiDialog.is(":data(ui-draggable)");
if ( isDraggable && !value ) {
2012-12-12 13:47:05 +00:00
uiDialog.draggable("destroy");
}
if ( !isDraggable && value ) {
this._makeDraggable();
}
}
if ( key === "position" ) {
this._position();
}
if ( key === "resizable" ) {
// currently resizable, becoming non-resizable
2012-12-12 13:47:05 +00:00
isResizable = uiDialog.is(":data(ui-resizable)");
if ( isResizable && !value ) {
2012-12-12 13:47:05 +00:00
uiDialog.resizable("destroy");
}
// currently resizable, changing handles
if ( isResizable && typeof value === "string" ) {
uiDialog.resizable( "option", "handles", value );
}
// currently non-resizable, becoming resizable
if ( !isResizable && value !== false ) {
this._makeResizable();
}
}
if ( key === "title" ) {
2012-12-12 13:47:05 +00:00
this._title( this.uiDialogTitlebar.find(".ui-dialog-title") );
2008-09-14 14:49:28 +00:00
}
},
_size: function() {
2012-10-29 18:37:06 +00:00
// If the user has resized the dialog, the .ui-dialog and .ui-dialog-content
// divs will both have width and height set, so we need to reset them
var nonContentHeight, minContentHeight, maxContentHeight,
options = this.options;
2012-12-11 21:23:18 +00:00
// Reset content sizing
this.element.show().css({
2010-12-18 00:53:22 +00:00
width: "auto",
minHeight: 0,
maxHeight: "none",
height: 0
});
2010-12-18 00:53:22 +00:00
if ( options.minWidth > options.width ) {
options.width = options.minWidth;
}
// reset wrapper sizing
// determine the height of all the non-content elements
2010-03-12 01:10:57 +00:00
nonContentHeight = this.uiDialog.css({
2010-12-18 00:53:22 +00:00
height: "auto",
width: options.width
})
.outerHeight();
minContentHeight = Math.max( 0, options.minHeight - nonContentHeight );
maxContentHeight = typeof options.maxHeight === "number" ?
Math.max( 0, options.maxHeight - nonContentHeight ) :
"none";
if ( options.height === "auto" ) {
this.element.css({
minHeight: minContentHeight,
maxHeight: maxContentHeight,
height: "auto"
});
} else {
this.element.height( Math.max( 0, options.height - nonContentHeight ) );
}
2012-12-12 13:47:05 +00:00
if (this.uiDialog.is(":data(ui-resizable)") ) {
2010-12-18 00:53:22 +00:00
this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
2010-03-12 01:10:57 +00:00
}
},
2008-06-04 02:34:33 +00:00
_createOverlay: function() {
if ( !this.options.modal ) {
return;
}
2012-12-11 21:23:18 +00:00
if ( !$.ui.dialog.overlayInstances ) {
// Prevent use of anchors and inputs.
// We use a delay in case the overlay is created from an
// event that we're going to be cancelling. (#2804)
this._delay(function() {
2012-12-11 21:23:18 +00:00
// Handle .dialog().dialog("close") (#4065)
if ( $.ui.dialog.overlayInstances ) {
this._on( this.document, {
focusin: function( event ) {
if ( !$( event.target ).closest(".ui-dialog").length &&
// TODO: Remove hack when datepicker implements
// the .ui-front logic (#8989)
!$( event.target ).closest(".ui-datepicker").length ) {
event.preventDefault();
2012-12-12 13:47:05 +00:00
$(".ui-dialog:visible:last .ui-dialog-content")
.data("ui-dialog")._focusTabbable();
}
}
});
}
});
}
2012-05-07 13:57:18 +00:00
2012-12-12 13:47:05 +00:00
this.overlay = $("<div>")
.addClass("ui-widget-overlay ui-front")
.appendTo( this._appendTo() );
2012-12-11 21:23:18 +00:00
this._on( this.overlay, {
mousedown: "_keepFocus"
});
2012-12-11 21:23:18 +00:00
$.ui.dialog.overlayInstances++;
2008-06-04 02:34:33 +00:00
},
_destroyOverlay: function() {
if ( !this.options.modal ) {
return;
}
2012-12-11 21:23:18 +00:00
if ( this.overlay ) {
$.ui.dialog.overlayInstances--;
if ( !$.ui.dialog.overlayInstances ) {
this._off( this.document, "focusin" );
}
this.overlay.remove();
this.overlay = null;
2008-06-04 02:34:33 +00:00
}
}
});
$.ui.dialog.overlayInstances = 0;
2008-06-04 02:34:33 +00:00
// DEPRECATED
if ( $.uiBackCompat !== false ) {
// position option with array notation
// just override with old implementation
$.widget( "ui.dialog", $.ui.dialog, {
_position: function() {
var position = this.options.position,
myAt = [],
offset = [ 0, 0 ],
isVisible;
if ( position ) {
if ( typeof position === "string" || (typeof position === "object" && "0" in position ) ) {
2012-12-12 13:47:05 +00:00
myAt = position.split ? position.split(" ") : [ position[0], position[1] ];
if ( myAt.length === 1 ) {
2012-12-12 13:47:05 +00:00
myAt[1] = myAt[0];
}
$.each( [ "left", "top" ], function( i, offsetPosition ) {
if ( +myAt[ i ] === myAt[ i ] ) {
offset[ i ] = myAt[ i ];
myAt[ i ] = offsetPosition;
}
});
position = {
my: myAt[0] + (offset[0] < 0 ? offset[0] : "+" + offset[0]) + " " +
myAt[1] + (offset[1] < 0 ? offset[1] : "+" + offset[1]),
2012-12-12 13:47:05 +00:00
at: myAt.join(" ")
};
}
position = $.extend( {}, $.ui.dialog.prototype.options.position, position );
} else {
position = $.ui.dialog.prototype.options.position;
}
// need to show the dialog to get the actual offset in the position plugin
2012-12-12 13:47:05 +00:00
isVisible = this.uiDialog.is(":visible");
if ( !isVisible ) {
this.uiDialog.show();
}
this.uiDialog.position( position );
if ( !isVisible ) {
this.uiDialog.hide();
}
}
});
}
2010-12-18 00:53:22 +00:00
}( jQuery ) );