Opened 14 years ago
Closed 14 years ago
#4136 closed bug (fixed)
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)
Change History (7)
Changed 14 years ago by
Attachment: | offset_patch.js added |
---|
comment:1 Changed 14 years ago by
Component: | dimensions → offset |
---|
!this[0].ownerDocument" - doesn't seem too bad. |
comment:2 Changed 14 years ago by
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!
comment:3 Changed 14 years ago by
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.
comment:4 Changed 14 years ago by
Milestone: | 1.3.2 → 1.3.3 |
---|---|
Resolution: | → invalid |
Status: | new → closed |
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()).
comment:5 Changed 14 years ago by
Resolution: | invalid |
---|---|
Status: | closed → reopened |
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;