]> source.dussan.org Git - jquery.git/commitdiff
Revert "Offset: Fix .offset() to correctly work with ShadowDOM"
authorOleg Gaidarenko <markelog@gmail.com>
Fri, 13 Nov 2015 11:59:25 +0000 (14:59 +0300)
committerOleg Gaidarenko <markelog@gmail.com>
Fri, 13 Nov 2015 11:59:25 +0000 (14:59 +0300)
This reverts commit 1617479fcf7cbdaf33dc9334ed10a0f30bf14687.

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

index 857b3a5cc5c37bff0afb22aabe622ec75afb0722..acc41997a9a752aa53a7d0b264574e3fceff4934 100644 (file)
@@ -32,7 +32,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" ) &&
@@ -77,41 +77,33 @@ jQuery.fn.extend( {
                if ( arguments.length ) {
                        return options === undefined ?
                                this :
-                               this.each( function( i ) {
+                               this.each(function( i ) {
                                        jQuery.offset.setOffset( this, options, i );
-                               } );
+                               });
                }
 
-               var docElem, win, rect,
+               var docElem, win,
                        elem = this[ 0 ],
+                       box = { top: 0, left: 0 },
                        doc = elem && elem.ownerDocument;
 
-               if ( !elem ) {
+               if ( !doc ) {
                        return;
                }
 
-               // Support: IE<=11+
-               // Running getBoundingClientRect on a
-               // disconnected node in IE throws an error
-               if ( !elem.getClientRects().length ) {
-                       return { top: 0, left: 0 };
-               }
-
-               rect = elem.getBoundingClientRect();
-
-               // Make sure element is not hidden (display: none) or disconnected
-               if ( rect.width || rect.height || elem.getClientRects().length ) {
-                       win = getWindow( doc );
-                       docElem = doc.documentElement;
+               docElem = doc.documentElement;
 
-                       return {
-                               top: rect.top + win.pageYOffset - docElem.clientTop,
-                               left: rect.left + win.pageXOffset - docElem.clientLeft
-                       };
+               // Make sure it's not a disconnected DOM node
+               if ( !jQuery.contains( docElem, elem ) ) {
+                       return box;
                }
 
-               // Return zeros for disconnected and hidden elements (gh-2310)
-               return rect;
+               box = elem.getBoundingClientRect();
+               win = getWindow( doc );
+               return {
+                       top: box.top + win.pageYOffset - docElem.clientTop,
+                       left: box.left + win.pageXOffset - docElem.clientLeft
+               };
        },
 
        position: function() {
index a4822e4a9b02a47458150f169958e7b65390c6f8..ea2c266069bf0d1b259b507138d3d27767f3a501 100644 (file)
@@ -57,7 +57,7 @@ QUnit.test( "object without getBoundingClientRect", function( assert ) {
        assert.equal( result.left, 0, "Check left" );
 });
 
-QUnit.test( "disconnected element", function( assert ) {
+QUnit.test( "disconnected node", function( assert ) {
        assert.expect( 2 );
 
        var result = jQuery( document.createElement( "div" ) ).offset();
@@ -65,8 +65,8 @@ QUnit.test( "disconnected element", function( assert ) {
        // 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 disconnected elements returns zeros (gh-2310)" );
-       assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
+       equal( result.top, 0, "Check top" );
+       equal( result.left, 0, "Check left" );
 } );
 
 QUnit.test( "hidden (display: none) element", function( assert ) {