Skip to content

Commit c8b2640

Browse files
meyerteescottgonzalez
authored andcommitted
Position: Avoid reading overflow css on documents
Fixes #9533 Closes jquerygh-1072 (cherry picked from commit 1bbbcc7)
1 parent a29be89 commit c8b2640

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

tests/unit/position/position_core.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,14 @@ test( "collision: flip, with margin", function() {
575575
});
576576

577577
test( "within", function() {
578-
expect( 6 );
578+
expect( 7 );
579+
580+
collisionTest({
581+
within: document
582+
}, {
583+
top: 10,
584+
left: 10
585+
}, "within document" );
579586

580587
collisionTest({
581588
within: "#within",

ui/jquery.ui.position.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ $.position = {
8888
return (cachedScrollbarWidth = w1 - w2);
8989
},
9090
getScrollInfo: function( within ) {
91-
var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ),
92-
overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ),
91+
var overflowX = within.isWindow || within.isDocument ? "" :
92+
within.element.css( "overflow-x" ),
93+
overflowY = within.isWindow || within.isDocument ? "" :
94+
within.element.css( "overflow-y" ),
9395
hasOverflowX = overflowX === "scroll" ||
9496
( overflowX === "auto" && within.width < within.element[0].scrollWidth ),
9597
hasOverflowY = overflowY === "scroll" ||
@@ -101,10 +103,12 @@ $.position = {
101103
},
102104
getWithinInfo: function( element ) {
103105
var withinElement = $( element || window ),
104-
isWindow = $.isWindow( withinElement[0] );
106+
isWindow = $.isWindow( withinElement[0] ),
107+
isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
105108
return {
106109
element: withinElement,
107110
isWindow: isWindow,
111+
isDocument: isDocument,
108112
offset: withinElement.offset() || { left: 0, top: 0 },
109113
scrollLeft: withinElement.scrollLeft(),
110114
scrollTop: withinElement.scrollTop(),

0 commit comments

Comments
 (0)