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

Ticket #7349 (closed defect: duplicate)

Opened 2 years ago

Last modified 1 year ago

Position.cumulativeOffset exception on IE

Reported by: CoolWind Assigned to: sam
Priority: normal Milestone: 2.x
Component: Prototype Version:
Severity: normal Keywords:
Cc:

Description

I found a weird problem when using Position.cumulativeOffset in Internet Explorer (tested on 6.0 and 7.0).

The function, under certain circumstances which I could not determine exactly, crashes returning an Exception (no value) if using IE. The exact point where it crashes is the line:

element.offsetParent

As I've said, doesn't return a value but an Exception, so the workaround I applied to "solve" the problem is simply adding a try/catch block like this:

  cumulativeOffset: function(element) {
    var valueT = 0, valueL = 0;
	try
	{
	  do {
	       valueT += element.offsetTop  || 0;
	       valueL += element.offsetLeft || 0;
	       element = element.offsetParent;
	      } while (element);
	    return [valueL, valueT];
	}
	catch(err)
	{
	    return [valueL, valueT];
	}
  }

and then the function _always_ works as expected.

I know I'm not giving too many details, is all I could find after some hours of testing. If you find the real problem or add this try/catch workaround in the next release I would be pleased (and as far as I know, this workaround only could help others, as the function works exactly the same).

Thank you.

Change History

02/26/07 15:49:02 changed by olleolleolle

#5515 also reports a like issue, with a similar fix. ("[PATCH] Position.cumulativeOffset breaks under IE when using dynamically-inserted (Ajax) content") It was closed, because it lacked a unit test.

This Ticket also needs a unit test, or it might suffer the same fate.

01/30/08 04:09:31 changed by kangax

  • status changed from new to closed.
  • resolution set to duplicate.

duplicate of #9416