Skip to main content

Bug Tracker

Side navigation

#4136 closed bug (fixed)

Opened February 12, 2009 04:09PM UTC

Closed April 22, 2009 05:29AM UTC

Offset Bug in 1.3.1

Reported by: mike.helgeson Owned by: brandon
Priority: minor Milestone: 1.4
Component: offset Version: 1.3.1
Keywords: Cc:
Blocked by: Blocking:
Description

Passing any non-element into the offset method throws an error... I think it should instead return zero values...

$( document ).offset(); ERROR

$( window ).offset(); ERROR

Attachments (1)
  • offset_patch.js (2.6 KB) - added by mike.helgeson February 12, 2009 04:11PM UTC.
Change History (6)

Changed February 12, 2009 04:23PM UTC by john comment:1

component: dimensionsoffset

It looks like you added "|| !this[0].ownerDocument" - doesn't seem too bad.

Changed March 02, 2009 12:43PM UTC by thomasvsundert comment:2

I also experience this when trying to call position() (which invokes offset()) on an element within an IFrame. Please include the fix in the next version!

Changed March 02, 2009 01:25PM UTC by thomasvsundert comment:3

Ok forget I said that, it's not true that the error occurs when it's called on elements within an IFrame. My error occured because I was trying to call $(undefined).position() and $(undefined) seems to return the HTML document, which then triggers the error.

Changed March 17, 2009 08:51PM UTC by brandon comment:4

milestone: 1.3.21.3.3
resolution: → invalid
status: newclosed

You can't run offset on window and when you run offset with no matched elements it should return null as it does now in SVN Trunk. This matches the behavior of other methods that return a result based on the first matched element (like .width()).

Changed April 16, 2009 08:32PM UTC by mike.helgeson comment:5

resolution: invalid
status: closedreopened

This function should return null. The issue is that is not happening in certain cases. Instead a javascript exception is thrown from:

$(window).offset() or $(document).offset()
TypeError: elem.ownerDocument is null

Maybe this is incorrect usage, but I feel like these calls should also return null, and not throw an error. Document and window are valid jquery object members, and don't cause errors in any other methods. Specifically, I have encountered this in my "drag" special event, I need to calculate the offset position... but I do not know if the event scope is going to be "document" or "window" and potentially break the code. I can test for document or window, but would rather have the "offset" and "position" methods test for "ownerDocument" The fix is quite simple...

Change:

if ( !elem ) return null;

To:

if ( !elem || !elem.ownerDocument ) return null;

Changed April 22, 2009 05:29AM UTC by brandon comment:6

resolution: → fixed
status: reopenedclosed

fixed in r6319