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 d4dd548aca
.
This commit is contained in:
parent
89228b9476
commit
c43ea04c54
@ -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() {
|
||||
|
@ -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 );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user