aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/position/position_core_within.js10
-rw-r--r--ui/jquery.ui.position.js38
2 files changed, 25 insertions, 23 deletions
diff --git a/tests/unit/position/position_core_within.js b/tests/unit/position/position_core_within.js
index 9dc91238f..c9670f8ff 100644
--- a/tests/unit/position/position_core_within.js
+++ b/tests/unit/position/position_core_within.js
@@ -277,7 +277,7 @@ test( "collision: fit, no offset", function() {
collisionTest({
collision: "fit"
- }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
collisionTest2({
collision: "fit"
@@ -292,7 +292,7 @@ test( "collision: fit, with offset", function() {
collisionTest({
collision: "fit",
at: "right+2 bottom+3"
- }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( within ).width }, "right bottom");
+ }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom");
collisionTest2({
collision: "fit",
@@ -397,7 +397,7 @@ test( "collision: fit, with margin", function() {
collisionTest({
collision: "fit"
- }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
collisionTest2({
collision: "fit"
@@ -410,7 +410,7 @@ test( "collision: fit, with margin", function() {
collisionTest({
collision: "fit"
- }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
collisionTest2({
collision: "fit"
@@ -423,7 +423,7 @@ test( "collision: fit, with margin", function() {
collisionTest({
collision: "fit"
- }, { top: addTop + of.position().top + of.height() - 15 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 15 - $.position.getScrollInfo( within ).width }, "right bottom" );
+ }, { top: addTop + of.position().top + of.height() - 15 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - 15 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
collisionTest2({
collision: "fit"
diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js
index e83c23e44..9e7407d7b 100644
--- a/ui/jquery.ui.position.js
+++ b/ui/jquery.ui.position.js
@@ -38,16 +38,28 @@ $.position = {
return w1 - w2;
},
- getScrollInfo: function(within) {
- var notWindow = within[0] !== window,
- overflowX = notWindow ? within.css( "overflow-x" ) : "",
- overflowY = notWindow ? within.css( "overflow-y" ) : "",
+ getScrollInfo: function( within ) {
+ var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
+ overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
scrollbarWidth = overflowX === "auto" || overflowX === "scroll" ? $.position.scrollbarWidth() : 0,
scrollbarHeight = overflowY === "auto" || overflowY === "scroll" ? $.position.scrollbarWidth() : 0;
return {
- height: within.height() < within[0].scrollHeight ? scrollbarHeight : 0,
- width: within.width() < within[0].scrollWidth ? scrollbarWidth : 0
+ height: within.height < within.element[0].scrollHeight ? scrollbarHeight : 0,
+ width: within.width < within.element[0].scrollWidth ? scrollbarWidth : 0
+ };
+ },
+ getWithinInfo: function( element ) {
+ var withinElement = $( element || window ),
+ isWindow = $.isWindow( withinElement[0] );
+ return {
+ element: withinElement,
+ isWindow: isWindow,
+ offset: withinElement.offset(),
+ scrollLeft: withinElement.scrollLeft(),
+ scrollTop: withinElement.scrollTop(),
+ width: isWindow ? withinElement.width() : withinElement.outerWidth(),
+ height: isWindow ? withinElement.height() : withinElement.outerHeight()
};
},
getOffsets: function( offsets, width, height ) {
@@ -70,18 +82,8 @@ $.fn.position = function( options ) {
options = $.extend( {}, options );
var target = $( options.of ),
- withinElement = $( options.within || window ),
- isWindow = $.isWindow( withinElement[0] ),
- within = {
- element: withinElement,
- isWindow: isWindow,
- offset: withinElement.offset(),
- scrollLeft: withinElement.scrollLeft(),
- scrollTop: withinElement.scrollTop(),
- width: isWindow ? withinElement.width() : withinElement.outerWidth(),
- height: isWindow ? withinElement.height() : withinElement.outerHeight()
- },
- scrollInfo = $.position.getScrollInfo( withinElement ),
+ within = $.position.getWithinInfo( options.within ),
+ scrollInfo = $.position.getScrollInfo( within ),
targetElem = target[0],
collision = ( options.collision || "flip" ).split( " " ),
offsets = {},