mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Revert "Offset: Fix .offset() to correctly work with ShadowDOM"
This reverts commit 1617479fcf
.
This commit is contained in:
parent
aaff6a87a1
commit
3a98c4ab27
@ -32,7 +32,7 @@ jQuery.offset = {
|
|||||||
elem.style.position = "relative";
|
elem.style.position = "relative";
|
||||||
}
|
}
|
||||||
|
|
||||||
curOffset = curElem.offset() || { top: 0, left: 0 };
|
curOffset = curElem.offset();
|
||||||
curCSSTop = jQuery.css( elem, "top" );
|
curCSSTop = jQuery.css( elem, "top" );
|
||||||
curCSSLeft = jQuery.css( elem, "left" );
|
curCSSLeft = jQuery.css( elem, "left" );
|
||||||
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
||||||
@ -82,36 +82,28 @@ jQuery.fn.extend( {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var docElem, win, rect,
|
var docElem, win,
|
||||||
elem = this[ 0 ],
|
elem = this[ 0 ],
|
||||||
|
box = { top: 0, left: 0 },
|
||||||
doc = elem && elem.ownerDocument;
|
doc = elem && elem.ownerDocument;
|
||||||
|
|
||||||
if ( !elem ) {
|
if ( !doc ) {
|
||||||
return;
|
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 {
|
// Make sure it's not a disconnected DOM node
|
||||||
top: rect.top + win.pageYOffset - docElem.clientTop,
|
if ( !jQuery.contains( docElem, elem ) ) {
|
||||||
left: rect.left + win.pageXOffset - docElem.clientLeft
|
return box;
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return zeros for disconnected and hidden elements (gh-2310)
|
box = elem.getBoundingClientRect();
|
||||||
return rect;
|
win = getWindow( doc );
|
||||||
|
return {
|
||||||
|
top: box.top + win.pageYOffset - docElem.clientTop,
|
||||||
|
left: box.left + win.pageXOffset - docElem.clientLeft
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
position: function() {
|
position: function() {
|
||||||
|
@ -57,7 +57,7 @@ QUnit.test( "object without getBoundingClientRect", function( assert ) {
|
|||||||
assert.equal( result.left, 0, "Check left" );
|
assert.equal( result.left, 0, "Check left" );
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test( "disconnected element", function( assert ) {
|
QUnit.test( "disconnected node", function( assert ) {
|
||||||
assert.expect( 2 );
|
assert.expect( 2 );
|
||||||
|
|
||||||
var result = jQuery( document.createElement( "div" ) ).offset();
|
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
|
// These tests are solely for master/compat consistency
|
||||||
// Retrieving offset on disconnected/hidden elements is not officially
|
// Retrieving offset on disconnected/hidden elements is not officially
|
||||||
// valid input, but will return zeros for back-compat
|
// valid input, but will return zeros for back-compat
|
||||||
assert.equal( result.top, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
|
equal( result.top, 0, "Check top" );
|
||||||
assert.equal( result.left, 0, "Retrieving offset on disconnected elements returns zeros (gh-2310)" );
|
equal( result.left, 0, "Check left" );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "hidden (display: none) element", function( assert ) {
|
QUnit.test( "hidden (display: none) element", function( assert ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user