Removing unnecessary variables, caching 'within' in tests where its beneficial, and making some other changes based on the code review

This commit is contained in:
David Murdoch 2011-05-16 23:46:21 +00:00
parent f798b046e0
commit e4a42991df
3 changed files with 83 additions and 201 deletions

View File

@ -314,7 +314,8 @@ test( "collision: fit, with offset", function() {
test( "collision: fit, window scrolled", function() { test( "collision: fit, window scrolled", function() {
if ( scrollTopSupport() ) { if ( scrollTopSupport() ) {
var win = $( window ); var win = $( window );
$( window ).scrollTop( 300 ).scrollLeft( 200 ); win.scrollTop( 300 ).scrollLeft( 200 );
collisionTest({ collisionTest({
collision: "fit", collision: "fit",
at: "left-100 top-100" at: "left-100 top-100"

View File

@ -1,11 +1,16 @@
(function( $ ) { (function( $ ) {
$("#within-container").show();
function scrollTopSupport() { function scrollTopSupport() {
$( window ).scrollTop( 1 ); $( window ).scrollTop( 1 );
return $( window ).scrollTop() === 1; return $( window ).scrollTop() === 1;
} }
module( "position - within", {
setup: function(){
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}).show();
}
});
var addTop = -20, var addTop = -20,
addLeft = -20; addLeft = -20;
@ -19,17 +24,15 @@ $.fn.addOffsets = function() {
return {top: elOffset.top - offset.top, left: elOffset.left - offset.left }; return {top: elOffset.top - offset.top, left: elOffset.left - offset.left };
}; };
test( "within: my, at, of", function() { test( "my, at, of", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
$( "#elx" ).position({ $( "#elx" ).position({
my: "left top", my: "left top",
at: "left top", at: "left top",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "left top, left top" ); same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "left top, left top" );
@ -38,7 +41,7 @@ test( "within: my, at, of", function() {
at: "left bottom", at: "left bottom",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 60, left: addLeft + 40 }, "left top, left bottom" ); same( $( "#elx" ).addOffsets(), { top: addTop + 60, left: addLeft + 40 }, "left top, left bottom" );
@ -47,7 +50,7 @@ test( "within: my, at, of", function() {
at: "bottom", at: "bottom",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 55, left: addLeft + 50 }, "left, bottom" ); same( $( "#elx" ).addOffsets(), { top: addTop + 55, left: addLeft + 50 }, "left, bottom" );
@ -56,16 +59,12 @@ test( "within: my, at, of", function() {
at: "bar baz", at: "bar baz",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 45, left: addLeft +50 }, "left foo, bar baz" ); same( $( "#elx" ).addOffsets(), { top: addTop + 45, left: addLeft +50 }, "left foo, bar baz" );
}); });
test( "within: multiple elements", function() { test( "multiple elements", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"});
var elements = $( "#el1, #el2" ); var elements = $( "#el1, #el2" );
var result = elements.position({ var result = elements.position({
my: "left top", my: "left top",
@ -82,11 +81,7 @@ test( "within: multiple elements", function() {
}); });
}); });
test( "within: positions", function() { test( "positions", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"});
var definitions = []; var definitions = [];
var offsets = { var offsets = {
left: 0, left: 0,
@ -124,18 +119,15 @@ test( "within: positions", function() {
}); });
}); });
test( "within: of", function() { test( "of", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
$( "#elx" ).position({ $( "#elx" ).position({
my: "left top", my: "left top",
at: "left top", at: "left top",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "selector" ); same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "selector" );
@ -144,7 +136,7 @@ test( "within: of", function() {
at: "left bottom", at: "left bottom",
of: $( "#parentx"), of: $( "#parentx"),
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 60, left: addLeft + 40 }, "jQuery object" ); same( $( "#elx" ).addOffsets(), { top: addTop + 60, left: addLeft + 40 }, "jQuery object" );
@ -153,85 +145,17 @@ test( "within: of", function() {
at: "left top", at: "left top",
of: $( "#parentx" )[ 0 ], of: $( "#parentx" )[ 0 ],
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "DOM element" ); same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "DOM element" );
// these tests are not valid for "within" since of is not contained by within.
/*
$( "#elx" ).position({
my: "right bottom",
at: "right bottom",
of: document,
collision: "none",
within: $("#within-container")
});
same( $( "#elx" ).addOffsets(), {
top: addTop + $( document ).height() - 10,
left: addLeft + $( document ).width() - 10
}, "document" );
$( "#elx" ).position({
my: "right bottom",
at: "right bottom",
of: $( document ),
collision: "none",
within: $("#within-container")
});
same( $( "#elx" ).addOffsets(), {
top: addTop + $( document ).height() - 10,
left: addLeft + $( document ).width() - 10
}, "document as jQuery object" );
$( window ).scrollTop( 0 );
$( "#elx" ).position({
my: "right bottom",
at: "right bottom",
of: window,
collision: "none",
within: $("#within-container")
});
same( $( "#elx" ).addOffsets(), {
top: addTop + $( window ).height() - 10,
left: addLeft + $( window ).width() - 10
}, "window" );
$( "#elx" ).position({
my: "right bottom",
at: "right bottom",
of: $( window ),
collision: "none",
within: $("#within-container")
});
same( $( "#elx" ).addOffsets(), {
top: addTop + $( window ).height() - 10,
left: addLeft + $( window ).width() - 10
}, "window as jQuery object" );
if ( scrollTopSupport() ) {
$( window ).scrollTop( 500 ).scrollLeft( 200 );
$( "#elx" ).position({
my: "right bottom",
at: "right bottom",
of: window,
collision: "none",
within: $("#within-container")
});
same( $( "#elx" ).addOffsets(), {
top: addTop + $( window ).height() + 500 - 10,
left: addLeft + $( window ).width() + 200 - 10
}, "window, scrolled" );
$( window ).scrollTop( 0 ).scrollLeft( 0 );
}*/
var event = $.extend( $.Event( "someEvent" ), { pageX: 200, pageY: 300 } ); var event = $.extend( $.Event( "someEvent" ), { pageX: 200, pageY: 300 } );
$( "#elx" ).position({ $( "#elx" ).position({
my: "left top", my: "left top",
at: "left top", at: "left top",
of: event, of: event,
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).offset(), { same( $( "#elx" ).offset(), {
top: 300, top: 300,
@ -244,7 +168,7 @@ test( "within: of", function() {
at: "right bottom", at: "right bottom",
of: event, of: event,
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).offset(), { same( $( "#elx" ).offset(), {
top: 600, top: 600,
@ -253,16 +177,14 @@ test( "within: of", function() {
}); });
test( "within:offsets", function() { test( "within:offsets", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
$( "#elx" ).position({ $( "#elx" ).position({
my: "left top", my: "left top",
at: "left+10 bottom+10", at: "left+10 bottom+10",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 70, left: addLeft + 50 }, "offsets in at" ); same( $( "#elx" ).addOffsets(), { top: addTop + 70, left: addLeft + 50 }, "offsets in at" );
@ -271,7 +193,7 @@ test( "within:offsets", function() {
at: "left bottom", at: "left bottom",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 50, left: addLeft + 50 }, "offsets in my" ); same( $( "#elx" ).addOffsets(), { top: addTop + 50, left: addLeft + 50 }, "offsets in my" );
@ -280,7 +202,7 @@ test( "within:offsets", function() {
at: "left+50% bottom-10%", at: "left+50% bottom-10%",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 58, left: addLeft + 50 }, "percentage offsets in at" ); same( $( "#elx" ).addOffsets(), { top: addTop + 58, left: addLeft + 50 }, "percentage offsets in at" );
@ -289,18 +211,16 @@ test( "within:offsets", function() {
at: "left bottom", at: "left bottom",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}); });
same( $( "#elx" ).addOffsets(), { top: addTop + 65, left: addLeft + 37 }, "percentage offsets in my" ); same( $( "#elx" ).addOffsets(), { top: addTop + 65, left: addLeft + 37 }, "percentage offsets in my" );
}); });
test( "within: using", function() { test( "using", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"});
expect( 6 ); expect( 6 );
var within = $("#within-container");
var count = 0, var count = 0,
elems = $( "#el1, #el2" ), elems = $( "#el1, #el2" ),
expectedPosition = { top: addTop + 40, left: addLeft + 40 }, expectedPosition = { top: addTop + 40, left: addLeft + 40 },
@ -309,7 +229,7 @@ test( "within: using", function() {
at: "rigt bottom", at: "rigt bottom",
of: "#parentx", of: "#parentx",
collision: "none", collision: "none",
within: $("#within-container") within: within
}).addOffsets(); }).addOffsets();
elems.position({ elems.position({
@ -317,13 +237,13 @@ test( "within: using", function() {
at: "left top", at: "left top",
of: "#parentx", of: "#parentx",
using: function( position ) { using: function( position ) {
position.top -= $("#within-container").offset().top; position.top -= within.offset().top;
position.left -= $("#within-container").offset().left; position.left -= within.offset().left;
same( this, elems[ count ], "correct context for call #" + count ); same( this, elems[ count ], "correct context for call #" + count );
same( position, expectedPosition, "correct position for call #" + count ); same( position, expectedPosition, "correct position for call #" + count );
count++; count++;
}, },
within: $("#within-container") within: within
}); });
elems.each(function() { elems.each(function() {
@ -332,12 +252,15 @@ test( "within: using", function() {
}); });
function collisionTest( config, result, msg ) { function collisionTest( config, result, msg ) {
var within = $("#within-container");
var elem = $( "#elx" ).position( $.extend({ var elem = $( "#elx" ).position( $.extend({
my: "left top", my: "left top",
at: "right bottom", at: "right bottom",
of: $("#within-container")[0], of: within[0],
within: $("#within-container") within: within
}, config ) ); }, config ) );
same( elem.addOffsets(), result, msg ); same( elem.addOffsets(), result, msg );
} }
@ -348,14 +271,12 @@ function collisionTest2( config, result, msg ) {
}, config ), result, msg ); }, config ), result, msg );
} }
test( "within: collision: fit, no offset", function() { test( "collision: fit, no offset", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
collisionTest({ collisionTest({
collision: "fit" collision: "fit"
}, { top: addTop + $("#within-container").height() - 10, left: addLeft + $("#within-container").width() - 10 }, "right bottom" ); }, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "right bottom" );
collisionTest2({ collisionTest2({
collision: "fit" collision: "fit"
@ -363,15 +284,13 @@ test( "within: collision: fit, no offset", function() {
}); });
test( "within: collision: fit, with offset", function() { test( "collision: fit, with offset", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
collisionTest({ collisionTest({
collision: "fit", collision: "fit",
at: "right+2 bottom+3" at: "right+2 bottom+3"
}, { top: addTop + $("#within-container").height() - 10, left: addLeft + $("#within-container").width() - 10 }, "right bottom"); }, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "right bottom");
collisionTest2({ collisionTest2({
collision: "fit", collision: "fit",
@ -384,14 +303,10 @@ test( "within: collision: fit, with offset", function() {
}, { top: addTop + 0, left: addLeft + 0 }, "left top, negative offset" ); }, { top: addTop + 0, left: addLeft + 0 }, "left top, negative offset" );
}); });
test( "within: collision: fit, within scrolled", function() { test( "collision: fit, within scrolled", function() {
if ( scrollTopSupport() ) { if ( scrollTopSupport() ) {
$("#within-container").css({"width": "1000px", "height": "800px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container").css({"width": "1000px", "height": "800px", "overflow": "auto"});
within.scrollTop( 300 ).scrollLeft( 150 );
var win = $("#within-container").css("overflow", "auto");
win.scrollTop( 300 ).scrollLeft( 150 );
collisionTest({ collisionTest({
collision: "fit", collision: "fit",
@ -400,15 +315,13 @@ test( "within: collision: fit, within scrolled", function() {
collisionTest2({ collisionTest2({
collision: "fit", collision: "fit",
at: "right+100 bottom+100" at: "right+100 bottom+100"
}, { top: addTop + win.height() - 10, left: addLeft + win.width() - 10 }, "right bottom" ); }, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "right bottom" );
win.scrollTop( 0 ).scrollLeft( 0 ); within.scrollTop( 0 ).scrollLeft( 0 );
} }
}); });
test( "within: collision: flip, no offset", function() { test( "collision: flip, no offset", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
collisionTest({ collisionTest({
collision: "flip" collision: "flip"
@ -416,13 +329,11 @@ test( "within: collision: flip, no offset", function() {
collisionTest2({ collisionTest2({
collision: "flip" collision: "flip"
}, { top: addTop + $("#within-container").height(), left: addLeft + $("#within-container").width() }, "right bottom" ); }, { top: addTop + within.height(), left: addLeft + within.width() }, "right bottom" );
}); });
test( "within: collision: flip, with offset", function() { test( "collision: flip, with offset", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
collisionTest({ collisionTest({
collision: "flip", collision: "flip",
@ -432,37 +343,33 @@ test( "within: collision: flip, with offset", function() {
collisionTest2({ collisionTest2({
collision: "flip", collision: "flip",
at: "left+2 top+3" at: "left+2 top+3"
}, { top: addTop + $("#within-container").height() - 3, left: addLeft + $("#within-container").width() - 2 }, "bottom, positive offset" ); }, { top: addTop + within.height() - 3, left: addLeft + within.width() - 2 }, "bottom, positive offset" );
collisionTest2({ collisionTest2({
collision: "flip", collision: "flip",
at: "left-2 top-3" at: "left-2 top-3"
}, { top: addTop + $("#within-container").height() + 3, left: addLeft + $("#within-container").width() + 2 }, "right bottom, negative offset" ); }, { top: addTop + within.height() + 3, left: addLeft + within.width() + 2 }, "right bottom, negative offset" );
}); });
test( "within: collision: none, no offset", function() { test( "collision: none, no offset", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
collisionTest({ collisionTest({
collision: "none" collision: "none"
}, { top: addTop + $("#within-container").height(), left: addLeft + $("#within-container").width() }, "left top" ); }, { top: addTop + within.height(), left: addLeft + within.width() }, "left top" );
collisionTest2({ collisionTest2({
collision: "none" collision: "none"
}, { top: addTop + -10, left: addLeft + -10 }, "moved to the right bottom" ); }, { top: addTop + -10, left: addLeft + -10 }, "moved to the right bottom" );
}); });
test( "within: collision: none, with offset", function() { test( "collision: none, with offset", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
collisionTest({ collisionTest({
collision: "none", collision: "none",
at: "right+2 bottom+3" at: "right+2 bottom+3"
}, { top: addTop + $("#within-container").height() + 3, left: addLeft + $("#within-container").width() + 2 }, "right bottom, with offset added" ); }, { top: addTop + within.height() + 3, left: addLeft + within.width() + 2 }, "right bottom, with offset added" );
collisionTest2({ collisionTest2({
collision: "none", collision: "none",
@ -475,16 +382,14 @@ test( "within: collision: none, with offset", function() {
}, { top: addTop + -13, left: addLeft + -12 }, "left top, negative offset" ); }, { top: addTop + -13, left: addLeft + -12 }, "left top, negative offset" );
}); });
test( "within: collision: fit, with margin", function() { test( "collision: fit, with margin", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
$( "#elx" ).css( "margin", 10 ); $( "#elx" ).css( "margin", 10 );
collisionTest({ collisionTest({
collision: "fit" collision: "fit"
}, { top: addTop + $("#within-container").height() - 20, left: addLeft + $("#within-container").width() - 20 }, "right bottom" ); }, { top: addTop + within.height() - 20, left: addLeft + within.width() - 20 }, "right bottom" );
collisionTest2({ collisionTest2({
collision: "fit" collision: "fit"
@ -497,7 +402,7 @@ test( "within: collision: fit, with margin", function() {
collisionTest({ collisionTest({
collision: "fit" collision: "fit"
}, { top: addTop + $("#within-container").height() - 20, left: addLeft + $("#within-container").width() - 20 }, "right bottom" ); }, { top: addTop + within.height() - 20, left: addLeft + within.width() - 20 }, "right bottom" );
collisionTest2({ collisionTest2({
collision: "fit" collision: "fit"
@ -510,24 +415,22 @@ test( "within: collision: fit, with margin", function() {
collisionTest({ collisionTest({
collision: "fit" collision: "fit"
}, { top: addTop + $("#within-container").height() - 25, left: addLeft + $("#within-container").width() - 25 }, "right bottom" ); }, { top: addTop + within.height() - 25, left: addLeft + within.width() - 25 }, "right bottom" );
collisionTest2({ collisionTest2({
collision: "fit" collision: "fit"
}, { top: addTop + 5, left: addLeft + 5 }, "left top" ); }, { top: addTop + 5, left: addLeft + 5 }, "left top" );
}); });
test( "within: collision: flip, with margin", function() { test( "collision: flip, with margin", function() {
$("#within-container").css({"width": "500px", "height": "500px", "top": "20px", "left": "20px", "position": "relative"}); var within = $("#within-container");
$( "#elx" ).css( "margin", 10 ); $( "#elx" ).css( "margin", 10 );
collisionTest({ collisionTest({
collision: "flip", collision: "flip",
at: "left top" at: "left top"
}, { top: addTop + $("#within-container").height() - 10, left: addLeft + $("#within-container").width() - 10 }, "left top" ); }, { top: addTop + within.height() - 10, left: addLeft + within.width() - 10 }, "left top" );
collisionTest2({ collisionTest2({
collision: "flip", collision: "flip",
@ -535,22 +438,4 @@ test( "within: collision: flip, with margin", function() {
}, { top: addTop + 0, left: addLeft + 0 }, "right bottom" ); }, { top: addTop + 0, left: addLeft + 0 }, "right bottom" );
}); });
//test( "bug #5280: consistent results (avoid fractional values)", function() {
// var wrapper = $( "#bug-5280" ),
// elem = wrapper.children(),
// offset1 = elem.position({
// my: "center",
// at: "center",
// of: wrapper,
// collision: "none"
// }).offset(),
// offset2 = elem.position({
// my: "center",
// at: "center",
// of: wrapper,
// collision: "none"
// }).offset();
// same( offset1, offset2 );
//});
}( jQuery ) ); }( jQuery ) );

View File

@ -191,20 +191,18 @@ $.ui.position = {
withinOffset = isWindow ? win.scrollLeft() : within.offset().left, withinOffset = isWindow ? win.scrollLeft() : within.offset().left,
outerWidth = isWindow ? win.width() : within.outerWidth(), outerWidth = isWindow ? win.width() : within.outerWidth(),
overLeft = withinOffset - data.collisionPosition.left, overLeft = withinOffset - data.collisionPosition.left,
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - withinOffset, overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - withinOffset;
newLeft;
// element is wider than window or too far left -> align with left edge // element is wider than window or too far left -> align with left edge
if ( data.collisionWidth > outerWidth || overLeft > 0 ) { if ( data.collisionWidth > outerWidth || overLeft > 0 ) {
newLeft = position.left + overLeft; position.left += overLeft;
// too far right -> align with right edge // too far right -> align with right edge
} else if ( overRight > 0 ) { } else if ( overRight > 0 ) {
newLeft = position.left - overRight; position.left -= overRight;
// adjust based on position and margin // adjust based on position and margin
} else { } else {
newLeft = Math.max( position.left - data.collisionPosition.left, position.left ); position.left = Math.max( position.left - data.collisionPosition.left, position.left );
} }
position.left = newLeft;
}, },
top: function( position, data ) { top: function( position, data ) {
var within = data.within, var within = data.within,
@ -213,20 +211,18 @@ $.ui.position = {
withinOffset = isWindow ? win.scrollTop() : within.offset().top, withinOffset = isWindow ? win.scrollTop() : within.offset().top,
outerHeight = isWindow ? win.height() : within.outerHeight(), outerHeight = isWindow ? win.height() : within.outerHeight(),
overTop = withinOffset - data.collisionPosition.top, overTop = withinOffset - data.collisionPosition.top,
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - withinOffset, overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - withinOffset;
newTop;
// element is taller than window or too far up -> align with top edge // element is taller than window or too far up -> align with top edge
if ( data.collisionHeight > outerHeight || overTop > 0 ) { if ( data.collisionHeight > outerHeight || overTop > 0 ) {
newTop = position.top + overTop; position.top += overTop;
// too far down -> align with bottom edge // too far down -> align with bottom edge
} else if ( overBottom > 0 ) { } else if ( overBottom > 0 ) {
newTop = position.top - overBottom; position.top -= overBottom;
// adjust based on position and margin // adjust based on position and margin
} else { } else {
newTop = Math.max( position.top - data.collisionPosition.top, position.top ); position.top = Math.max( position.top - data.collisionPosition.top, position.top );
} }
position.top = newTop;
} }
}, },
flip: { flip: {