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

Ticket #6686 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Make Element.getStyle work with camelized string parameter

Reported by: Tobie Assigned to: sam
Priority: normal Milestone: 1.2
Component: Prototype Version: edge
Severity: normal Keywords: camelize getcomputedstyle getstyle
Cc: mislav

Description

See my blog entry here.

getPropertyValue wants a standard CSS style string (not a camelized) one. So non inline styles will not be properly returned if a camelized string is passed to Element.getStyle.

This corrects the problem.

Tests added.

Attachments

getStyle.diff (1.9 kB) - added by Tobie on 11/23/06 05:35:42.
js + tests

Change History

11/23/06 05:34:37 changed by Tobie

Sorry for the typos and unclear statements above.

Here it an better expanation:

Element.geStyle relies on getPropertyValueto return styles that have been set via a stylesheet.

Unfortunately getPropertyValuedoes not accept camelized strings.

Therefore the following will yield an incorrect result:

$(element).getStyle('fontSize');

Idealy, Element.getStyle should be able to handle both camelized and non-camelized string.

As per W3C DOM CSS:

"The CSS2Properties interface represents a convenience mechanism for retrieving and setting properties within a CSSStyleDeclaration. Getting an attribute of this interface is equivalent to calling the getPropertyValue method of the CSSStyleDeclaration interface".

Thus the following are equivalent:

css.getPropertyValue(style)
css[style.camelize()]

As we already have a camelized version of the style, it is faster to use the second method rather than to do:

css.getPropertyValue(style.underscore().dasherize())

It has been tested and works in Opera 9, Safari 2 & Firefox 1.5

11/23/06 05:35:42 changed by Tobie

  • attachment getStyle.diff added.

js + tests

11/26/06 21:05:34 changed by madrobby

  • type changed from defect to enhancement.
  • summary changed from [PATCH] BUG Element.getStyle doesn't return a correct value if a camelized string is passed to [PATCH] Make Element.getStyle work with camelized string parameter.

11/27/06 15:57:52 changed by mislav

  • cc set to mislav.

Good work Tobie!

Now I'll try to be smart about this in #6696, too.

12/01/06 14:16:45 changed by madrobby

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

(In [5659]) Prototype: make Element.getStyle() work with camelCased argument, fixes #6686 [Tobie]