aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.position.js
diff options
context:
space:
mode:
authorJean-Francois Remy <jfremy@virtuoz.com>2011-05-03 04:38:17 -0400
committerScott González <scott.gonzalez@gmail.com>2011-05-03 04:38:17 -0400
commit5e44b3ce8851f62a38ce9211c6721e1050e2dabf (patch)
tree8e87f743e6a498e0fc50a8c396a504f409eb7efe /ui/jquery.ui.position.js
parent51df02ee4ea02e91919842a169463612176682d5 (diff)
downloadjquery-ui-5e44b3ce8851f62a38ce9211c6721e1050e2dabf.tar.gz
jquery-ui-5e44b3ce8851f62a38ce9211c6721e1050e2dabf.zip
Position: Handled scrolled windows properly with collision: fit. Fixes #7211 - Position: Collision: fit doesn't work at top of window when scrolled.
Diffstat (limited to 'ui/jquery.ui.position.js')
-rw-r--r--ui/jquery.ui.position.js35
1 files changed, 26 insertions, 9 deletions
diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js
index b6fcc7151..98b8198e2 100644
--- a/ui/jquery.ui.position.js
+++ b/ui/jquery.ui.position.js
@@ -184,20 +184,37 @@ $.ui.position = {
fit: {
left: function( position, data ) {
var win = $( window ),
- over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft();
- position.left = over > 0 ?
- position.left - over :
- Math.max( position.left - data.collisionPosition.left, position.left );
+ overLeft = win.scrollLeft() - data.collisionPosition.left,
+ overRight = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft();
+
+ // element is wider than window or too far left -> align with left edge
+ if ( data.collisionWidth > win.width() || overLeft > 0 ) {
+ position.left = position.left + overLeft;
+ // too far right -> align with right edge
+ } else if ( overRight > 0 ) {
+ position.left = position.left - overRight;
+ // adjust based on position and margin
+ } else {
+ position.left = Math.max( position.left - data.collisionPosition.left, position.left );
+ }
},
top: function( position, data ) {
var win = $( window ),
- over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop();
- position.top = over > 0 ?
- position.top - over :
- Math.max( position.top - data.collisionPosition.top, position.top );
+ overTop = win.scrollTop() - data.collisionPosition.top,
+ overBottom = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop();
+
+ // element is taller than window or too far up -> align with top edge
+ if ( data.collisionHeight > win.height() || overTop > 0 ) {
+ position.top = position.top + overTop;
+ // too far down -> align with bottom edge
+ } else if ( overBottom > 0 ) {
+ position.top = position.top - overBottom;
+ // adjust based on position and margin
+ } else {
+ position.top = Math.max( position.top - data.collisionPosition.top, position.top );
+ }
}
},
-
flip: {
left: function( position, data ) {
if ( data.at[ 0 ] === center ) {