Skip to content

Commit d457b7e

Browse files
Add documentation for dom.js.
1 parent ce3d1ab commit d457b7e

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/prototype/dom/dom.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,8 +2813,12 @@
28132813
*
28142814
* ##### Notes
28152815
*
2816-
* Internet Explorer returns literal values while other browsers return
2817-
* computed values.
2816+
* Not all CSS shorthand properties are supported. You may only use the CSS
2817+
* properties described in the
2818+
* [Document Object Model (DOM) Level 2 Style Specification](http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineStyle).
2819+
*
2820+
* Old versions of Internet Explorer return _literal_ values; other browsers
2821+
* return _computed_ values.
28182822
*
28192823
* Consider the following HTML snippet:
28202824
*
@@ -2833,12 +2837,33 @@
28332837
* // -> '1em' in Internet Explorer,
28342838
* // -> '12px' elsewhere.
28352839
*
2840+
*
28362841
* Safari returns `null` for *any* non-inline property if the element is
28372842
* hidden (has `display` set to `'none'`).
2843+
*
2844+
* ##### Caveats
2845+
*
2846+
* Early versions of Prototype attempted to "fix" this behavior for
2847+
* certain properties. A few examples:
2848+
*
2849+
* 1. Reading and writing the CSS `opacity` property works exactly like
2850+
* calling [[Element.getOpacity]] and [[Element.setOpacity]]
2851+
* respectively. This lets us pretend that IE didn't have a
2852+
* properietary way to set opacity in versions 6-7.
2853+
* 2. Browsers disagree on how to report certain properties of hidden
2854+
* elements (i.e., `display: none`). Opera, for instance, says that a
2855+
* hidden element has a `width` of `0px`. It's an arguable point, but
2856+
* we return `null` in those cases instead (so as to agree with the
2857+
* majority behavior). **In short: if an element is hidden,
2858+
* `getStyle('width')` and `getStyle('height')` will return `null`.**
2859+
* 3. In older versions of Internet Explorer, Prototype will return a
2860+
* pixel value for `width` and `height`, even if the literal value is
2861+
* a different unit. It does this by treating `width` like `offsetWidth`
2862+
* and `height` like `offsetHeight`. This is often the incorrect
2863+
* measurement, but it's a mistake we're stuck with for
2864+
* backward-compatibility. **If you're trying to measure an element's
2865+
* dimensions, don't use `getStyle`; use [[Element.measure]] instead.**
28382866
*
2839-
* Not all CSS shorthand properties are supported. You may only use the CSS
2840-
* properties described in the
2841-
* [Document Object Model (DOM) Level 2 Style Specification](http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-ElementCSSInlineStyle).
28422867
**/
28432868
function getStyle(element, style) {
28442869
element = $(element);

0 commit comments

Comments
 (0)