diff options
author | Ben Hollis <ben@benhollis.net> | 2010-09-03 10:38:44 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2010-09-03 10:38:44 -0400 |
commit | 4b9d5d1b5bd36726c6e49b105c0f75649cca1ae4 (patch) | |
tree | a03bc490cc46c0c1bacddd9d2afd140dcdaf4a8f /ui/jquery.ui.position.js | |
parent | 0a0a39f896f83412dc91bedd6819c3a3a0932302 (diff) | |
download | jquery-ui-4b9d5d1b5bd36726c6e49b105c0f75649cca1ae4.tar.gz jquery-ui-4b9d5d1b5bd36726c6e49b105c0f75649cca1ae4.zip |
Position: Take margin into account when performing collisions. Fixes #5766 - position: collision should take margin into account.
Diffstat (limited to 'ui/jquery.ui.position.js')
-rw-r--r-- | ui/jquery.ui.position.js | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index a14c5c612..aa9881cff 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -99,7 +99,14 @@ $.fn.position = function( options ) { var elem = $( this ), elemWidth = elem.outerWidth(), elemHeight = elem.outerHeight(), - position = $.extend( {}, basePosition ); + marginLeft = parseInt( $.curCSS( this, "marginLeft", true ) ) || 0, + marginTop = parseInt( $.curCSS( this, "marginTop", true ) ) || 0, + collisionWidth = elemWidth + marginLeft + + parseInt( $.curCSS( this, "marginRight", true ) ) || 0, + collisionHeight = elemHeight + marginTop + + parseInt( $.curCSS( this, "marginBottom", true ) ) || 0, + position = $.extend( {}, basePosition ), + collisionPosition; if ( options.my[0] === "right" ) { position.left -= elemWidth; @@ -117,6 +124,11 @@ $.fn.position = function( options ) { position.left = parseInt( position.left ); position.top = parseInt( position.top ); + collisionPosition = { + left: position.left - marginLeft, + top: position.top - marginTop + }; + $.each( [ "left", "top" ], function( i, dir ) { if ( $.ui.position[ collision[i] ] ) { $.ui.position[ collision[i] ][ dir ]( position, { @@ -124,6 +136,9 @@ $.fn.position = function( options ) { targetHeight: targetHeight, elemWidth: elemWidth, elemHeight: elemHeight, + collisionPosition: collisionPosition, + collisionWidth: collisionWidth, + collisionHeight: collisionHeight, offset: offset, my: options.my, at: options.at @@ -142,13 +157,13 @@ $.ui.position = { fit: { left: function( position, data ) { var win = $( window ), - over = position.left + data.elemWidth - win.width() - win.scrollLeft(); - position.left = over > 0 ? position.left - over : Math.max( 0, position.left ); + 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 ); }, top: function( position, data ) { var win = $( window ), - over = position.top + data.elemHeight - win.height() - win.scrollTop(); - position.top = over > 0 ? position.top - over : Math.max( 0, position.top ); + 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 ); } }, @@ -158,7 +173,7 @@ $.ui.position = { return; } var win = $( window ), - over = position.left + data.elemWidth - win.width() - win.scrollLeft(), + over = data.collisionPosition.left + data.collisionWidth - win.width() - win.scrollLeft(), myOffset = data.my[ 0 ] === "left" ? -data.elemWidth : data.my[ 0 ] === "right" ? @@ -168,7 +183,7 @@ $.ui.position = { data.targetWidth : -data.targetWidth, offset = -2 * data.offset[ 0 ]; - position.left += position.left < 0 ? + position.left += data.collisionPosition.left < 0 ? myOffset + atOffset + offset : over > 0 ? myOffset + atOffset + offset : @@ -179,7 +194,7 @@ $.ui.position = { return; } var win = $( window ), - over = position.top + data.elemHeight - win.height() - win.scrollTop(), + over = data.collisionPosition.top + data.collisionHeight - win.height() - win.scrollTop(), myOffset = data.my[ 1 ] === "top" ? -data.elemHeight : data.my[ 1 ] === "bottom" ? @@ -189,7 +204,7 @@ $.ui.position = { data.targetHeight : -data.targetHeight, offset = -2 * data.offset[ 1 ]; - position.top += position.top < 0 ? + position.top += data.collisionPosition.top < 0 ? myOffset + atOffset + offset : over > 0 ? myOffset + atOffset + offset : |