r2885 - positionTo: basic tests for collision detection and a fix for flip.left (copy/paste error)

r2885 - positionTo: basic tests for collision detection and a fix for flip.left (copy/paste error)


Author: joern.zaefferer
Date: Tue Jul 7 14:07:53 2009
New Revision: 2885
Modified:
branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js
branches/dev/positionTo/ui/ui.positionTo.js
Log:
positionTo: basic tests for collision detection and a fix for flip.left
(copy/paste error)
Modified: branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js
==============================================================================
--- branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js    
(original)
+++ branches/dev/positionTo/tests/unit/positionTo/positionTo_core.js    Tue
Jul 7 14:07:53 2009
@@ -233,4 +233,79 @@
    });
});
+function collisionTest(config, result, msg) {
+    var elem = $("#elx").positionTo($.extend({
+        my: "left top",
+        at: "right bottom",
+        of: window,
+    }, config));
+    same(elem.offset(), result, msg);
+}
+
+test("collision: fit, no offset", function() {
+    collisionTest({
+        collision: "fit"
+    }, { top: $(window).height() - 10, left: $(window).width() - 10 }, "moved
to the right bottom");
+    
+    collisionTest({
+        my: "right bottom",
+        at: "left top",
+        collision: "fit"
+    }, { top: 0, left: 0 }, "moved to the left top");
+});
+
+test("collision: fit, with offset", function() {
+    collisionTest({
+        collision: "fit",
+        offset: "2 3"
+    }, { top: $(window).height() - 10, left: $(window).width() - 10 }, "moved
to the right bottom")
+    
+    collisionTest({
+        my: "right bottom",
+        at: "left top",
+        collision: "fit",
+        offset: "2 3"
+    }, { top: 0, left: 0 }, "moved to the left top, positive offset")
+    
+    collisionTest({
+        my: "right bottom",
+        at: "left top",
+        collision: "fit",
+        offset: "-2 -3"
+    }, { top: 0, left: 0 }, "moved to the left top, negative offset")
+});
+
+test("collision: flip, no offset", function() {
+    collisionTest({
+        collision: "flip"
+    }, { top: -10, left: -10 }, "moved to the left top")
+    
+    collisionTest({
+        my: "right bottom",
+        at: "left top",
+        collision: "flip"
+    }, { top: $(window).height(), left: $(window).width() }, "moved to the
right bottom");
+});
+
+test("collision: flip, with offset", function() {
+    collisionTest({
+        collision: "flip",
+        offset: "2 3"
+    }, { top: -13, left: -12 }, "moved to the left top, with offset added")
+    
+    collisionTest({
+        my: "right bottom",
+        at: "left top",
+        collision: "flip",
+        offset: "2 3"
+    }, { top: $(window).height() - 3, left: $(window).width() - 2 }, "moved
to the right bottom, positive offset")
+    
+    collisionTest({
+        my: "right bottom",
+        at: "left top",
+        collision: "flip",
+        offset: "-2 -3"
+    }, { top: $(window).height() + 3, left: $(window).width() + 2 }, "moved
to the right bottom, negative offset")
+});
+
})(jQuery);
Modified: branches/dev/positionTo/ui/ui.positionTo.js
==============================================================================
--- branches/dev/positionTo/ui/ui.positionTo.js    (original)
+++ branches/dev/positionTo/ui/ui.positionTo.js    Tue Jul 7 14:07:53 2009
@@ -154,8 +154,8 @@
    flip: {
        left: function(position, data) {
-            var over = position.top + data.elemHeight - $(window).width() -
$(window).scrollLeft();
-            myOffset = data.my[0] == 'left' ? -data.elemWidth : data.elemWidth;
+            var over = position.left + data.elemWidth - $(window).width() -
$(window).scrollLeft();
+            var myOffset = data.my[0] == 'left' ? -data.elemWidth : data.elemWidth;
            position.left += position.left < 0 ? myOffset + data.targetWidth : over