diff options
author | Scott González <scott.gonzalez@gmail.com> | 2009-08-03 14:28:54 +0000 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2009-08-03 14:28:54 +0000 |
commit | d6385b039b603aa898c2e412c442dd064fdbe446 (patch) | |
tree | 6d0263e8214bede5b5a9f608d47cbfed248e78ae | |
parent | 52ca5251123f62c48030115fbaa58fb4827dd413 (diff) | |
download | jquery-ui-d6385b039b603aa898c2e412c442dd064fdbe446.tar.gz jquery-ui-d6385b039b603aa898c2e412c442dd064fdbe446.zip |
Dialog: Support hash, array, string for cursorAt option. Use position plugin. Partial fix for #2525 - Standardised way to pass coordinates to plugins.
-rw-r--r-- | demos/dialog/animated.html | 1 | ||||
-rw-r--r-- | demos/dialog/default.html | 1 | ||||
-rw-r--r-- | demos/dialog/modal-confirmation.html | 1 | ||||
-rw-r--r-- | demos/dialog/modal-form.html | 1 | ||||
-rw-r--r-- | demos/dialog/modal-message.html | 1 | ||||
-rw-r--r-- | demos/dialog/modal.html | 1 | ||||
-rw-r--r-- | ui/ui.dialog.js | 85 |
7 files changed, 46 insertions, 45 deletions
diff --git a/demos/dialog/animated.html b/demos/dialog/animated.html index e54807f29..bf0d74efc 100644 --- a/demos/dialog/animated.html +++ b/demos/dialog/animated.html @@ -6,6 +6,7 @@ <script type="text/javascript" src="../../jquery-1.3.2.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.draggable.js"></script> + <script type="text/javascript" src="../../ui/ui.position.js"></script> <script type="text/javascript" src="../../ui/ui.resizable.js"></script> <script type="text/javascript" src="../../ui/ui.stackfix.js"></script> <script type="text/javascript" src="../../ui/ui.dialog.js"></script> diff --git a/demos/dialog/default.html b/demos/dialog/default.html index 58e07ca09..f59ee2d13 100644 --- a/demos/dialog/default.html +++ b/demos/dialog/default.html @@ -6,6 +6,7 @@ <script type="text/javascript" src="../../jquery-1.3.2.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.draggable.js"></script> + <script type="text/javascript" src="../../ui/ui.position.js"></script> <script type="text/javascript" src="../../ui/ui.resizable.js"></script> <script type="text/javascript" src="../../ui/ui.stackfix.js"></script> <script type="text/javascript" src="../../ui/ui.dialog.js"></script> diff --git a/demos/dialog/modal-confirmation.html b/demos/dialog/modal-confirmation.html index b8c9a7115..6a4b10d22 100644 --- a/demos/dialog/modal-confirmation.html +++ b/demos/dialog/modal-confirmation.html @@ -6,6 +6,7 @@ <script type="text/javascript" src="../../jquery-1.3.2.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.draggable.js"></script> + <script type="text/javascript" src="../../ui/ui.position.js"></script> <script type="text/javascript" src="../../ui/ui.resizable.js"></script> <script type="text/javascript" src="../../ui/ui.stackfix.js"></script> <script type="text/javascript" src="../../ui/ui.dialog.js"></script> diff --git a/demos/dialog/modal-form.html b/demos/dialog/modal-form.html index 32e3bbb63..548e454ec 100644 --- a/demos/dialog/modal-form.html +++ b/demos/dialog/modal-form.html @@ -6,6 +6,7 @@ <script type="text/javascript" src="../../jquery-1.3.2.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.draggable.js"></script> + <script type="text/javascript" src="../../ui/ui.position.js"></script> <script type="text/javascript" src="../../ui/ui.resizable.js"></script> <script type="text/javascript" src="../../ui/ui.stackfix.js"></script> <script type="text/javascript" src="../../ui/ui.dialog.js"></script> diff --git a/demos/dialog/modal-message.html b/demos/dialog/modal-message.html index ca826b191..24282589f 100644 --- a/demos/dialog/modal-message.html +++ b/demos/dialog/modal-message.html @@ -6,6 +6,7 @@ <script type="text/javascript" src="../../jquery-1.3.2.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.draggable.js"></script> + <script type="text/javascript" src="../../ui/ui.position.js"></script> <script type="text/javascript" src="../../ui/ui.resizable.js"></script> <script type="text/javascript" src="../../ui/ui.stackfix.js"></script> <script type="text/javascript" src="../../ui/ui.dialog.js"></script> diff --git a/demos/dialog/modal.html b/demos/dialog/modal.html index 8716e7310..fd4a7ba1f 100644 --- a/demos/dialog/modal.html +++ b/demos/dialog/modal.html @@ -6,6 +6,7 @@ <script type="text/javascript" src="../../jquery-1.3.2.js"></script> <script type="text/javascript" src="../../ui/ui.core.js"></script> <script type="text/javascript" src="../../ui/ui.draggable.js"></script> + <script type="text/javascript" src="../../ui/ui.position.js"></script> <script type="text/javascript" src="../../ui/ui.resizable.js"></script> <script type="text/javascript" src="../../ui/ui.stackfix.js"></script> <script type="text/javascript" src="../../ui/ui.dialog.js"></script> diff --git a/ui/ui.dialog.js b/ui/ui.dialog.js index 2815e4968..e0955664b 100644 --- a/ui/ui.dialog.js +++ b/ui/ui.dialog.js @@ -10,6 +10,7 @@ * Depends: * ui.core.js * ui.draggable.js + * ui.position.js * ui.resizable.js */ (function($) { @@ -376,56 +377,50 @@ $.widget("ui.dialog", { : Math.min(options.minHeight, options.height)); }, - _position: function(pos) { - var wnd = $(window), doc = $(document), - pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), - minTop = pTop, - uiDialog = this.uiDialog; - - if ($.inArray(pos, ['center','top','right','bottom','left']) >= 0) { - pos = [ - pos == 'right' || pos == 'left' ? pos : 'center', - pos == 'top' || pos == 'bottom' ? pos : 'middle' - ]; - } - if (pos.constructor != Array) { - pos = ['center', 'middle']; - } - if (pos[0].constructor == Number) { - pLeft += pos[0]; - } else { - switch (pos[0]) { - case 'left': - pLeft += 0; - break; - case 'right': - pLeft += wnd.width() - uiDialog.outerWidth(); - break; - default: - case 'center': - pLeft += (wnd.width() - uiDialog.outerWidth()) / 2; + _position: function(position) { + var myAt = [], + offset = [0, 0]; + + // deep extending converts arrays to objects in jQuery <= 1.3.2 :-( +// if (typeof position == 'string' || $.isArray(position)) { +// myAt = $.isArray(position) ? position : position.split(' '); + if (typeof position == 'string' || '0' in position) { + myAt = position.split ? position.split(' ') : [position[0], position[1]]; + if (myAt.length == 1) { + myAt[1] = myAt[0]; } - } - if (pos[1].constructor == Number) { - pTop += pos[1]; + + $.each(['left', 'top'], function(i, offsetPosition) { + if (+myAt[i] == myAt[i]) { + offset[i] = myAt[i]; + myAt[i] = offsetPosition; + } + }); } else { - switch (pos[1]) { - case 'top': - pTop += 0; - break; - case 'bottom': - pTop += wnd.height() - uiDialog.outerHeight(); - break; - default: - case 'middle': - pTop += (wnd.height() - uiDialog.outerHeight()) / 2; + if ('left' in position) { + myAt[0] = 'left'; + offset[0] = position.left; + } else if ('right' in position) { + myAt[0] = 'right'; + offset[0] = -position.right; + } + + if ('top' in position) { + myAt[1] = 'top'; + offset[1] = position.top; + } else if ('bottom' in position) { + myAt[1] = 'bottom'; + offset[1] = -position.bottom; } } - // prevent the dialog from being too high (make sure the titlebar - // is accessible) - pTop = Math.max(pTop, minTop); - uiDialog.css({top: pTop, left: pLeft}); + this.uiDialog.position({ + my: myAt.join(' '), + at: myAt.join(' '), + offset: offset.join(' '), + of: window, + collision: 'fit' + }); }, _setData: function(key, value){ |