Skip to content

Commit e7701e2

Browse files
committed
Position: Fixed issue with offsets using the within option which caused flips to not happen when the containing element had been scrolled.
1 parent a505192 commit e7701e2

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ui/jquery.ui.position.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,10 @@ $.ui.position = {
317317
isWindow = $.isWindow( data.within[0] ),
318318
withinOffset = ( isWindow ? 0 : within.offset().left ) + within.scrollLeft(),
319319
outerWidth = isWindow ? within.width() : within.outerWidth(),
320+
offsetLeft = isWindow ? 0 : within.offset().left,
320321
collisionPosLeft = position.left - data.collisionPosition.marginLeft,
321-
overLeft = collisionPosLeft - withinOffset,
322-
overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
322+
overLeft = collisionPosLeft - offsetLeft,
323+
overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
323324
left = data.my[ 0 ] === "left",
324325
myOffset = data.my[ 0 ] === "left" ?
325326
-data.elemWidth :
@@ -343,7 +344,7 @@ $.ui.position = {
343344
}
344345
}
345346
else if ( overRight > 0 ) {
346-
newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - withinOffset;
347+
newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
347348
if ( newOverLeft > 0 || Math.abs( newOverLeft ) < overRight ) {
348349
data.elem
349350
.addClass( "ui-flipped-left" );
@@ -365,9 +366,10 @@ $.ui.position = {
365366
isWindow = $.isWindow( data.within[0] ),
366367
withinOffset = ( isWindow ? 0 : within.offset().top ) + within.scrollTop(),
367368
outerHeight = isWindow ? within.height() : within.outerHeight(),
369+
offsetTop = isWindow ? 0 : within.offset().top,
368370
collisionPosTop = position.top - data.collisionPosition.marginTop,
369-
overTop = collisionPosTop - withinOffset,
370-
overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
371+
overTop = collisionPosTop - offsetTop,
372+
overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
371373
top = data.my[ 1 ] === "top",
372374
myOffset = top ?
373375
-data.elemHeight :
@@ -390,7 +392,7 @@ $.ui.position = {
390392
}
391393
}
392394
else if ( overBottom > 0 ) {
393-
newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - withinOffset;
395+
newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
394396
if ( ( position.top + myOffset + atOffset + offset) > overBottom && ( newOverTop > 0 || Math.abs( newOverTop ) < overBottom ) ) {
395397
data.elem
396398
.addClass( "ui-flipped-top" );

0 commit comments

Comments
 (0)