]> source.dussan.org Git - jquery.git/commitdiff
Offset: remove ownerDocument check in offset getter
authorTimmy Willison <timmywillisn@gmail.com>
Tue, 5 May 2015 15:31:39 +0000 (08:31 -0700)
committerTimmy Willison <timmywillisn@gmail.com>
Tue, 5 May 2015 16:00:37 +0000 (09:00 -0700)
Fixes gh-2115

src/offset.js
test/unit/offset.js

index 0cc26d7d9cbe6eee4df1148111c4fd8cb68ce78a..e4a706ee0969a33c67d7901243735b54c2b46bfa 100644 (file)
@@ -79,6 +79,7 @@ jQuery.offset = {
 
 jQuery.fn.extend({
        offset: function( options ) {
+               // Preserve chaining for setter
                if ( arguments.length ) {
                        return options === undefined ?
                                this :
@@ -87,11 +88,10 @@ jQuery.fn.extend({
                                });
                }
 
-               var docElem, win, rect,
-                       elem = this[ 0 ],
-                       doc = elem && elem.ownerDocument;
+               var docElem, win, rect, doc,
+                       elem = this[ 0 ];
 
-               if ( !doc ) {
+               if ( !elem ) {
                        return;
                }
 
@@ -99,6 +99,7 @@ jQuery.fn.extend({
 
                // Make sure element is not hidden (display: none) or disconnected
                if ( rect.width || rect.height || elem.getClientRects().length ) {
+                       doc = elem.ownerDocument;
                        win = getWindow( doc );
                        docElem = doc.documentElement;
 
index c0eacb65cb410b81ec6acb66d167c453d915cdaa..3977e3933710de3f1de5273acf642e4523f6f381 100644 (file)
@@ -43,20 +43,11 @@ module("offset", { setup: function(){
 */
 
 test("empty set", function() {
-       expect(2);
+       expect( 2 );
        strictEqual( jQuery().offset(), undefined, "offset() returns undefined for empty set (#11962)" );
        strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" );
 });
 
-test("object without getBoundingClientRect", function() {
-       expect(2);
-
-       // Simulates a browser without gBCR on elements, we just want to return 0,0
-       var result = jQuery({ ownerDocument: document }).offset();
-       equal( result.top, 0, "Check top" );
-       equal( result.left, 0, "Check left" );
-});
-
 test("disconnected element", function() {
        expect(1);