Position: Guard against passing window to offset

Starting in jQuery 3.0 this will throw an error

Fixes #13493
Closes gh-1565
This commit is contained in:
Alexander Schmitz 2015-06-17 11:33:06 -04:00
parent bec722abdb
commit b3a9b13a21

View File

@ -142,12 +142,13 @@ $.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; isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
hasOffset = !isWindow && !isDocument;
return { return {
element: withinElement, element: withinElement,
isWindow: isWindow, isWindow: isWindow,
isDocument: isDocument, isDocument: isDocument,
offset: withinElement.offset() || { left: 0, top: 0 }, offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
scrollLeft: withinElement.scrollLeft(), scrollLeft: withinElement.scrollLeft(),
scrollTop: withinElement.scrollTop(), scrollTop: withinElement.scrollTop(),
width: withinElement.outerWidth(), width: withinElement.outerWidth(),