]> source.dussan.org Git - jquery-ui.git/commitdiff
Position: Guard against passing window to offset
authorAlexander Schmitz <arschmitz@gmail.com>
Wed, 17 Jun 2015 15:33:06 +0000 (11:33 -0400)
committerScott González <scott.gonzalez@gmail.com>
Thu, 9 Jun 2016 19:00:28 +0000 (15:00 -0400)
Starting in jQuery 3.0 this will throw an error

Fixes #13493
Closes gh-1565

(cherry picked from commit b3a9b13a218cd90b7cf67be5d5f8ad6e76c557b0)

ui/position.js

index 28aca6dc6344aad5e5469bed01a857f5043b8c91..a59f0009da1eba3f99157f755e9ac08c1c16a104 100644 (file)
@@ -114,13 +114,14 @@ $.position = {
        },
        getWithinInfo: function( element ) {
                var withinElement = $( element || window ),
-                       isWindow = $.isWindow( withinElement[0] ),
-                       isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
+                       isWindow = $.isWindow( withinElement[ 0 ] ),
+                       isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9,
+                       hasOffset = !isWindow && !isDocument;
                return {
                        element: withinElement,
                        isWindow: isWindow,
                        isDocument: isDocument,
-                       offset: withinElement.offset() || { left: 0, top: 0 },
+                       offset: hasOffset ? $( element ).offset() : { left: 0, top: 0 },
                        scrollLeft: withinElement.scrollLeft(),
                        scrollTop: withinElement.scrollTop(),