Position: Finish refactoring of within data

This commit is contained in:
Jörn Zaefferer 2012-04-13 14:46:43 +02:00
parent 59b93a7dac
commit c0a5e52f87

View File

@ -72,11 +72,12 @@ $.fn.position = function( options ) {
var target = $( options.of ), var target = $( options.of ),
withinElement = $( options.within || window ), withinElement = $( options.within || window ),
isWindow = $.isWindow( withinElement[0] ), isWindow = $.isWindow( withinElement[0] ),
withinOffset = withinElement.offset(),
within = { within = {
element: withinElement, element: withinElement,
left: isWindow ? withinElement.scrollLeft() : withinOffset.left, isWindow: isWindow,
top: isWindow ? withinElement.scrollTop() : withinOffset.top, offset: withinElement.offset(),
scrollLeft: withinElement.scrollLeft(),
scrollTop: withinElement.scrollTop(),
width: isWindow ? withinElement.width() : withinElement.outerWidth(), width: isWindow ? withinElement.width() : withinElement.outerWidth(),
height: isWindow ? withinElement.height() : withinElement.outerHeight() height: isWindow ? withinElement.height() : withinElement.outerHeight()
}, },
@ -262,8 +263,9 @@ $.fn.position = function( options ) {
$.ui.position = { $.ui.position = {
fit: { fit: {
left: function( position, data ) { left: function( position, data ) {
var withinOffset = data.within.left, var within = data.within,
outerWidth = data.within.width, withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
outerWidth = within.width,
collisionPosLeft = position.left - data.collisionPosition.marginLeft, collisionPosLeft = position.left - data.collisionPosition.marginLeft,
overLeft = withinOffset - collisionPosLeft, overLeft = withinOffset - collisionPosLeft,
overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset, overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
@ -299,7 +301,8 @@ $.ui.position = {
} }
}, },
top: function( position, data ) { top: function( position, data ) {
var withinOffset = data.within.top, var within = data.within,
withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
outerHeight = data.within.height, outerHeight = data.within.height,
collisionPosTop = position.top - data.collisionPosition.marginTop, collisionPosTop = position.top - data.collisionPosition.marginTop,
overTop = withinOffset - collisionPosTop, overTop = withinOffset - collisionPosTop,
@ -342,12 +345,10 @@ $.ui.position = {
return; return;
} }
// TODO refactor the offset/scrollLeft calls var within = data.within,
var within = data.within.element, withinOffset = ( within.isWindow ? 0 : within.offset.left ) + within.scrollLeft,
isWindow = $.isWindow( within[0] ), outerWidth = within.width,
withinOffset = ( isWindow ? 0 : within.offset().left ) + within.scrollLeft(), offsetLeft = within.isWindow ? 0 : within.offset.left,
outerWidth = data.within.width,
offsetLeft = isWindow ? 0 : within.offset().left,
collisionPosLeft = position.left - data.collisionPosition.marginLeft, collisionPosLeft = position.left - data.collisionPosition.marginLeft,
overLeft = collisionPosLeft - offsetLeft, overLeft = collisionPosLeft - offsetLeft,
overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft, overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
@ -382,12 +383,10 @@ $.ui.position = {
return; return;
} }
// TODO refactor the offset/scrollLeft calls var within = data.within,
var within = data.within.element, withinOffset = ( within.isWindow ? 0 : within.offset.top ) + within.scrollTop,
isWindow = $.isWindow( within[0] ), outerHeight = within.height,
withinOffset = ( isWindow ? 0 : within.offset().top ) + within.scrollTop(), offsetTop = within.isWindow ? 0 : within.offset.top,
outerHeight = data.within.height,
offsetTop = isWindow ? 0 : within.offset().top,
collisionPosTop = position.top - data.collisionPosition.marginTop, collisionPosTop = position.top - data.collisionPosition.marginTop,
overTop = collisionPosTop - offsetTop, overTop = collisionPosTop - offsetTop,
overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop, overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,