Forum: Ruby on Rails Toggle

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mikael B. (Guest)
on 2008-11-03 16:52
Hi!

I'am using Effect.toggle to show/hide a div field. Is there a simple way
to also toggle the icon i am using. (+ if hidden and - if visible)

<%= link_to_function '',
        "Effect.toggle('summary_dropdown')",
        :class => 'icon-expand' %>

Thanks.
Frederick C. (Guest)
on 2008-11-03 17:03
(Received via mailing list)
On 3 Nov 2008, at 14:52, Mikael Björkegren wrote:

>
> Hi!
>
> I'am using Effect.toggle to show/hide a div field. Is there a simple
> way
> to also toggle the icon i am using. (+ if hidden and - if visible)
>
I typically do that by also toggling some css class (eg $
('something').toggleClassName('expanded'). in this case you can
probably do this.toggleClassName('some-class') )

Fred
Mikael B. (Guest)
on 2008-11-04 11:02
Thanks for the quick reply. But where am i going to put this?

> I typically do that by also toggling some css class (eg $
> ('something').toggleClassName('expanded'). in this case you can
> probably do this.toggleClassName('some-class') )
>
> Fred

<%= link_to_function '',
    "Effect.toggle('summary_dropdown')",
    :id => 'toggle',
    :class => 'icon-expand' %>

I guess it should be someting like
('toggle').toggleClassName('icon-fade')

but where will i put this in my link_to_function ?
Mikael B. (Guest)
on 2008-11-04 16:03
I can only get one off them to work at a time. Do anyone know
how to combine the two functions. So the div will fade/appear and
the icon will change from + to -.
Frederick C. (Guest)
on 2008-11-04 16:19
(Received via mailing list)
On 4 Nov 2008, at 09:02, Mikael Björkegren wrote:

>    "Effect.toggle('summary_dropdown')",
>    :id => 'toggle',
>    :class => 'icon-expand' %>
>
> I guess it should be someting like
> ('toggle').toggleClassName('icon-fade')
>
> but where will i put this in my link_to_function ?

the second argument to link_to_function is an arbitrary javascript
fragment. You can put as much in there as you want.

Fred
Phillip K. (Guest)
on 2008-11-04 16:57
Frederick C. wrote:
>
> the second argument to link_to_function is an arbitrary javascript
> fragment. You can put as much in there as you want.
>
> Fred

To give just a little more detail to what Fred said, you can do
something like

"Effect.toggle('this-thing'); Effect.toggle('that-thing');"

Just remember that needs to be proper JavaScript since it's going to be
eval'd.

Peace.
Mikael B. (Guest)
on 2008-11-04 17:59
Got it working thanks for the reply.
This topic is locked and can not be replied to.