-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Fix .offset() to work in ShadowDOM #2043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6ae0de7
a97da28
f2790eb
7e12dc8
981cc26
65d9de9
ebf43fa
d0df2c6
2e7e1b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ jQuery.offset = { | |
| elem.style.position = "relative"; | ||
| } | ||
|
|
||
| curOffset = curElem.offset(); | ||
| curOffset = curElem.offset() || { top: 0, left: 0 }; | ||
| curCSSTop = jQuery.css( elem, "top" ); | ||
| curCSSLeft = jQuery.css( elem, "left" ); | ||
| calculatePosition = ( position === "absolute" || position === "fixed" ) && | ||
|
|
@@ -82,28 +82,26 @@ jQuery.fn.extend({ | |
| }); | ||
| } | ||
|
|
||
| var docElem, win, | ||
| var docElem, win, rect, | ||
| elem = this[ 0 ], | ||
| box = { top: 0, left: 0 }, | ||
| doc = elem && elem.ownerDocument; | ||
|
|
||
| if ( !doc ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this can also go, along with the related "object without getBoundingClientRect" test, since all supported browsers have gBCR.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I got your message here. If you plan to remove that condition then you can remove it in separate thread. This PR is not about refacroting
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right; agreed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tracking in #2115.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, that test is failing with this PR. I'm going to include #2115 when landing.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timmywil I am not sure about this, but as I remember that test did not worker even before I made any changes. Anyway, it's what all is resolved now, thanks! |
||
| return; | ||
| } | ||
|
|
||
| docElem = doc.documentElement; | ||
| rect = elem.getBoundingClientRect(); | ||
|
|
||
| // Make sure it's not a disconnected DOM node | ||
| if ( !jQuery.contains( docElem, elem ) ) { | ||
| return box; | ||
| } | ||
| // Make sure element is not hidden (display: none) or disconnected | ||
| if ( rect.width || rect.height || elem.getClientRects().length ) { | ||
| win = getWindow( doc ); | ||
| docElem = doc.documentElement; | ||
|
|
||
| box = elem.getBoundingClientRect(); | ||
| win = getWindow( doc ); | ||
| return { | ||
| top: box.top + win.pageYOffset - docElem.clientTop, | ||
| left: box.left + win.pageXOffset - docElem.clientLeft | ||
| }; | ||
| return { | ||
| top: rect.top + win.pageYOffset - docElem.clientTop, | ||
| left: rect.left + win.pageXOffset - docElem.clientLeft | ||
| }; | ||
| } | ||
| }, | ||
|
|
||
| position: function() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This relates to #2043 (comment) ... do we want to suppress exceptions when setting document-relative offset on no-layout elements? I'd like some other opinions here, but personally am inclined to drop this change and let the call throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. +1 for throwing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need to mention it in the release notes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you suggest to just remove
|| { top: 0, left: 0 }or guard forcurOffsetand throw manually custom error?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per meeting, remove
|| { top: 0, left: 0 }.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, after further discussion, we'll leave as is and make this change separately. Sorry to confuse! Nothing further for you to do here @NekR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracking in #2114.