From e4218ca10b333e530b4c4e8023f375f79e029a3c Mon Sep 17 00:00:00 2001 From: Oleg Gaidarenko Date: Fri, 13 Nov 2015 14:54:25 +0300 Subject: [PATCH] Revert "Offset: remove ownerDocument check in offset getter" This reverts commit 6176567361e9d05d4f5eb7e98735a678f2cd7ea9. --- src/offset.js | 12 +++++------- test/unit/offset.js | 9 +++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/offset.js b/src/offset.js index f7ef79c3c..c185c1c3b 100644 --- a/src/offset.js +++ b/src/offset.js @@ -74,8 +74,6 @@ jQuery.offset = { jQuery.fn.extend( { offset: function( options ) { - - // Preserve chaining for setter if ( arguments.length ) { return options === undefined ? this : @@ -84,8 +82,9 @@ jQuery.fn.extend( { } ); } - var docElem, win, rect, doc, - elem = this[ 0 ]; + var docElem, win, rect, + elem = this[ 0 ], + doc = elem && elem.ownerDocument; if ( !elem ) { return; @@ -100,9 +99,8 @@ jQuery.fn.extend( { rect = elem.getBoundingClientRect(); - // Make sure element is not hidden (display: none) - if ( rect.width || rect.height ) { - doc = elem.ownerDocument; + // Make sure element is not hidden (display: none) or disconnected + if ( rect.width || rect.height || elem.getClientRects().length ) { win = getWindow( doc ); docElem = doc.documentElement; diff --git a/test/unit/offset.js b/test/unit/offset.js index a0f253b4e..a4822e4a9 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -48,6 +48,15 @@ QUnit.test( "empty set", function( assert ) { assert.strictEqual( jQuery().position(), undefined, "position() returns undefined for empty set (#11962)" ); } ); +QUnit.test( "object without getBoundingClientRect", function( assert ) { + assert.expect( 2 ); + + // Simulates a browser without gBCR on elements, we just want to return 0,0 + var result = jQuery({ ownerDocument: document }).offset(); + assert.equal( result.top, 0, "Check top" ); + assert.equal( result.left, 0, "Check left" ); +}); + QUnit.test( "disconnected element", function( assert ) { assert.expect( 2 ); -- 2.39.5