Skip to content

Offset: fix wrong origin value #334

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

Merged
merged 1 commit into from
Apr 10, 2020

Conversation

panlina
Copy link
Contributor

@panlina panlina commented Apr 2, 2020

Fixes #330 .

offset should return undefined instead of {top:0,left:0} for non DOM element.

offset should return undefined instead of {top:0,left:0} for non DOM element.
@jsf-clabot
Copy link

jsf-clabot commented Apr 2, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@mgol mgol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@panlina
Copy link
Contributor Author

panlina commented Apr 4, 2020

When will this be merged?

@mgol
Copy link
Member

mgol commented Apr 4, 2020

I'd like @dmethvin to do a review as well but I'd like to get it in a Migrate 3.2.0 release that is likely to be available within a week or two.

Copy link
Member

@dmethvin dmethvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to return the bogus for things without a nodeType, but otherwise good.


if ( !elem || !elem.nodeType ) {
migrateWarn( "jQuery.fn.offset() requires a valid DOM element" );
return origin;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only want to return undefined for the !elem case. Some code including older older versions of jQuery UI would pass window and expect the top/left of 0. jquery/jquery#3249

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it expect {left:0,top:0} for window? Why both 1.12.4 and 2.2.4 return undefined as I tested?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sure does, thanks for catching that! I don't have time to look at it right now but I must have been thinking of some other edge case with .offset()? Looks like that ticket is specifically about calling a method on window, not returning the bogus value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmethvin Since the issue was about a breaking change in jQuery 3.0.0, it seems we shouldn't care about it here as Migrate 3.x is meant to aid with upgrading to the future jQuery 4.0. Am I missing anything?

Copy link
Member

@dmethvin dmethvin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dmethvin dmethvin merged commit da094d8 into jquery:master Apr 10, 2020
@mgol mgol added this to the 3.2.0 milestone Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why offset is restored to return { left: 0, top: 0} in 3.1.0?
4 participants