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";
|
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" ) &&
|
||||||
@ -89,7 +89,8 @@ jQuery.fn.extend( {
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
var docElem, win, rect,
|
var docElem, win,
|
||||||
|
box = { top: 0, left: 0 },
|
||||||
elem = this[ 0 ],
|
elem = this[ 0 ],
|
||||||
doc = elem && elem.ownerDocument;
|
doc = elem && elem.ownerDocument;
|
||||||
|
|
||||||
@ -97,33 +98,19 @@ jQuery.fn.extend( {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
doc = elem.ownerDocument;
|
|
||||||
docElem = doc.documentElement;
|
docElem = doc.documentElement;
|
||||||
|
|
||||||
// Support: IE<=11+
|
// Make sure it's not a disconnected DOM node
|
||||||
// Running getBoundingClientRect on a
|
|
||||||
// disconnected node in IE throws an error
|
|
||||||
// Support: IE8 only
|
|
||||||
// getClientRects() errors on disconnected elems
|
|
||||||
if ( !jQuery.contains( docElem, elem ) ) {
|
if ( !jQuery.contains( docElem, elem ) ) {
|
||||||
return { top: 0, left: 0 };
|
return box;
|
||||||
}
|
}
|
||||||
|
|
||||||
rect = elem.getBoundingClientRect();
|
box = elem.getBoundingClientRect();
|
||||||
|
win = getWindow( doc );
|
||||||
if ( rect.width || rect.height || elem.getClientRects().length ) {
|
return {
|
||||||
win = getWindow( doc );
|
top: box.top + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
|
||||||
|
left: box.left + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
|
||||||
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;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
position: function() {
|
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)" );
|
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 ) {
|
testIframe( "offset/absolute", "absolute", function( $, iframe, document, assert ) {
|
||||||
assert.expect( 4 );
|
assert.expect( 4 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user