]> 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)
committerAlexander Schmitz <arschmitz@gmail.com>
Wed, 8 Jul 2015 04:15:34 +0000 (00:15 -0400)
Starting in jQuery 3.0 this will throw an error

Fixes #13493
Closes gh-1565

ui/position.js

index 367fc3978d67aae114d749c0d00f1af161bfa3e0..172503fefaf2cd2587c711507b2a3e9607fd2c52 100644 (file)
@@ -142,12 +142,13 @@ $.position = {
        getWithinInfo: function( element ) {
                var withinElement = $( element || window ),
                        isWindow = $.isWindow( withinElement[ 0 ] ),
-                       isDocument = !!withinElement[ 0 ] && withinElement[ 0 ].nodeType === 9;
+                       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(),
                        width: withinElement.outerWidth(),