Fix issue when window is "within".

This commit is contained in:
David Murdoch 2011-05-11 16:44:20 -07:00
parent c6afaa1072
commit abf3a86c8b

View File

@ -37,8 +37,6 @@ $.fn.position = function( options ) {
targetHeight, targetHeight,
basePosition; basePosition;
options.within = within;
if ( targetElem.nodeType === 9 ) { if ( targetElem.nodeType === 9 ) {
targetWidth = target.width(); targetWidth = target.width();
targetHeight = target.height(); targetHeight = target.height();
@ -187,11 +185,12 @@ $.fn.position = function( options ) {
$.ui.position = { $.ui.position = {
fit: { fit: {
left: function( position, data ) { left: function( position, data ) {
var win = $( data.within ), var win = data.within,
winOffset = win.offset(), isWindow = $.isWindow(data.within[0]),
outerWidth = win.outerWidth(), winOffset = isWindow ? 0 : win.offset().left,
overLeft = win.scrollLeft() - data.collisionPosition.left + winOffset.left, outerWidth = isWindow ? win.width() : win.outerWidth(),
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - win.scrollLeft() - winOffset.left; overLeft = win.scrollLeft() - data.collisionPosition.left + winOffset,
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - win.scrollLeft() - winOffset;
// 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 ) {
@ -205,11 +204,12 @@ $.ui.position = {
} }
}, },
top: function( position, data ) { top: function( position, data ) {
var win = $( data.within ), var win = data.within,
winOffset = win.offset(), isWindow = $.isWindow(data.within[0]),
outerHeight = win.outerHeight(), winOffset = isWindow ? 0 : win.offset().top,
overTop = win.scrollTop() - data.collisionPosition.top + winOffset.top, outerHeight = isWindow ? win.height() : win.outerHeight(),
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - win.scrollTop() - winOffset.top; overTop = win.scrollTop() - data.collisionPosition.top + winOffset,
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - win.scrollTop() - winOffset;
// 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 ) {
@ -228,11 +228,12 @@ $.ui.position = {
if ( data.at[ 0 ] === center ) { if ( data.at[ 0 ] === center ) {
return; return;
} }
var win = $( data.within ), var win = data.within,
winOffset = win.offset(), isWindow = $.isWindow(data.within[0]),
outerWidth = win.outerWidth(), winOffset = isWindow ? 0 : win.offset().left,
overLeft = data.collisionPosition.left - winOffset.left, outerWidth = isWindow ? win.width() : win.outerWidth(),
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - win.scrollLeft() - winOffset.left, overLeft = data.collisionPosition.left - winOffset,
overRight = data.collisionPosition.left + data.collisionWidth - outerWidth - win.scrollLeft() - winOffset
left = data.my[ 0 ] === "left", left = data.my[ 0 ] === "left",
myOffset = data.my[ 0 ] === "left" ? myOffset = data.my[ 0 ] === "left" ?
-data.elemWidth : -data.elemWidth :
@ -251,11 +252,12 @@ $.ui.position = {
if ( data.at[ 1 ] === center ) { if ( data.at[ 1 ] === center ) {
return; return;
} }
var win = $( data.within ), var win = data.within,
winOffset = win.offset(), isWindow = $.isWindow(data.within[0]),
outerHeight = win.outerHeight(), winOffset = isWindow ? 0 : win.offset().top,
overTop = data.collisionPosition.top - winOffset.top, outerHeight = isWindow ? win.height() : win.outerHeight(),
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - win.scrollTop() - winOffset.top, overTop = data.collisionPosition.top - winOffset,
overBottom = data.collisionPosition.top + data.collisionHeight - outerHeight - win.scrollTop() - winOffset,
top = data.my[ 1 ] === "top", top = data.my[ 1 ] === "top",
myOffset = top ? myOffset = top ?
-data.elemHeight : -data.elemHeight :