Skip to content

Commit 4394503

Browse files
arschmitzscottgonzalez
authored andcommitted
Position: Guard against passing window to offset
Starting in jQuery 3.0 this will throw an error Fixes #13493 Closes jquerygh-1565 (cherry picked from commit b3a9b13)
1 parent 330db54 commit 4394503

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

ui/position.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,14 @@ $.position = {
114114
},
115115
getWithinInfo: function( element ) {
116116
var withinElement = $( element || window ),
117-
isWindow = $.isWindow( withinElement[0] ),
118-
isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
117+
isWindow = $.isWindow( withinElement[ 0 ] ),
118+
isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
119+
hasOffset = !isWindow && !isDocument;
119120
return {
120121
element: withinElement,
121122
isWindow: isWindow,
122123
isDocument: isDocument,
123-
offset: withinElement.offset() || { left: 0, top: 0 },
124+
offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
124125
scrollLeft: withinElement.scrollLeft(),
125126
scrollTop: withinElement.scrollTop(),
126127

0 commit comments

Comments
 (0)