On Sep 1, 2006, at 1:40 PM, Sam wrote:



As I understand it: get and set style are not symmetrical because of CSS cascaded inheritance:

"get" will return the cascaded style which starts with the HTML element property, may be overridden by the CSS directive, which may be overridden by coding style="whatever" in the HTML. getStyle will return whichever property cascaded down to dominate. It would be difficult to determine in JavaScript where the style declaration came from, but if it were known, it might solve the upcoming
problem.

OK, we've got the style but we don't know from whence it came. Now after overwriting the element "style" doing an effect, we would
like to "set" things back.  There's the problem...

Without the ability to undo the setStyle, using setStyle( {display: ''} ) is a partial solution.

Each of these 3 divs will end up with different results when an effect "restores" the display style state using setStyle( {display:
''} )

<div style="display:none">abc</div>
<div style="display:block">abc</div>
<div style="display:inline">abc</div>


Wouldn't it be possible to save the original style in a stack so the element style could be restored to it's original state?


Not sure about this but I imagine you would run into inheritance / specificity problems again if the original styles came from anywhere other than inline. Your example wouldn't have this problem, but here's one that would.

Consider an external stylesheet with a single class selector applying the display property you want (it would have a specificity of 0010). Even if Prototype stored the original state in a stack, when it set it back it would take precedence over most other styles (since JS- applied styles are equivalent to inline styles with a specificity of 1000). So you wouldn't be back to normal -- instead of having a CSS- file rule with a specificity of 0010, you have an inline rule saying the same thing with a specificity of 1000. This would take precedence over, say, an external CSS rule with an ID selector, which would have a specificity of 0100.

Bottom line: you could probably end up having different behavior before and after the restore. My guess is that that would be too leaky of an abstraction for Prototype.

--be

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to