Drag and Drop to ‘fixed’ position droppable

Edit: Modified to work with IE 7.

In Rails 2.1 (Prototype 1.6.0.1) we found an error when we created a fixed position Droppable region on a page that could scroll. In order to get around the problem we modified the prototype.js library’s cumulativeOffset at line 1988 to be:

cumulativeOffset: function(element) {
   var valueT = 0, valueL = 0;
   do {
     if(Element.getStyle(element, 'position') == 'fixed')
          {
              Position.prepare();
              valueT += Position.deltaY + element.offsetTop;
              valueL += Position.deltaX + element.offsetLeft;
              element = null;
          } else {
         valueT += element.offsetTop || 0;
         valueL += element.offsetLeft || 0;
         element = element.offsetParent;
     }
   } while (element);
   return [valueL, valueT];
   }




This seems to have fixed the problem for when the user scrolls, though we haven’t had a chance yet to exhaustively test this in the other browsers. The closest thing we could find was at http://dev.rubyonrails.org/ticket/6411#comment:2 but ultimately didn’t work as written for us.



I would love for someone more familiar with Prototype to explain the ramifications of this change.

4 Responses to “Drag and Drop to ‘fixed’ position droppable”

  1. Andy Says:

    Thanks, this worked great!

  2. lacho Says:

    Tested it in FF2 and works great, but not in IE7 and Chrome.

  3. Chris Chandler Says:

    I modified the example to work with IE 7. We encountered the same problem after cross-browser testing. The major difference is the call to Position.prepare()

  4. Guillaume Says:

    Thanks for the fix. Have you submitted it yet to the prototype team?

    Cheers