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

This reverts commit 1617479fcf.
This commit is contained in:
Oleg Gaidarenko 2015-11-13 14:59:25 +03:00
parent aaff6a87a1
commit 3a98c4ab27
2 changed files with 20 additions and 28 deletions

View 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 };
docElem = doc.documentElement;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
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;
return {
top: rect.top + win.pageYOffset - docElem.clientTop,
left: rect.left + win.pageXOffset - docElem.clientLeft
};
}
// 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() {

View 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 ) {