From: Oleg Gaidarenko Date: Tue, 22 Dec 2015 13:15:52 +0000 (+0300) Subject: Revert "Offset: Fix .offset() to correctly work with ShadowDOM" X-Git-Tag: 1.12.0~56 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c43ea04c543be06f0985484a740c172587d7a8dd;p=jquery.git Revert "Offset: Fix .offset() to correctly work with ShadowDOM" This reverts commit d4dd548acaf049d8e4dca9e4b879a51f26bb3d27. --- diff --git a/src/offset.js b/src/offset.js index 8047c872f..b7dbdf561 100644 --- a/src/offset.js +++ b/src/offset.js @@ -41,7 +41,7 @@ jQuery.offset = { elem.style.position = "relative"; } - curOffset = curElem.offset() || { top: 0, left: 0 }; + curOffset = curElem.offset(); curCSSTop = jQuery.css( elem, "top" ); curCSSLeft = jQuery.css( elem, "left" ); calculatePosition = ( position === "absolute" || position === "fixed" ) && @@ -89,7 +89,8 @@ jQuery.fn.extend( { } ); } - var docElem, win, rect, + var docElem, win, + box = { top: 0, left: 0 }, elem = this[ 0 ], doc = elem && elem.ownerDocument; @@ -97,33 +98,19 @@ jQuery.fn.extend( { return; } - doc = elem.ownerDocument; docElem = doc.documentElement; - // Support: IE<=11+ - // Running getBoundingClientRect on a - // disconnected node in IE throws an error - // Support: IE8 only - // getClientRects() errors on disconnected elems + // Make sure it's not a disconnected DOM node if ( !jQuery.contains( docElem, elem ) ) { - return { top: 0, left: 0 }; + return box; } - rect = elem.getBoundingClientRect(); - - if ( rect.width || rect.height || elem.getClientRects().length ) { - win = getWindow( doc ); - - return { - top: rect.top + ( win.pageYOffset || docElem.scrollTop ) - - ( docElem.clientTop || 0 ), - left: rect.left + ( win.pageXOffset || docElem.scrollLeft ) - - ( docElem.clientLeft || 0 ) - }; - } - - // Return zeros for hidden elements - return rect; + box = elem.getBoundingClientRect(); + win = getWindow( doc ); + return { + top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ), + left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 ) + }; }, position: function() { diff --git a/test/unit/offset.js b/test/unit/offset.js index e8c2c8f10..783873dbe 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -70,21 +70,6 @@ QUnit.test( "disconnected element", function( assert ) { assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" ); } ); -QUnit.test( "hidden (display: none) element", function( assert ) { - assert.expect( 2 ); - - var node = jQuery( "
" ).appendTo( "#qunit-fixture" ), - result = node.offset(); - - node.remove(); - - // These tests are solely for master/compat consistency - // Retrieving offset on disconnected/hidden elements is not officially - // valid input, but will return zeros for back-compat - assert.equal( result.top, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); - assert.equal( result.left, 0, "Retrieving offset on hidden elements returns zeros (gh-2310)" ); -} ); - testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) { assert.expect( 4 );