r2876 - positionTo: fixed "fit" collision detection to handle left/top window edges as well as ta...

r2876 - positionTo: fixed "fit" collision detection to handle left/top window edges as well as ta...


Author: joern.zaefferer
Date: Mon Jul 6 04:38:52 2009
New Revision: 2876
Modified:
branches/dev/positionTo/ui/ui.positionTo.js
Log:
positionTo: fixed "fit" collision detection to handle left/top window edges
as well as taking scrolling into account
Modified: branches/dev/positionTo/ui/ui.positionTo.js
==============================================================================
--- branches/dev/positionTo/ui/ui.positionTo.js    (original)
+++ branches/dev/positionTo/ui/ui.positionTo.js    Mon Jul 6 04:38:52 2009
@@ -112,32 +112,26 @@
                break;
        }
-        // TODO fit breaks when the window scrolls; need to take scrollLeft/Top
into account
-        // TODO fit works at the right/bottom edge
        if (collision[0] != "none") {
-            over = (position.left + elemWidth) - $(window).width();
-            if (over > 0) {
-                switch(collision[0]) {
-                case 'fit':
-                    position.left -= over;
-                    break;
-                case 'flip':
-                    // TODO not yet implemented
-                    break;
-                }
+            over = position.left + elemWidth - $(window).width() -
elem.scrollParent().scrollLeft();
+            switch(collision[0]) {
+            case 'fit':
+                position.left = over > 0 ? position.left - over : Math.max(0,
position.left);
+                break;
+            case 'flip':
+                // TODO not yet implemented
+                break;
            }
        }
        if (collision[1] != "none") {
-            over = (position.top + elemHeight) - $(window).height();
-            if (over > 0) {
-                switch(collision[1]) {
-                case 'fit':
-                    position.top -= over;
-                    break;
-                case 'flip':
-                    // TODO not yet implemented
-                    break;
-                }
+            over = (position.top + elemHeight) - $(window).height() -
elem.scrollParent().scrollTop();
+            switch(collision[1]) {
+            case 'fit':
+                position.top = over > 0 ? position.top - over : Math.max(0,
position.top);
+                break;
+            case 'flip':
+                // TODO not yet implemented
+                break;
            }
        }