2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2010-01-07 03:19:50 +00:00
|
|
|
* jQuery UI Position @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2010-01-07 03:19:50 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2010-01-07 03:19:50 +00:00
|
|
|
*
|
2012-09-26 23:06:20 +00:00
|
|
|
* http://api.jqueryui.com/position/
|
2010-01-07 03:19:50 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Position
|
|
|
|
//>>group: UI Core
|
|
|
|
//>>description: Positions elements relative to other elements.
|
|
|
|
//>>docs: http://api.jqueryui.com/position/
|
|
|
|
//>>demos: http://jqueryui.com/position/
|
|
|
|
|
2015-03-14 11:33:03 +00:00
|
|
|
( function( factory ) {
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define( [ "jquery" ], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2015-03-14 11:33:03 +00:00
|
|
|
}( function( $ ) {
|
|
|
|
( function() {
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
$.ui = $.ui || {};
|
|
|
|
|
2014-04-03 14:54:52 +00:00
|
|
|
var cachedScrollbarWidth, supportsOffsetFractions,
|
2012-04-20 12:09:17 +00:00
|
|
|
max = Math.max,
|
|
|
|
abs = Math.abs,
|
2012-04-20 12:15:57 +00:00
|
|
|
round = Math.round,
|
2012-04-20 12:09:17 +00:00
|
|
|
rhorizontal = /left|center|right/,
|
2011-03-22 17:12:03 +00:00
|
|
|
rvertical = /top|center|bottom/,
|
2013-02-12 02:04:28 +00:00
|
|
|
roffset = /[\+\-]\d+(\.[\d]+)?%?/,
|
2011-03-22 16:25:25 +00:00
|
|
|
rposition = /^\w+/,
|
|
|
|
rpercent = /%$/,
|
2012-04-20 12:09:17 +00:00
|
|
|
_position = $.fn.position;
|
2011-05-26 14:22:12 +00:00
|
|
|
|
2015-03-18 14:05:36 +00:00
|
|
|
// Support: IE <=9 only
|
|
|
|
supportsOffsetFractions = function() {
|
|
|
|
var element = $( "<div>" )
|
|
|
|
.css( "position", "absolute" )
|
|
|
|
.appendTo( "body" )
|
|
|
|
.offset( {
|
|
|
|
top: 1.5,
|
|
|
|
left: 1.5
|
|
|
|
} ),
|
|
|
|
support = element.offset().top === 1.5;
|
|
|
|
|
|
|
|
element.remove();
|
|
|
|
|
|
|
|
supportsOffsetFractions = function() {
|
|
|
|
return support;
|
|
|
|
};
|
|
|
|
|
|
|
|
return support;
|
|
|
|
};
|
|
|
|
|
2012-04-17 22:30:47 +00:00
|
|
|
function getOffsets( offsets, width, height ) {
|
|
|
|
return [
|
2013-02-12 02:04:28 +00:00
|
|
|
parseFloat( offsets[ 0 ] ) * ( rpercent.test( offsets[ 0 ] ) ? width / 100 : 1 ),
|
|
|
|
parseFloat( offsets[ 1 ] ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
|
2012-04-17 22:30:47 +00:00
|
|
|
];
|
|
|
|
}
|
2012-12-06 20:00:42 +00:00
|
|
|
|
2012-04-17 22:30:47 +00:00
|
|
|
function parseCss( element, property ) {
|
|
|
|
return parseInt( $.css( element, property ), 10 ) || 0;
|
|
|
|
}
|
|
|
|
|
2012-12-06 20:00:42 +00:00
|
|
|
function getDimensions( elem ) {
|
2015-03-14 11:33:03 +00:00
|
|
|
var raw = elem[ 0 ];
|
2012-12-06 20:00:42 +00:00
|
|
|
if ( raw.nodeType === 9 ) {
|
|
|
|
return {
|
|
|
|
width: elem.width(),
|
|
|
|
height: elem.height(),
|
|
|
|
offset: { top: 0, left: 0 }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if ( $.isWindow( raw ) ) {
|
|
|
|
return {
|
|
|
|
width: elem.width(),
|
|
|
|
height: elem.height(),
|
|
|
|
offset: { top: elem.scrollTop(), left: elem.scrollLeft() }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
if ( raw.preventDefault ) {
|
|
|
|
return {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
offset: { top: raw.pageY, left: raw.pageX }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
width: elem.outerWidth(),
|
|
|
|
height: elem.outerHeight(),
|
|
|
|
offset: elem.offset()
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:22:12 +00:00
|
|
|
$.position = {
|
2011-06-10 20:07:03 +00:00
|
|
|
scrollbarWidth: function() {
|
2012-04-13 13:12:37 +00:00
|
|
|
if ( cachedScrollbarWidth !== undefined ) {
|
|
|
|
return cachedScrollbarWidth;
|
|
|
|
}
|
2011-06-10 20:07:03 +00:00
|
|
|
var w1, w2,
|
2013-05-16 12:34:04 +00:00
|
|
|
div = $( "<div style='display:block;position:absolute;width:50px;height:50px;overflow:hidden;'><div style='height:100px;width:auto;'></div></div>" ),
|
2015-03-14 11:33:03 +00:00
|
|
|
innerDiv = div.children()[ 0 ];
|
2011-06-10 20:07:03 +00:00
|
|
|
|
|
|
|
$( "body" ).append( div );
|
|
|
|
w1 = innerDiv.offsetWidth;
|
|
|
|
div.css( "overflow", "scroll" );
|
|
|
|
|
|
|
|
w2 = innerDiv.offsetWidth;
|
|
|
|
|
2011-05-26 00:53:16 +00:00
|
|
|
if ( w1 === w2 ) {
|
2015-03-14 11:33:03 +00:00
|
|
|
w2 = div[ 0 ].clientWidth;
|
2011-05-26 00:53:16 +00:00
|
|
|
}
|
|
|
|
|
2011-06-10 20:07:03 +00:00
|
|
|
div.remove();
|
|
|
|
|
2015-03-14 11:33:03 +00:00
|
|
|
return ( cachedScrollbarWidth = w1 - w2 );
|
2011-05-26 00:53:16 +00:00
|
|
|
},
|
2012-04-13 13:05:43 +00:00
|
|
|
getScrollInfo: function( within ) {
|
2013-09-04 22:13:53 +00:00
|
|
|
var overflowX = within.isWindow || within.isDocument ? "" :
|
|
|
|
within.element.css( "overflow-x" ),
|
|
|
|
overflowY = within.isWindow || within.isDocument ? "" :
|
|
|
|
within.element.css( "overflow-y" ),
|
2012-04-24 15:23:25 +00:00
|
|
|
hasOverflowX = overflowX === "scroll" ||
|
2015-03-14 11:33:03 +00:00
|
|
|
( overflowX === "auto" && within.width < within.element[ 0 ].scrollWidth ),
|
2012-04-24 15:23:25 +00:00
|
|
|
hasOverflowY = overflowY === "scroll" ||
|
2015-03-14 11:33:03 +00:00
|
|
|
( overflowY === "auto" && within.height < within.element[ 0 ].scrollHeight );
|
2011-06-10 20:07:03 +00:00
|
|
|
return {
|
2013-02-26 13:59:28 +00:00
|
|
|
width: hasOverflowY ? $.position.scrollbarWidth() : 0,
|
|
|
|
height: hasOverflowX ? $.position.scrollbarWidth() : 0
|
2012-04-13 13:05:43 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getWithinInfo: function( element ) {
|
|
|
|
var withinElement = $( element || window ),
|
2015-03-14 11:33:03 +00:00
|
|
|
isWindow = $.isWindow( withinElement[ 0 ] ),
|
2015-06-17 15:33:06 +00:00
|
|
|
isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
|
|
|
|
hasOffset = !isWindow && !isDocument;
|
2012-04-13 13:05:43 +00:00
|
|
|
return {
|
|
|
|
element: withinElement,
|
|
|
|
isWindow: isWindow,
|
2013-09-04 22:13:53 +00:00
|
|
|
isDocument: isDocument,
|
2015-06-17 15:33:06 +00:00
|
|
|
offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
|
2012-04-13 13:05:43 +00:00
|
|
|
scrollLeft: withinElement.scrollLeft(),
|
|
|
|
scrollTop: withinElement.scrollTop(),
|
2015-01-12 16:19:46 +00:00
|
|
|
width: withinElement.outerWidth(),
|
|
|
|
height: withinElement.outerHeight()
|
2011-06-10 20:07:03 +00:00
|
|
|
};
|
2011-05-26 14:22:12 +00:00
|
|
|
}
|
|
|
|
};
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
$.fn.position = function( options ) {
|
|
|
|
if ( !options || !options.of ) {
|
|
|
|
return _position.apply( this, arguments );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2010-02-14 18:15:32 +00:00
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
// make a copy, we don't want to modify arguments
|
2010-02-14 18:15:32 +00:00
|
|
|
options = $.extend( {}, options );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-12-06 20:00:42 +00:00
|
|
|
var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
|
2012-04-18 14:43:25 +00:00
|
|
|
target = $( options.of ),
|
2012-04-13 13:05:43 +00:00
|
|
|
within = $.position.getWithinInfo( options.within ),
|
|
|
|
scrollInfo = $.position.getScrollInfo( within ),
|
2010-02-14 18:15:32 +00:00
|
|
|
collision = ( options.collision || "flip" ).split( " " ),
|
2012-04-18 14:43:25 +00:00
|
|
|
offsets = {};
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-12-06 20:00:42 +00:00
|
|
|
dimensions = getDimensions( target );
|
2015-03-14 11:33:03 +00:00
|
|
|
if ( target[ 0 ].preventDefault ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
// force left top to allow flipping
|
2010-02-14 18:15:32 +00:00
|
|
|
options.at = "left top";
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2012-12-06 20:00:42 +00:00
|
|
|
targetWidth = dimensions.width;
|
|
|
|
targetHeight = dimensions.height;
|
|
|
|
targetOffset = dimensions.offset;
|
2012-04-10 21:41:41 +00:00
|
|
|
// clone to reuse original targetOffset later
|
|
|
|
basePosition = $.extend( {}, targetOffset );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2011-03-21 18:02:00 +00:00
|
|
|
// force my and at to have valid horizontal and vertical positions
|
2011-06-10 20:07:03 +00:00
|
|
|
// if a value is missing or invalid, it will be converted to center
|
2010-02-14 18:15:32 +00:00
|
|
|
$.each( [ "my", "at" ], function() {
|
2011-03-22 17:12:03 +00:00
|
|
|
var pos = ( options[ this ] || "" ).split( " " ),
|
2011-03-22 16:25:25 +00:00
|
|
|
horizontalOffset,
|
|
|
|
verticalOffset;
|
|
|
|
|
2015-03-14 11:33:03 +00:00
|
|
|
if ( pos.length === 1 ) {
|
2011-03-22 17:12:03 +00:00
|
|
|
pos = rhorizontal.test( pos[ 0 ] ) ?
|
2012-04-12 15:48:01 +00:00
|
|
|
pos.concat( [ "center" ] ) :
|
2011-03-22 17:12:03 +00:00
|
|
|
rvertical.test( pos[ 0 ] ) ?
|
2012-04-12 15:48:01 +00:00
|
|
|
[ "center" ].concat( pos ) :
|
|
|
|
[ "center", "center" ];
|
2010-02-14 18:15:32 +00:00
|
|
|
}
|
2012-04-12 15:48:01 +00:00
|
|
|
pos[ 0 ] = rhorizontal.test( pos[ 0 ] ) ? pos[ 0 ] : "center";
|
|
|
|
pos[ 1 ] = rvertical.test( pos[ 1 ] ) ? pos[ 1 ] : "center";
|
2011-03-22 16:25:25 +00:00
|
|
|
|
|
|
|
// calculate offsets
|
|
|
|
horizontalOffset = roffset.exec( pos[ 0 ] );
|
2011-03-22 17:12:03 +00:00
|
|
|
verticalOffset = roffset.exec( pos[ 1 ] );
|
2011-03-22 16:25:25 +00:00
|
|
|
offsets[ this ] = [
|
|
|
|
horizontalOffset ? horizontalOffset[ 0 ] : 0,
|
|
|
|
verticalOffset ? verticalOffset[ 0 ] : 0
|
|
|
|
];
|
|
|
|
|
|
|
|
// reduce to just the positions without the offsets
|
|
|
|
options[ this ] = [
|
|
|
|
rposition.exec( pos[ 0 ] )[ 0 ],
|
|
|
|
rposition.exec( pos[ 1 ] )[ 0 ]
|
|
|
|
];
|
2015-03-14 11:33:03 +00:00
|
|
|
} );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
// normalize collision option
|
2010-02-14 18:15:32 +00:00
|
|
|
if ( collision.length === 1 ) {
|
|
|
|
collision[ 1 ] = collision[ 0 ];
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 17:12:03 +00:00
|
|
|
if ( options.at[ 0 ] === "right" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
basePosition.left += targetWidth;
|
2012-04-12 15:48:01 +00:00
|
|
|
} else if ( options.at[ 0 ] === "center" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
basePosition.left += targetWidth / 2;
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 17:12:03 +00:00
|
|
|
if ( options.at[ 1 ] === "bottom" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
basePosition.top += targetHeight;
|
2012-04-12 15:48:01 +00:00
|
|
|
} else if ( options.at[ 1 ] === "center" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
basePosition.top += targetHeight / 2;
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2012-04-17 22:30:47 +00:00
|
|
|
atOffset = getOffsets( offsets.at, targetWidth, targetHeight );
|
2011-05-12 13:28:01 +00:00
|
|
|
basePosition.left += atOffset[ 0 ];
|
2011-03-22 16:25:25 +00:00
|
|
|
basePosition.top += atOffset[ 1 ];
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2015-03-14 11:33:03 +00:00
|
|
|
return this.each( function() {
|
2012-04-18 14:43:25 +00:00
|
|
|
var collisionPosition, using,
|
|
|
|
elem = $( this ),
|
2010-01-07 03:19:50 +00:00
|
|
|
elemWidth = elem.outerWidth(),
|
|
|
|
elemHeight = elem.outerHeight(),
|
2012-04-17 22:30:47 +00:00
|
|
|
marginLeft = parseCss( this, "marginLeft" ),
|
|
|
|
marginTop = parseCss( this, "marginTop" ),
|
|
|
|
collisionWidth = elemWidth + marginLeft + parseCss( this, "marginRight" ) + scrollInfo.width,
|
|
|
|
collisionHeight = elemHeight + marginTop + parseCss( this, "marginBottom" ) + scrollInfo.height,
|
2010-09-03 14:38:44 +00:00
|
|
|
position = $.extend( {}, basePosition ),
|
2012-04-18 14:43:25 +00:00
|
|
|
myOffset = getOffsets( offsets.my, elem.outerWidth(), elem.outerHeight() );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2011-03-22 17:12:03 +00:00
|
|
|
if ( options.my[ 0 ] === "right" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
position.left -= elemWidth;
|
2012-04-12 15:48:01 +00:00
|
|
|
} else if ( options.my[ 0 ] === "center" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
position.left -= elemWidth / 2;
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 17:12:03 +00:00
|
|
|
if ( options.my[ 1 ] === "bottom" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
position.top -= elemHeight;
|
2012-04-12 15:48:01 +00:00
|
|
|
} else if ( options.my[ 1 ] === "center" ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
position.top -= elemHeight / 2;
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-22 16:25:25 +00:00
|
|
|
position.left += myOffset[ 0 ];
|
|
|
|
position.top += myOffset[ 1 ];
|
|
|
|
|
2011-11-02 15:09:00 +00:00
|
|
|
// if the browser doesn't support fractions, then round for consistent results
|
2015-03-18 14:05:36 +00:00
|
|
|
if ( !supportsOffsetFractions() ) {
|
2012-04-20 12:15:57 +00:00
|
|
|
position.left = round( position.left );
|
|
|
|
position.top = round( position.top );
|
2011-11-02 15:09:00 +00:00
|
|
|
}
|
|
|
|
|
2010-09-03 14:38:44 +00:00
|
|
|
collisionPosition = {
|
2011-08-13 03:19:52 +00:00
|
|
|
marginLeft: marginLeft,
|
|
|
|
marginTop: marginTop
|
2010-09-03 14:38:44 +00:00
|
|
|
};
|
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
$.each( [ "left", "top" ], function( i, dir ) {
|
2011-03-22 17:12:03 +00:00
|
|
|
if ( $.ui.position[ collision[ i ] ] ) {
|
|
|
|
$.ui.position[ collision[ i ] ][ dir ]( position, {
|
2010-01-07 03:19:50 +00:00
|
|
|
targetWidth: targetWidth,
|
|
|
|
targetHeight: targetHeight,
|
|
|
|
elemWidth: elemWidth,
|
|
|
|
elemHeight: elemHeight,
|
2010-09-03 14:38:44 +00:00
|
|
|
collisionPosition: collisionPosition,
|
|
|
|
collisionWidth: collisionWidth,
|
|
|
|
collisionHeight: collisionHeight,
|
2011-03-22 16:25:25 +00:00
|
|
|
offset: [ atOffset[ 0 ] + myOffset[ 0 ], atOffset [ 1 ] + myOffset[ 1 ] ],
|
2010-01-07 03:19:50 +00:00
|
|
|
my: options.my,
|
2011-05-11 23:30:21 +00:00
|
|
|
at: options.at,
|
2011-07-11 23:49:56 +00:00
|
|
|
within: within,
|
2013-12-09 11:55:17 +00:00
|
|
|
elem: elem
|
2015-03-14 11:33:03 +00:00
|
|
|
} );
|
2010-02-14 18:15:32 +00:00
|
|
|
}
|
2015-03-14 11:33:03 +00:00
|
|
|
} );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-04-10 22:19:26 +00:00
|
|
|
if ( options.using ) {
|
|
|
|
// adds feedback as second argument to using callback, if present
|
|
|
|
using = function( props ) {
|
2012-04-20 15:02:50 +00:00
|
|
|
var left = targetOffset.left - position.left,
|
2012-04-20 14:10:02 +00:00
|
|
|
right = left + targetWidth - elemWidth,
|
2012-04-20 15:02:50 +00:00
|
|
|
top = targetOffset.top - position.top,
|
2012-04-20 14:10:02 +00:00
|
|
|
bottom = top + targetHeight - elemHeight,
|
2012-04-10 21:41:41 +00:00
|
|
|
feedback = {
|
2012-04-13 14:05:29 +00:00
|
|
|
target: {
|
|
|
|
element: target,
|
|
|
|
left: targetOffset.left,
|
|
|
|
top: targetOffset.top,
|
|
|
|
width: targetWidth,
|
|
|
|
height: targetHeight
|
|
|
|
},
|
|
|
|
element: {
|
|
|
|
element: elem,
|
2012-04-20 15:02:50 +00:00
|
|
|
left: position.left,
|
|
|
|
top: position.top,
|
2012-04-13 14:05:29 +00:00
|
|
|
width: elemWidth,
|
|
|
|
height: elemHeight
|
|
|
|
},
|
2012-04-10 21:41:41 +00:00
|
|
|
horizontal: right < 0 ? "left" : left > 0 ? "right" : "center",
|
2012-04-13 14:05:29 +00:00
|
|
|
vertical: bottom < 0 ? "top" : top > 0 ? "bottom" : "middle"
|
2012-04-20 12:09:17 +00:00
|
|
|
};
|
2012-04-12 15:14:03 +00:00
|
|
|
if ( targetWidth < elemWidth && abs( left + right ) < targetWidth ) {
|
2012-04-11 23:32:30 +00:00
|
|
|
feedback.horizontal = "center";
|
|
|
|
}
|
2012-04-12 15:14:03 +00:00
|
|
|
if ( targetHeight < elemHeight && abs( top + bottom ) < targetHeight ) {
|
2012-04-11 23:32:30 +00:00
|
|
|
feedback.vertical = "middle";
|
|
|
|
}
|
2012-04-12 15:14:03 +00:00
|
|
|
if ( max( abs( left ), abs( right ) ) > max( abs( top ), abs( bottom ) ) ) {
|
2012-04-10 20:16:38 +00:00
|
|
|
feedback.important = "horizontal";
|
2012-04-10 16:11:28 +00:00
|
|
|
} else {
|
2012-04-10 20:16:38 +00:00
|
|
|
feedback.important = "vertical";
|
2012-04-10 16:11:28 +00:00
|
|
|
}
|
2012-04-10 22:19:26 +00:00
|
|
|
options.using.call( this, props, feedback );
|
2012-04-10 16:11:28 +00:00
|
|
|
};
|
|
|
|
}
|
2012-04-10 21:41:41 +00:00
|
|
|
|
2012-04-10 22:19:26 +00:00
|
|
|
elem.offset( $.extend( position, { using: using } ) );
|
2015-03-14 11:33:03 +00:00
|
|
|
} );
|
2010-01-07 03:19:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.ui.position = {
|
|
|
|
fit: {
|
2010-02-14 18:15:32 +00:00
|
|
|
left: function( position, data ) {
|
2012-04-13 12:46:43 +00:00
|
|
|
var within = data.within,
|
|
|
|
withinOffset = within.isWindow ? within.scrollLeft : within.offset.left,
|
|
|
|
outerWidth = within.width,
|
2011-08-13 03:19:52 +00:00
|
|
|
collisionPosLeft = position.left - data.collisionPosition.marginLeft,
|
|
|
|
overLeft = withinOffset - collisionPosLeft,
|
|
|
|
overRight = collisionPosLeft + data.collisionWidth - outerWidth - withinOffset,
|
2012-04-28 21:36:38 +00:00
|
|
|
newOverRight;
|
2011-08-13 03:19:52 +00:00
|
|
|
|
|
|
|
// element is wider than within
|
|
|
|
if ( data.collisionWidth > outerWidth ) {
|
|
|
|
// element is initially over the left side of within
|
|
|
|
if ( overLeft > 0 && overRight <= 0 ) {
|
|
|
|
newOverRight = position.left + overLeft + data.collisionWidth - outerWidth - withinOffset;
|
|
|
|
position.left += overLeft - newOverRight;
|
|
|
|
// element is initially over right side of within
|
|
|
|
} else if ( overRight > 0 && overLeft <= 0 ) {
|
|
|
|
position.left = withinOffset;
|
|
|
|
// element is initially over both left and right sides of within
|
|
|
|
} else {
|
|
|
|
if ( overLeft > overRight ) {
|
|
|
|
position.left = withinOffset + outerWidth - data.collisionWidth;
|
|
|
|
} else {
|
|
|
|
position.left = withinOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// too far left -> align with left edge
|
|
|
|
} else if ( overLeft > 0 ) {
|
2011-05-16 23:46:21 +00:00
|
|
|
position.left += overLeft;
|
2011-05-03 08:38:17 +00:00
|
|
|
// too far right -> align with right edge
|
|
|
|
} else if ( overRight > 0 ) {
|
2011-05-16 23:46:21 +00:00
|
|
|
position.left -= overRight;
|
2011-05-03 08:38:17 +00:00
|
|
|
// adjust based on position and margin
|
|
|
|
} else {
|
2012-04-20 12:15:57 +00:00
|
|
|
position.left = max( position.left - collisionPosLeft, position.left );
|
2011-05-03 08:38:17 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-02-14 18:15:32 +00:00
|
|
|
top: function( position, data ) {
|
2012-04-13 12:46:43 +00:00
|
|
|
var within = data.within,
|
|
|
|
withinOffset = within.isWindow ? within.scrollTop : within.offset.top,
|
2012-04-12 16:33:31 +00:00
|
|
|
outerHeight = data.within.height,
|
2011-08-13 03:19:52 +00:00
|
|
|
collisionPosTop = position.top - data.collisionPosition.marginTop,
|
|
|
|
overTop = withinOffset - collisionPosTop,
|
|
|
|
overBottom = collisionPosTop + data.collisionHeight - outerHeight - withinOffset,
|
|
|
|
newOverBottom;
|
|
|
|
|
|
|
|
// element is taller than within
|
|
|
|
if ( data.collisionHeight > outerHeight ) {
|
|
|
|
// element is initially over the top of within
|
|
|
|
if ( overTop > 0 && overBottom <= 0 ) {
|
|
|
|
newOverBottom = position.top + overTop + data.collisionHeight - outerHeight - withinOffset;
|
|
|
|
position.top += overTop - newOverBottom;
|
|
|
|
// element is initially over bottom of within
|
|
|
|
} else if ( overBottom > 0 && overTop <= 0 ) {
|
|
|
|
position.top = withinOffset;
|
|
|
|
// element is initially over both top and bottom of within
|
|
|
|
} else {
|
|
|
|
if ( overTop > overBottom ) {
|
|
|
|
position.top = withinOffset + outerHeight - data.collisionHeight;
|
|
|
|
} else {
|
|
|
|
position.top = withinOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// too far up -> align with top
|
|
|
|
} else if ( overTop > 0 ) {
|
2011-05-16 23:46:21 +00:00
|
|
|
position.top += overTop;
|
2011-05-03 08:38:17 +00:00
|
|
|
// too far down -> align with bottom edge
|
|
|
|
} else if ( overBottom > 0 ) {
|
2011-05-16 23:46:21 +00:00
|
|
|
position.top -= overBottom;
|
2011-05-03 08:38:17 +00:00
|
|
|
// adjust based on position and margin
|
|
|
|
} else {
|
2012-04-20 12:15:57 +00:00
|
|
|
position.top = max( position.top - collisionPosTop, position.top );
|
2011-05-03 08:38:17 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
flip: {
|
2010-02-14 18:15:32 +00:00
|
|
|
left: function( position, data ) {
|
2012-04-13 12:46:43 +00:00
|
|
|
var within = data.within,
|
2012-04-20 12:13:52 +00:00
|
|
|
withinOffset = within.offset.left + within.scrollLeft,
|
2012-04-13 12:46:43 +00:00
|
|
|
outerWidth = within.width,
|
2012-08-17 14:34:00 +00:00
|
|
|
offsetLeft = within.isWindow ? within.scrollLeft : within.offset.left,
|
2011-08-13 03:19:52 +00:00
|
|
|
collisionPosLeft = position.left - data.collisionPosition.marginLeft,
|
2012-04-04 02:08:34 +00:00
|
|
|
overLeft = collisionPosLeft - offsetLeft,
|
|
|
|
overRight = collisionPosLeft + data.collisionWidth - outerWidth - offsetLeft,
|
2010-02-14 18:15:32 +00:00
|
|
|
myOffset = data.my[ 0 ] === "left" ?
|
|
|
|
-data.elemWidth :
|
|
|
|
data.my[ 0 ] === "right" ?
|
|
|
|
data.elemWidth :
|
|
|
|
0,
|
2010-08-05 06:57:19 +00:00
|
|
|
atOffset = data.at[ 0 ] === "left" ?
|
|
|
|
data.targetWidth :
|
2012-04-24 15:50:52 +00:00
|
|
|
data.at[ 0 ] === "right" ?
|
|
|
|
-data.targetWidth :
|
|
|
|
0,
|
2011-08-13 03:19:52 +00:00
|
|
|
offset = -2 * data.offset[ 0 ],
|
|
|
|
newOverRight,
|
|
|
|
newOverLeft;
|
|
|
|
|
|
|
|
if ( overLeft < 0 ) {
|
|
|
|
newOverRight = position.left + myOffset + atOffset + offset + data.collisionWidth - outerWidth - withinOffset;
|
2012-04-20 12:15:57 +00:00
|
|
|
if ( newOverRight < 0 || newOverRight < abs( overLeft ) ) {
|
2011-08-13 03:19:52 +00:00
|
|
|
position.left += myOffset + atOffset + offset;
|
|
|
|
}
|
2013-10-16 18:43:09 +00:00
|
|
|
} else if ( overRight > 0 ) {
|
2012-04-04 02:08:34 +00:00
|
|
|
newOverLeft = position.left - data.collisionPosition.marginLeft + myOffset + atOffset + offset - offsetLeft;
|
2012-04-20 12:15:57 +00:00
|
|
|
if ( newOverLeft > 0 || abs( newOverLeft ) < overRight ) {
|
2011-08-13 03:19:52 +00:00
|
|
|
position.left += myOffset + atOffset + offset;
|
|
|
|
}
|
2011-05-11 23:30:21 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-02-14 18:15:32 +00:00
|
|
|
top: function( position, data ) {
|
2012-04-13 12:46:43 +00:00
|
|
|
var within = data.within,
|
2012-04-20 12:13:52 +00:00
|
|
|
withinOffset = within.offset.top + within.scrollTop,
|
2012-04-13 12:46:43 +00:00
|
|
|
outerHeight = within.height,
|
2012-08-17 14:34:00 +00:00
|
|
|
offsetTop = within.isWindow ? within.scrollTop : within.offset.top,
|
2011-08-13 03:19:52 +00:00
|
|
|
collisionPosTop = position.top - data.collisionPosition.marginTop,
|
2012-04-04 02:08:34 +00:00
|
|
|
overTop = collisionPosTop - offsetTop,
|
|
|
|
overBottom = collisionPosTop + data.collisionHeight - outerHeight - offsetTop,
|
2011-05-11 23:30:21 +00:00
|
|
|
top = data.my[ 1 ] === "top",
|
|
|
|
myOffset = top ?
|
2010-02-14 18:15:32 +00:00
|
|
|
-data.elemHeight :
|
|
|
|
data.my[ 1 ] === "bottom" ?
|
|
|
|
data.elemHeight :
|
|
|
|
0,
|
|
|
|
atOffset = data.at[ 1 ] === "top" ?
|
|
|
|
data.targetHeight :
|
2012-04-24 15:50:52 +00:00
|
|
|
data.at[ 1 ] === "bottom" ?
|
|
|
|
-data.targetHeight :
|
|
|
|
0,
|
2011-08-13 03:19:52 +00:00
|
|
|
offset = -2 * data.offset[ 1 ],
|
|
|
|
newOverTop,
|
|
|
|
newOverBottom;
|
|
|
|
if ( overTop < 0 ) {
|
|
|
|
newOverBottom = position.top + myOffset + atOffset + offset + data.collisionHeight - outerHeight - withinOffset;
|
2013-09-04 16:54:07 +00:00
|
|
|
if ( newOverBottom < 0 || newOverBottom < abs( overTop ) ) {
|
2011-08-13 03:19:52 +00:00
|
|
|
position.top += myOffset + atOffset + offset;
|
|
|
|
}
|
2013-10-16 18:43:09 +00:00
|
|
|
} else if ( overBottom > 0 ) {
|
2013-08-02 11:15:58 +00:00
|
|
|
newOverTop = position.top - data.collisionPosition.marginTop + myOffset + atOffset + offset - offsetTop;
|
2013-09-04 16:54:07 +00:00
|
|
|
if ( newOverTop > 0 || abs( newOverTop ) < overBottom ) {
|
2011-08-13 03:19:52 +00:00
|
|
|
position.top += myOffset + atOffset + offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
flipfit: {
|
2012-01-18 23:58:43 +00:00
|
|
|
left: function() {
|
|
|
|
$.ui.position.flip.left.apply( this, arguments );
|
2011-08-13 03:19:52 +00:00
|
|
|
$.ui.position.fit.left.apply( this, arguments );
|
|
|
|
},
|
2012-01-18 23:58:43 +00:00
|
|
|
top: function() {
|
|
|
|
$.ui.position.flip.top.apply( this, arguments );
|
2011-08-13 03:19:52 +00:00
|
|
|
$.ui.position.fit.top.apply( this, arguments );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-14 11:33:03 +00:00
|
|
|
} )();
|
2013-07-12 16:40:48 +00:00
|
|
|
|
|
|
|
return $.ui.position;
|
|
|
|
|
2015-03-14 11:33:03 +00:00
|
|
|
} ) );
|