diff options
Diffstat (limited to 'resources/jquery.ui/jquery.ui.position.js')
-rw-r--r-- | resources/jquery.ui/jquery.ui.position.js | 89 |
1 files changed, 54 insertions, 35 deletions
diff --git a/resources/jquery.ui/jquery.ui.position.js b/resources/jquery.ui/jquery.ui.position.js index 50dd57f0..b66e59ef 100644 --- a/resources/jquery.ui/jquery.ui.position.js +++ b/resources/jquery.ui/jquery.ui.position.js @@ -1,20 +1,19 @@ /* - * jQuery UI Position 1.8.2 + * jQuery UI Position 1.8.11 * - * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about) - * Dual licensed under the MIT (MIT-LICENSE.txt) - * and GPL (GPL-LICENSE.txt) licenses. + * Copyright 2011, AUTHORS.txt (http://jqueryui.com/about) + * Dual licensed under the MIT or GPL Version 2 licenses. + * http://jquery.org/license * * http://docs.jquery.com/UI/Position */ -(function( $ ) { +(function( $, undefined ) { $.ui = $.ui || {}; var horizontalPositions = /left|center|right/, - horizontalDefault = "center", verticalPositions = /top|center|bottom/, - verticalDefault = "center", + center = "center", _position = $.fn.position, _offset = $.fn.offset; @@ -27,21 +26,23 @@ $.fn.position = function( options ) { options = $.extend( {}, options ); var target = $( options.of ), + targetElem = target[0], collision = ( options.collision || "flip" ).split( " " ), offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ], targetWidth, targetHeight, basePosition; - if ( options.of.nodeType === 9 ) { + if ( targetElem.nodeType === 9 ) { targetWidth = target.width(); targetHeight = target.height(); basePosition = { top: 0, left: 0 }; - } else if ( options.of.scrollTo && options.of.document ) { + // TODO: use $.isWindow() in 1.9 + } else if ( targetElem.setTimeout ) { targetWidth = target.width(); targetHeight = target.height(); basePosition = { top: target.scrollTop(), left: target.scrollLeft() }; - } else if ( options.of.preventDefault ) { + } else if ( targetElem.preventDefault ) { // force left top to allow flipping options.at = "left top"; targetWidth = targetHeight = 0; @@ -58,13 +59,13 @@ $.fn.position = function( options ) { var pos = ( options[this] || "" ).split( " " ); if ( pos.length === 1) { pos = horizontalPositions.test( pos[0] ) ? - pos.concat( [verticalDefault] ) : + pos.concat( [center] ) : verticalPositions.test( pos[0] ) ? - [ horizontalDefault ].concat( pos ) : - [ horizontalDefault, verticalDefault ]; + [ center ].concat( pos ) : + [ center, center ]; } - pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : horizontalDefault; - pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : verticalDefault; + pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : center; + pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : center; options[ this ] = pos; }); @@ -82,13 +83,13 @@ $.fn.position = function( options ) { if ( options.at[0] === "right" ) { basePosition.left += targetWidth; - } else if (options.at[0] === horizontalDefault ) { + } else if ( options.at[0] === center ) { basePosition.left += targetWidth / 2; } if ( options.at[1] === "bottom" ) { basePosition.top += targetHeight; - } else if ( options.at[1] === verticalDefault ) { + } else if ( options.at[1] === center ) { basePosition.top += targetHeight / 2; } @@ -99,23 +100,35 @@ $.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; - } else if ( options.my[0] === horizontalDefault ) { + } else if ( options.my[0] === center ) { position.left -= elemWidth / 2; } if ( options.my[1] === "bottom" ) { position.top -= elemHeight; - } else if ( options.my[1] === verticalDefault ) { + } else if ( options.my[1] === center ) { position.top -= elemHeight / 2; } // prevent fractions (see #5280) - position.left = parseInt( position.left ); - position.top = parseInt( position.top ); + position.left = Math.round( position.left ); + position.top = Math.round( position.top ); + + collisionPosition = { + left: position.left - marginLeft, + top: position.top - marginTop + }; $.each( [ "left", "top" ], function( i, dir ) { if ( $.ui.position[ collision[i] ] ) { @@ -124,6 +137,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,41 +158,44 @@ $.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 ); } }, flip: { left: function( position, data ) { - if ( data.at[0] === "center" ) { + if ( data.at[0] === center ) { 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" ? data.elemWidth : 0, + atOffset = data.at[ 0 ] === "left" ? + data.targetWidth : + -data.targetWidth, offset = -2 * data.offset[ 0 ]; - position.left += position.left < 0 ? - myOffset + data.targetWidth + offset : + position.left += data.collisionPosition.left < 0 ? + myOffset + atOffset + offset : over > 0 ? - myOffset - data.targetWidth + offset : + myOffset + atOffset + offset : 0; }, top: function( position, data ) { - if ( data.at[1] === "center" ) { + if ( data.at[1] === center ) { 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" ? @@ -186,8 +205,8 @@ $.ui.position = { data.targetHeight : -data.targetHeight, offset = -2 * data.offset[ 1 ]; - position.top += position.top < 0 ? - myOffset + data.targetHeight + offset : + position.top += data.collisionPosition.top < 0 ? + myOffset + atOffset + offset : over > 0 ? myOffset + atOffset + offset : 0; |