2010-01-07 03:19:50 +00:00
|
|
|
/*
|
|
|
|
* jQuery UI Position @VERSION
|
|
|
|
*
|
2010-07-14 19:45:45 +00:00
|
|
|
* Copyright 2010, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2010-01-07 03:19:50 +00:00
|
|
|
*
|
|
|
|
* http://docs.jquery.com/UI/Position
|
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
$.ui = $.ui || {};
|
|
|
|
|
|
|
|
var horizontalPositions = /left|center|right/,
|
|
|
|
verticalPositions = /top|center|bottom/,
|
2010-08-27 17:19:51 +00:00
|
|
|
center = "center",
|
2010-03-11 22:16:00 +00:00
|
|
|
_position = $.fn.position,
|
|
|
|
_offset = $.fn.offset;
|
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
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
var target = $( options.of ),
|
2010-08-27 17:34:14 +00:00
|
|
|
targetElem = target[0],
|
2010-02-14 18:15:32 +00:00
|
|
|
collision = ( options.collision || "flip" ).split( " " ),
|
|
|
|
offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ],
|
2010-01-07 03:19:50 +00:00
|
|
|
targetWidth,
|
|
|
|
targetHeight,
|
|
|
|
basePosition;
|
|
|
|
|
2010-08-27 17:34:14 +00:00
|
|
|
if ( targetElem.nodeType === 9 ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
targetWidth = target.width();
|
|
|
|
targetHeight = target.height();
|
|
|
|
basePosition = { top: 0, left: 0 };
|
2010-08-27 17:34:14 +00:00
|
|
|
} else if ( targetElem.scrollTo && targetElem.document ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
targetWidth = target.width();
|
|
|
|
targetHeight = target.height();
|
|
|
|
basePosition = { top: target.scrollTop(), left: target.scrollLeft() };
|
2010-08-27 17:34:14 +00:00
|
|
|
} else if ( targetElem.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
|
|
|
targetWidth = targetHeight = 0;
|
|
|
|
basePosition = { top: options.of.pageY, left: options.of.pageX };
|
|
|
|
} else {
|
|
|
|
targetWidth = target.outerWidth();
|
|
|
|
targetHeight = target.outerHeight();
|
|
|
|
basePosition = target.offset();
|
|
|
|
}
|
|
|
|
|
|
|
|
// force my and at to have valid horizontal and veritcal positions
|
|
|
|
// 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() {
|
|
|
|
var pos = ( options[this] || "" ).split( " " );
|
|
|
|
if ( pos.length === 1) {
|
|
|
|
pos = horizontalPositions.test( pos[0] ) ?
|
2010-08-27 17:19:51 +00:00
|
|
|
pos.concat( [center] ) :
|
2010-02-14 18:15:32 +00:00
|
|
|
verticalPositions.test( pos[0] ) ?
|
2010-08-27 17:19:51 +00:00
|
|
|
[ center ].concat( pos ) :
|
|
|
|
[ center, center ];
|
2010-02-14 18:15:32 +00:00
|
|
|
}
|
2010-08-27 17:19:51 +00:00
|
|
|
pos[ 0 ] = horizontalPositions.test( pos[0] ) ? pos[ 0 ] : center;
|
|
|
|
pos[ 1 ] = verticalPositions.test( pos[1] ) ? pos[ 1 ] : center;
|
2010-02-14 18:15:32 +00:00
|
|
|
options[ this ] = pos;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// normalize offset option
|
2010-02-14 18:15:32 +00:00
|
|
|
offset[ 0 ] = parseInt( offset[0], 10 ) || 0;
|
|
|
|
if ( offset.length === 1 ) {
|
|
|
|
offset[ 1 ] = offset[ 0 ];
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2010-02-14 18:15:32 +00:00
|
|
|
offset[ 1 ] = parseInt( offset[1], 10 ) || 0;
|
|
|
|
|
|
|
|
if ( options.at[0] === "right" ) {
|
|
|
|
basePosition.left += targetWidth;
|
2010-08-27 17:19:51 +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
|
|
|
}
|
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
if ( options.at[1] === "bottom" ) {
|
|
|
|
basePosition.top += targetHeight;
|
2010-08-27 17:19:51 +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
|
|
|
}
|
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
basePosition.left += offset[ 0 ];
|
|
|
|
basePosition.top += offset[ 1 ];
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
return this.each(function() {
|
2010-02-14 18:15:32 +00:00
|
|
|
var elem = $( this ),
|
2010-01-07 03:19:50 +00:00
|
|
|
elemWidth = elem.outerWidth(),
|
|
|
|
elemHeight = elem.outerHeight(),
|
2010-03-11 22:16:00 +00:00
|
|
|
position = $.extend( {}, basePosition );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
if ( options.my[0] === "right" ) {
|
|
|
|
position.left -= elemWidth;
|
2010-08-27 17:19:51 +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
|
|
|
}
|
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
if ( options.my[1] === "bottom" ) {
|
|
|
|
position.top -= elemHeight;
|
2010-08-27 17:19:51 +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
|
|
|
}
|
|
|
|
|
2010-03-26 23:53:43 +00:00
|
|
|
// prevent fractions (see #5280)
|
|
|
|
position.left = parseInt( position.left );
|
|
|
|
position.top = parseInt( position.top );
|
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
$.each( [ "left", "top" ], function( i, dir ) {
|
|
|
|
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,
|
|
|
|
offset: offset,
|
|
|
|
my: options.my,
|
|
|
|
at: options.at
|
2010-02-14 18:15:32 +00:00
|
|
|
});
|
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
|
|
|
|
2010-02-14 18:15:32 +00:00
|
|
|
if ( $.fn.bgiframe ) {
|
|
|
|
elem.bgiframe();
|
|
|
|
}
|
|
|
|
elem.offset( $.extend( position, { using: options.using } ) );
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ui.position = {
|
|
|
|
fit: {
|
2010-02-14 18:15:32 +00:00
|
|
|
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 );
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-02-14 18:15:32 +00:00
|
|
|
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 );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
flip: {
|
2010-02-14 18:15:32 +00:00
|
|
|
left: function( position, data ) {
|
2010-08-27 17:19:51 +00:00
|
|
|
if ( data.at[0] === center ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
return;
|
2010-02-14 18:15:32 +00:00
|
|
|
}
|
|
|
|
var win = $( window ),
|
|
|
|
over = position.left + data.elemWidth - win.width() - win.scrollLeft(),
|
|
|
|
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 :
|
|
|
|
-data.targetWidth,
|
2010-02-14 18:15:32 +00:00
|
|
|
offset = -2 * data.offset[ 0 ];
|
|
|
|
position.left += position.left < 0 ?
|
2010-08-05 06:57:19 +00:00
|
|
|
myOffset + atOffset + offset :
|
2010-02-14 18:15:32 +00:00
|
|
|
over > 0 ?
|
2010-08-05 06:57:19 +00:00
|
|
|
myOffset + atOffset + offset :
|
2010-02-14 18:15:32 +00:00
|
|
|
0;
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-02-14 18:15:32 +00:00
|
|
|
top: function( position, data ) {
|
2010-08-27 17:19:51 +00:00
|
|
|
if ( data.at[1] === center ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
return;
|
2010-02-14 18:15:32 +00:00
|
|
|
}
|
|
|
|
var win = $( window ),
|
|
|
|
over = position.top + data.elemHeight - win.height() - win.scrollTop(),
|
|
|
|
myOffset = data.my[ 1 ] === "top" ?
|
|
|
|
-data.elemHeight :
|
|
|
|
data.my[ 1 ] === "bottom" ?
|
|
|
|
data.elemHeight :
|
|
|
|
0,
|
|
|
|
atOffset = data.at[ 1 ] === "top" ?
|
|
|
|
data.targetHeight :
|
|
|
|
-data.targetHeight,
|
|
|
|
offset = -2 * data.offset[ 1 ];
|
|
|
|
position.top += position.top < 0 ?
|
2010-08-05 06:57:19 +00:00
|
|
|
myOffset + atOffset + offset :
|
2010-02-14 18:15:32 +00:00
|
|
|
over > 0 ?
|
|
|
|
myOffset + atOffset + offset :
|
|
|
|
0;
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// offset setter from jQuery 1.4
|
2010-02-14 18:15:32 +00:00
|
|
|
if ( !$.offset.setOffset ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
$.offset.setOffset = function( elem, options ) {
|
|
|
|
// set position first, in-case top/left are set even on static elem
|
2010-03-11 22:16:00 +00:00
|
|
|
if ( /static/.test( $.curCSS( elem, "position" ) ) ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
elem.style.position = "relative";
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2010-03-11 22:16:00 +00:00
|
|
|
var curElem = $( elem ),
|
2010-01-07 03:19:50 +00:00
|
|
|
curOffset = curElem.offset(),
|
2010-03-11 22:16:00 +00:00
|
|
|
curTop = parseInt( $.curCSS( elem, "top", true ), 10 ) || 0,
|
|
|
|
curLeft = parseInt( $.curCSS( elem, "left", true ), 10) || 0,
|
2010-01-07 03:19:50 +00:00
|
|
|
props = {
|
|
|
|
top: (options.top - curOffset.top) + curTop,
|
|
|
|
left: (options.left - curOffset.left) + curLeft
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( 'using' in options ) {
|
|
|
|
options.using.call( elem, props );
|
|
|
|
} else {
|
|
|
|
curElem.css( props );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.offset = function( options ) {
|
2010-02-14 18:15:32 +00:00
|
|
|
var elem = this[ 0 ];
|
2010-01-07 03:19:50 +00:00
|
|
|
if ( !elem || !elem.ownerDocument ) { return null; }
|
|
|
|
if ( options ) {
|
|
|
|
return this.each(function() {
|
|
|
|
$.offset.setOffset( this, options );
|
|
|
|
});
|
|
|
|
}
|
2010-02-14 18:15:32 +00:00
|
|
|
return _offset.call( this );
|
2010-01-07 03:19:50 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-03-11 22:16:00 +00:00
|
|
|
}( jQuery ));
|