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

Ticket #5695 (closed defect: duplicate)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Element.getStyle() incorrectly returns the empty string for inherited properties that were specified in their camelized form

Reported by: eden.li@gmail.com Assigned to: sam
Priority: normal Milestone:
Component: Prototype Version:
Severity: normal Keywords:
Cc:

Description

Element.getStyle() uses getPropertyValue() which works for most style properties, but returns for specific margin and padding properties. (Left, Top, Right, Bottom).

These properties are available from the computed style object if you use the [] operator. This patch tries the [] operator on the style property if getPropertyValue returned nothing.

I've tested this on Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5.

This diff is against Prototype v1.5.0_rc0 as downloaded from here:"http://script.aculo.us/dist/scriptaculous-js-1.6.1.tar.bz2"

Index: prototype.js
===================================================================
--- prototype.js        (revision 78)
+++ prototype.js        (working copy)
@@ -1024,6 +1024,7 @@
       if (document.defaultView && document.defaultView.getComputedStyle) {
         var css = document.defaultView.getComputedStyle(element, null);
         value = css ? css.getPropertyValue(style) : null;
+        value = css && !value ? css[style] : null;
       } else if (element.currentStyle) {
         value = element.currentStyle[style.camelize()];
       }

Attachments

domElementGetStyle.diff (4.3 kB) - added by eden on 10/15/06 09:04:10.
Patch for Element.getStyle against r5304.

Change History

08/03/06 14:53:57 changed by eden.li@gmail.com

Er. that should be '' for what getPropertyValue() returns.

09/03/06 20:42:13 changed by madrobby

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

09/04/06 03:02:18 changed by eden.li@gmail.com

  • status changed from closed to reopened.
  • resolution deleted.

Can you enlighten me on how to test this? The bug still exists and I depend on these property values in my app. I don't want to keep having to re-apply my patch on every new prototype build that comes out.

09/04/06 21:52:41 changed by madrobby

  • status changed from reopened to closed.
  • resolution set to untested.

Please refer to the unit tests available in Prototype and script.aculo.us (we know the coverage is not complete yet, you want t o extend test/unit/dom.html in Prototype). You can auto-build Prototype and auto-run the tests by having Ruby and Rake installed. By doing a

rake

in the prototype folder you've checked out from SVN, a prototype.js file will be put together, and by using

rake test

the unit tests will be executed for the available browsers (supported are IE, Firefox, Safari and Konqueror).

You can also manually run unit tests by just opening the .html file in a browser (given that you first run the rake command so you get a prototype.js file). You can find more information on unit testing on the script.aculo.us wiki (more documentation should be forthcoming, but I can't name a date yet).

10/15/06 09:04:10 changed by eden

  • attachment domElementGetStyle.diff added.

Patch for Element.getStyle against r5304.

10/15/06 09:05:56 changed by eden

  • status changed from closed to reopened.
  • resolution deleted.
  • severity changed from minor to normal.

It turns out there's an even deeper issue. Element.getStyle() will return the empty string for inherited properties that were specified in their camelized form.

getPropertyValue() (which getStyle() uses) requires properties to be specified in their uncamelized forms, it'll return the empty string otherwise (see the DOM standard). So, if you pass in the non-camelized version to getStyle, you'll get the proper computed value, but if you pass in the camelized form, you'll get the empty string back.

The attached patch fixes this. The associated unit tests have been verified to pass in Firefox 1.5 and Opera 9.

10/15/06 09:07:15 changed by eden

  • summary changed from [PATCH] Element.getStyle() returns nothing for padding{Left,Top,Right,Bottom} and margin{Left,Top,Right,Bottom} in Firefox to [PATCH] Element.getStyle() incorrectly returns the empty string for inherited properties that were specified in their camelized form.

11/23/06 05:43:15 changed by Tobie

  • status changed from reopened to closed.
  • resolution set to duplicate.

Sorry I opened a duplicate ticket for this bug (#6686). I'm closing this as the patch I uploaded is based on a much more recent version of Prototype.