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

Ticket #10644 (closed defect: fixed)

Opened 1 year ago

Last modified 10 months ago

positionedOffset incorrectly handles position fixed

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

Description

This affects Prototype 1.6.0

Currently the Element.positionedOffset function stops recursing when it finds a relative or absolutely positioned element. This is incorrect since it ignores the "fixed" position. Elsewhere in the code, the logic simply checks for !static which is more inclusive and also (technically) a faster check.

The easy fix, shown below is to check for !static.

Patch

positionedOffset: function(element) {
  var valueT = 0, valueL = 0;
  do {
    valueT += element.offsetTop  || 0;
    valueL += element.offsetLeft || 0;
    element = element.offsetParent;
    if (element) {
      if (element.tagName == 'BODY') break;
      var p = Element.getStyle(element, 'position');
      if (p != 'static') break;//was if (p == 'relative' || p == 'absolute') break;
    }
  } while (element);
  return Element._returnOffset(valueL, valueT);
},

Example:

<div style="position:fixed; top:100px;">
  <a onclick="alert($(this).positionedOffset())">Click Here to see the wrong offset</a>
</div>

Attachments

positionedOffset_fixed_test.diff (1.0 kB) - added by kangax on 01/25/08 21:14:13.

Change History

01/25/08 21:14:13 changed by kangax

  • attachment positionedOffset_fixed_test.diff added.

01/25/08 22:09:32 changed by kangax

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

Fixed in [8723]