Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11473 (new defect)

Opened 2 months ago

Last modified 1 month ago

[PATCH][TEST] Element#getOffsetParent and Element#viewportOffset IE error.

Reported by: jdalton Assigned to: jdalton
Priority: high Milestone: 2.x
Component: Prototype Version: edge
Severity: major Keywords: 1.6.0.3
Cc:

Description

Sometimes IE will wrongly assert that an elements offsetParent is "document".
In these cases we use "document.body" instead.

More info here: http://dev.rubyonrails.org/ticket/11007

Attachments

ie_offsetParent_fix.diff (1 bytes) - added by jdalton on 04/03/08 07:30:18.
deleted.
viewportOffset_fix.diff (1 bytes) - added by jdalton on 04/03/08 07:30:46.
deleted
unit_tests.diff (1.2 kB) - added by jdalton on 04/03/08 12:59:16.
tests for the offsetParent bug
getOffsetParent_viewportOffset_fix.diff (1.7 kB) - added by jdalton on 04/04/08 04:04:15.
fixed element#getOffsetParent() and element#viewportOffset passes unit tests

Change History

04/01/08 18:30:11 changed by jdalton

  • summary changed from [PATCH] Element.getOffsetParent() IE error. to [PATCH] Element#getOffsetParent and Element#viewportOffset IE error..

04/01/08 18:38:48 changed by jdalton

Please test...

04/02/08 07:36:59 changed by AndrewRev

  • owner changed from sam to jdalton.

Element#viewportOffset PATCH isn't all too well (ref: http://dev.rubyonrails.org/attachment/ticket/11473/viewportOffset_fix.diff)

In fact, new line #594 of that patch anyways sets element to be equal to its element.offsetParent, which we know can be document.documentElement.
Thus in a next pass of the loop, at line #591 (new), the call to element.getOffsetParent() will raise an error: Method or property is missing.
Because this object isn't an extended DOM element (and it shouldn't be)

04/02/08 07:48:45 changed by jdalton

Wrong :).
The patched getOffsetParent() which the viewportOffset patch is to be used with will not return document.documentElement, but document.body.

The patch is fine.

The element = $(element) issue is addressed in this path: http://dev.rubyonrails.org/ticket/11472[[BR]]

I did not overlap patches to make it easier on the devs.

04/02/08 12:09:44 changed by jdalton

04/02/08 14:48:31 changed by jdalton

  • keywords set to 1.6.0.3.

04/03/08 06:05:28 changed by AndrewRev

I'm sorry, jdalton (don't know your name, pardon).

Error occurs on
if (element.getOffsetParent() == document.body &&
line on a a presumably second iteration cycle because element has been previously assigned to by an unsafe assignment in a ending loop statement:
while (element = element.offsetParent); //regular .offsetParent can be null
And thus, in 'if' condition, first time, the 'element' is extended, yes. Yet, the second time it can become a) unextended and b) document.documentElement.
See, in the 'while assignment' line element.offsetParent can be document.documentElement,
and the assignment is done without any checking. (As also stated in a following comment: "regular .offsetParent can be null").
I don't understand why you haven't introduced safe assignment in that line. It seems that that done would fix things.

My data is purely empirical. )

04/03/08 06:15:13 changed by AndrewRev

I would recommend the following snippet to replace the current:

var pendingOffset;
do {
	valueT += element.offsetTop	|| 0;
	valueL += element.offsetLeft || 0;

	// Safari fix
	if ((pendingOffset = element.getOffsetParent()) == document.body &&
		Element.getStyle(element, 'position') == 'absolute')) break;

} while (element = pendingOffset);

(follow-up: ↓ 10 ) 04/03/08 06:25:44 changed by AndrewRev

CORRECTION: Oops, the if statement has doubled parenthesis. Correct version goes like this:

if ((pendingOffset = element.getOffsetParent()) == document.body &&
	Element.getStyle(element, 'position') == 'absolute') break;

(in reply to: ↑ 9 ) 04/03/08 06:48:46 changed by AndrewRev

CORR.2 (using logical OR):

if ((pendingOffset = element.getOffsetParent()) == document.body ||
	Element.getStyle(element, 'position') == 'absolute') break;

04/03/08 07:00:41 changed by jdalton

AndrewRev you are right :)
I had tested the getOffsetParent() patch but had eye balled the viewportOffset() patch.
I will correct it soon.

04/03/08 07:30:18 changed by jdalton

  • attachment ie_offsetParent_fix.diff added.

deleted.

04/03/08 07:30:46 changed by jdalton

  • attachment viewportOffset_fix.diff added.

deleted

04/03/08 07:38:56 changed by jdalton

Thanx AdnrewRev,

I have combined the patches for easy comparision of what is changed.
I removed the "Safari fix" because I think it is no longer needed.
Every browser will leave the while loop if the element.getOffsetParent() == document.body
(which is the last thing it can ever be.)

04/03/08 12:59:16 changed by jdalton

  • attachment unit_tests.diff added.

tests for the offsetParent bug

04/03/08 13:00:49 changed by jdalton

  • summary changed from [PATCH] Element#getOffsetParent and Element#viewportOffset IE error. to [PATCH][TEST] Element#getOffsetParent and Element#viewportOffset IE error..

IE with strict doctype may try to return documentElement as offsetParent on relatively positioned elements. This fix correctly returns document.body instead.

04/03/08 16:32:36 changed by AndrewRev

Anytime. You're welcome!

04/04/08 04:04:15 changed by jdalton

  • attachment getOffsetParent_viewportOffset_fix.diff added.

fixed element#getOffsetParent() and element#viewportOffset passes unit tests

04/09/08 01:09:18 changed by jdalton

I believe this addresses ticket: http://dev.rubyonrails.org/ticket/11319 too

04/12/08 16:26:36 changed by jdalton

Also fixes this ticket: http://dev.rubyonrails.org/ticket/11007

04/18/08 16:23:38 changed by slusarz

I would recommend that this issue be bumped in severity because it breaks a lot of existing code. The problem (or at least the problem reported to us by several users) is that this behavior became broken only recently on IE 7 because of a recent security update - namely KB 947864:

http://www.microsoft.com/technet/security/Bulletin/MS08-024.mspx

See, e.g.:

http://bugs.horde.org/ticket/6590

If this information is true, and all installations of IE 7 are going to regress, this seems like an awfully severe issue.

04/18/08 17:44:41 changed by jdalton

  • priority changed from normal to high.
  • severity changed from normal to major.

Thank you very much for that info, the patch has been pushed to the devs so we will hopefully see it in the core before too long :)