#1093 ✓duplicate
heeae

Prototypejs 1.6.X getDimensions Problem

Reported by heeae | July 8th, 2010 @ 04:34 AM

The following segment is from prototypejs 1.6.X (1.7 are using Layout and not tested yet).

element = $(element);
var display = element.getStyle('display');
if (display != 'none' && display != null) // Safari bug
  return {width: element.offsetWidth, height: element.offsetHeight};

// All *Width and *Height properties give 0 on elements with display none,
// so enable the element temporarily
var els = element.style;
var originalVisibility = els.visibility;
var originalPosition = els.position;
var originalDisplay = els.display;
els.visibility = 'hidden';
els.position = 'absolute';
els.display = 'block';
var originalWidth = element.clientWidth;
var originalHeight = element.clientHeight;
els.display = originalDisplay;
els.position = originalPosition;
els.visibility = originalVisibility;
return {width: originalWidth, height: originalHeight};

The code are talking about if the item is not visible, then make it display.
However, this will calculated wrong
if the element does not defined width (i.e. its parent elements control the width)
setting it to absolute will cause the element expands by the text content

e.g.

this is a very very very very very very very very very very very very very very very very long string.



this is a very very very very very very very very very very very very very very very very long string.

======= you will see 2 different values

possible solution:
1. defines width
2. Find parent width
3. not settings it as absolute first, then get width, and then set absolute and width, get height again

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

Attachments

Tags

Pages