aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.position.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2012-12-06 15:00:42 -0500
committerScott González <scott.gonzalez@gmail.com>2012-12-06 15:00:42 -0500
commita1eb9ca4befdabace88fc78aa59947dbf7c36e20 (patch)
tree91d6de8c88543356e4d2b0826940c276c5f1b736 /ui/jquery.ui.position.js
parentfb38c20763c637e4d05ca2a48e25db4b380754be (diff)
downloadjquery-ui-a1eb9ca4befdabace88fc78aa59947dbf7c36e20.tar.gz
jquery-ui-a1eb9ca4befdabace88fc78aa59947dbf7c36e20.zip
Position: Split out dimension parsing.
Diffstat (limited to 'ui/jquery.ui.position.js')
-rw-r--r--ui/jquery.ui.position.js54
1 files changed, 37 insertions, 17 deletions
diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js
index a5dc31834..dbfadedd1 100644
--- a/ui/jquery.ui.position.js
+++ b/ui/jquery.ui.position.js
@@ -29,10 +29,41 @@ function getOffsets( offsets, width, height ) {
parseInt( offsets[ 1 ], 10 ) * ( rpercent.test( offsets[ 1 ] ) ? height / 100 : 1 )
];
}
+
function parseCss( element, property ) {
return parseInt( $.css( element, property ), 10 ) || 0;
}
+function getDimensions( elem ) {
+ var raw = elem[0];
+ 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()
+ };
+}
+
$.position = {
scrollbarWidth: function() {
if ( cachedScrollbarWidth !== undefined ) {
@@ -91,32 +122,21 @@ $.fn.position = function( options ) {
// make a copy, we don't want to modify arguments
options = $.extend( {}, options );
- var atOffset, targetWidth, targetHeight, targetOffset, basePosition,
+ var atOffset, targetWidth, targetHeight, targetOffset, basePosition, dimensions,
target = $( options.of ),
within = $.position.getWithinInfo( options.within ),
scrollInfo = $.position.getScrollInfo( within ),
- targetElem = target[0],
collision = ( options.collision || "flip" ).split( " " ),
offsets = {};
- if ( targetElem.nodeType === 9 ) {
- targetWidth = target.width();
- targetHeight = target.height();
- targetOffset = { top: 0, left: 0 };
- } else if ( $.isWindow( targetElem ) ) {
- targetWidth = target.width();
- targetHeight = target.height();
- targetOffset = { top: target.scrollTop(), left: target.scrollLeft() };
- } else if ( targetElem.preventDefault ) {
+ dimensions = getDimensions( target );
+ if ( target[0].preventDefault ) {
// force left top to allow flipping
options.at = "left top";
- targetWidth = targetHeight = 0;
- targetOffset = { top: targetElem.pageY, left: targetElem.pageX };
- } else {
- targetWidth = target.outerWidth();
- targetHeight = target.outerHeight();
- targetOffset = target.offset();
}
+ targetWidth = dimensions.width;
+ targetHeight = dimensions.height;
+ targetOffset = dimensions.offset;
// clone to reuse original targetOffset later
basePosition = $.extend( {}, targetOffset );