]> source.dussan.org Git - jquery-ui.git/commitdiff
dialog: fixed _position regression; wrote a test for the default positon, which still...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Sat, 19 Sep 2009 14:03:53 +0000 (14:03 +0000)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Sat, 19 Sep 2009 14:03:53 +0000 (14:03 +0000)
tests/unit/dialog/dialog_options.js
ui/jquery.ui.dialog.js

index 7254431fde9f48371da9ff88af2f78b18c218608..761f03b2784cd2a41ecacaa7ac1b6c64e7804c72 100644 (file)
@@ -240,7 +240,16 @@ test("modal", function() {
        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');
 });
 
index ddeeda7c680f251352545652049219005141e5bb..702b30a923361c320d86a9501c369e901d4a51ed 100644 (file)
@@ -382,35 +382,36 @@ $.widget("ui.dialog", {
                // 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;
+               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;
                                }
-                       });
-               } 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;
                        }
                }