r3263 committed - dialog: fixed _position regression; wrote a test for the default posit...

r3263 committed - dialog: fixed _position regression; wrote a test for the default posit...


Revision: 3263
Author: joern.zaefferer
Date: Sat Sep 19 07:03:53 2009
Log: dialog: fixed _position regression; wrote a test for the default
positon, which still needs some tuning
http://code.google.com/p/jquery-ui/source/detail?r=3263
Modified:
/trunk/tests/unit/dialog/dialog_options.js
/trunk/ui/jquery.ui.dialog.js
=======================================
--- /trunk/tests/unit/dialog/dialog_options.js    Sat Sep 19 03:16:08 2009
+++ /trunk/tests/unit/dialog/dialog_options.js    Sat Sep 19 07:03:53 2009
@@ -240,7 +240,16 @@
    ok(false, 'missing test - untested code is broken code');
});
-test("position", function() {
+test("position, default center on window", function() {
+    var el = $('<div></div>').dialog();
+    var offset = el.parent().offset();
+    // use .position() instead to avoid replicating center-logic?
+    same(offset.left, Math.floor($(window).width() / 2 - el.parent().width()
/ 2));
+    same(offset.top, Math.floor($(window).height() / 2 - el.parent().height()
/ 2));
+    el.remove();
+});
+
+test("position, others", function() {
    ok(false, 'missing test - untested code is broken code');
});
=======================================
--- /trunk/ui/jquery.ui.dialog.js    Sat Sep 19 02:35:53 2009
+++ /trunk/ui/jquery.ui.dialog.js    Sat Sep 19 07:03:53 2009
@@ -382,35 +382,36 @@
        // deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
//        if (typeof position == 'string' || $.isArray(position)) {
//            myAt = $.isArray(position) ? position : position.split(' ');
-        if (!position || (typeof positon != "string" && typeof
positon != "object"))
-            return
-        if (typeof position == 'string' || '0' in position) {
-            myAt = position.split ? position.split(' ') : [position[0],
position[1]];
-            if (myAt.length == 1) {
-                myAt[1] = myAt[0];
-            }
-
-            $.each(['left', 'top'], function(i, offsetPosition) {
-                if (+myAt[i] == myAt[i]) {
-                    offset[i] = myAt[i];
-                    myAt[i] = offsetPosition;
-                }
-            });
-        } else {
-            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;
+
+        if (position && (typeof positon == "string" || typeof positon
== "object")) {
+            if (typeof position == 'string' || '0' in position) {
+                myAt = position.split ? position.split(' ') : [position[0],
position[1]];
+                if (myAt.length == 1) {
+                    myAt[1] = myAt[0];
+                }
+
+                $.each(['left', 'top'], function(i, offsetPosition) {
+                    if (+myAt[i] == myAt[i]) {
+                        offset[i] = myAt[i];
+                        myAt[i] = offsetPosition;
+                    }
+                });
+            } else {
+                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;
+                }
            }
        }