Skip to content

Commit

Permalink
Position: Avoid reading overflow css on documents
Browse files Browse the repository at this point in the history
Fixes #9533
Closes gh-1072
(cherry picked from commit 1bbbcc7)
  • Loading branch information
meyertee authored and scottgonzalez committed Jan 15, 2014
1 parent a29be89 commit c8b2640
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion tests/unit/position/position_core.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -575,7 +575,14 @@ test( "collision: flip, with margin", function() {
}); });


test( "within", function() { test( "within", function() {
expect( 6 ); expect( 7 );

collisionTest({
within: document
}, {
top: 10,
left: 10
}, "within document" );


collisionTest({ collisionTest({
within: "#within", within: "#within",
Expand Down
10 changes: 7 additions & 3 deletions ui/jquery.ui.position.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ $.position = {
return (cachedScrollbarWidth = w1 - w2); return (cachedScrollbarWidth = w1 - w2);
}, },
getScrollInfo: function( within ) { getScrollInfo: function( within ) {
var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ), var overflowX = within.isWindow || within.isDocument ? "" :
overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ), within.element.css( "overflow-x" ),
overflowY = within.isWindow || within.isDocument ? "" :
within.element.css( "overflow-y" ),
hasOverflowX = overflowX === "scroll" || hasOverflowX = overflowX === "scroll" ||
( overflowX === "auto" && within.width < within.element[0].scrollWidth ), ( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
hasOverflowY = overflowY === "scroll" || hasOverflowY = overflowY === "scroll" ||
Expand All @@ -101,10 +103,12 @@ $.position = {
}, },
getWithinInfo: function( element ) { getWithinInfo: function( element ) {
var withinElement = $( element || window ), var withinElement = $( element || window ),
isWindow = $.isWindow( withinElement[0] ); isWindow = $.isWindow( withinElement[0] ),
isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
return { return {
element: withinElement, element: withinElement,
isWindow: isWindow, isWindow: isWindow,
isDocument: isDocument,
offset: withinElement.offset() || { left: 0, top: 0 }, offset: withinElement.offset() || { left: 0, top: 0 },
scrollLeft: withinElement.scrollLeft(), scrollLeft: withinElement.scrollLeft(),
scrollTop: withinElement.scrollTop(), scrollTop: withinElement.scrollTop(),
Expand Down

0 comments on commit c8b2640

Please sign in to comment.