To correct myself: toggle doesn't maintain an array state of visibility (this
was from another JS library I used)
I was digging deeper into how toggle works and I forgot to check this function:
visible: function(element) {
return $(element).style.display != 'none';
Which is what prototype's toggle uses to decide if an element should be hidden
or not. Technically speaking, even if style.display is not readable, "none" !=
"" thus this should return visible and attempt to hide the object.
In the case stated two emails ago, I would assume dynamicCSS.js is setting
display to some value. However that would mean that toggle would evaluate
correctly. It is not so one of two things is happening.
1) dynamicCSS.js is setting visibility and not display
or
2) Something else is going on, like dynamicCSS.js is setting some other
attribute you wouldn't expect or possibly the parent? (far fetched)
I'm not familiar with dynamicCSS.js (or whatever it is) so I can only speculate.
Either way, if you use CSS to hide an item by default, you will have to unhide
it with JS the first time to properly use toggle. I just always use
element.style.display ="dispVal" and avoid this problem. Rarely is there a
situation where a toggle function works better.
-Andrew Martinez
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Martinez,
Andrew
Sent: Thursday, May 25, 2006 2:03 PM
To: [email protected]
Subject: RE: [Rails-spinoffs] Hide content before page load
The reason for this is because if the element.style.display and
element.style.visibility are not always visible via JS calls. This means you
can not probe elements that use class names and inline styles for their default
state. After JS is used to alter the state of display, it then becomes a
readable attribute (I don't know why).
Toggle attempts to avoid this issue by not probing the object at all. Toggle
assumes that the element will be visible by default and sets style.display =
"none" as the first action. It also keeps an array of the state of all objects
toggle has touched. Since it assumes items are visible the first time, the
stored state is corrupt. Therefore, to use toggle the element must be visible
the first time it is called.
I know of no work around.
Toggle could be changed to attempt a style look up, however then toggle's
behavior will be inconsistent between JS touched and non-touched JS elements.
-Andrew Martinez
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dirk Eschler
Sent: Thursday, May 25, 2006 1:38 PM
To: [email protected]
Subject: [Rails-spinoffs] Hide content before page load
Hi,
i've been experimentating with dynamicCSS.js [1] to hide content only if
JavaScript is enabled. It works pretty well and fires before onload to avoid
the flash of visible content. Now i'm wondering if there is a Prototype way
of doing this.
[1] http://www.bobbyvandersluis.com/articles/dynamicCSS.php
My main problem is that Prototype functions like Element.toggle() do not work
on elements that were used together with the dynamically created styles.
Best Regards,
Dirk Eschler
--
Dirk Eschler <mailto:[EMAIL PROTECTED]>
http://www.krusader.org
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs