mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Position: Split out dimension parsing.
This commit is contained in:
parent
fb38c20763
commit
a1eb9ca4be
54
ui/jquery.ui.position.js
vendored
54
ui/jquery.ui.position.js
vendored
@ -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 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user