#1370 new
Roberto

Element.clonePosition top position not being calculated correctly

Reported by Roberto | August 15th, 2012 @ 02:46 AM

when an element is display:none and direct child of the body, and the source is within an hierarchy of elements that is child of the body, the setTop option does not calculate the top correctly. by changing the code to this it will:

function clonePosition(element, source, options) {
options = Object.extend({
  setLeft:    true,
  setTop:     true,
  setWidth:   true,
  setHeight:  true,
  offsetTop:  0,
  offsetLeft: 0
}, options || {});

source  = $(source);
element = $(element);
var p, delta, layout, styles = {};

if (options.setLeft || options.setTop) {
  p = Element.viewportOffset(source);
  delta = [0, 0];
  if (Element.getStyle(element, 'position') === 'absolute') {
    var parent = Element.getOffsetParent(element);
    //if (parent !== document.body) 
    delta = Element.viewportOffset(parent);
  }
}

console.log(delta, Element.viewportOffset(parent));

if (options.setWidth || options.setHeight) {
  layout = Element.getLayout(source);
}

if (options.setLeft)
  styles.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
if (options.setTop)
  styles.top  = (p[1] - delta[1] + options.offsetTop)  + 'px';

if (options.setWidth)
  styles.width  = layout.get('border-box-width')  + 'px';
if (options.setHeight)
  styles.height = layout.get('border-box-height') + 'px';

return Element.setStyle(element, styles);

}

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

People watching this ticket

Pages