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

Ticket #5515 (closed defect: untested)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Position.cumulativeOffset breaks under IE when using dynamically-inserted (Ajax) content

Reported by: nate.abele@gmail.com Assigned to: sam
Priority: normal Milestone:
Component: Prototype Version:
Severity: normal Keywords: Position cumulativeOffset
Cc:

Description

It appears that IE has issues (what else is new?) traversing the DOM when dynamically-inserted elements are involved. Specifically, these are the steps which are taken in the example below:

  1. New month view is loaded and inserted via Ajax.Updater
  2. Loaded in the preceeding Ajax call is a JSON object containing event data
  3. Using the script.ac Builder object, the calendar events are built and inserted, based on the data in the JSON object
  4. When an event is dragged, IE throws an error when Position.cumulativeOffset (as used by script.ac Draggables) attempts to move up the DOM tree starting from the element being dragged.

Replicating the issue:
Go to http://pamplona.isaka.net/calendar/calendar/index/2006/07/0/buggy in IE6
Click "< Prev" to page to the previous month (June), then try to drag an event

You can observe the patched version at http://pamplona.isaka.net/calendar/
The diff is against the full Prototype file, rather than the individual component in question, I hope that's okay.

Patch:

@@ -1805,9 +1805,11 @@
   cumulativeOffset: function(element) {
     var valueT = 0, valueL = 0;
     do {
-      valueT += element.offsetTop  || 0;
-      valueL += element.offsetLeft || 0;
-      element = element.offsetParent;
+        valueT += element.offsetTop  || 0;
+        valueL += element.offsetLeft || 0;
+        if (typeof element.offsetParent == 'undefined' || typeof element.offsetParent == 'unknown')
+          break;
+        element = element.offsetParent;
     } while (element);
     return [valueL, valueT];
   },

Change History

09/03/06 21:01:18 changed by madrobby

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

This one screams for a nice unit test. :)