Revert "Offset: Fix .offset() to correctly work with ShadowDOM"

This reverts commit d4dd548aca.
This commit is contained in:
Oleg Gaidarenko 2015-12-22 16:15:52 +03:00
parent 89228b9476
commit c43ea04c54
2 changed files with 11 additions and 39 deletions

View File

@ -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() {

View File

@ -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( "<div style='display: none' />" ).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 );