I''m trying to incorporate a "Show/Hide" link on a page that uses Scriptaculous elements (i.e. Effect.toggle). Initially, the the link says: "Show more" to show more text that''s hidden. How can I make it such that when the user clicks on that "Show More" link, it transforms to a "Hide Text" link? I noticed this article by 37signals is close to two years old: http://www.37signals.com/svn/archives2/implementing_stateful_links.php, so I don''t know if there''s a more efficient way to do it. Any ideas? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld
2007-Aug-19 10:38 UTC
Re: Transforming "Show" Link to "Hide" Link When Clicked
<script type="text/javascript"> function toggle_views(id, second_id, display_mode) { if ($(id).style.display!=''none'') { \\ if sends here if the $id element is shown on page $(id).style.display=''none''; $(second_id).style.display=display_mode; } else { \\ else sends here if the $id element is hidden $(id).style.display=display_mode; $(second_id).style.display=''none''; }} </script> and then just call this function for your two elements (one hidden, one shown); <%= link_to ''open'', {url}, :id => "turtle", :onclick=> ''toogle_views(''turtle'', ''bird'', ''block'')'' %> <%= link_to ''close'', {url}, :id => "bird", :style =>''display:none;'' %> ...this could fit your needs i suppose, but if u want a cleaner way, i''m sure it will come down the thread by the other suitable people on board: -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Hoehne
2007-Aug-19 14:07 UTC
Re: Transforming "Show" Link to "Hide" Link When Clicked
The easiest way is to make sure you can get to the link element. The easiest way to do this is through and id, however, you can also have an id on a parent element and then do a "down" from there to the link. Once you have the link in hand you can replace the inner html. On Aug 19, 2007, at 5:27 AM, Bob Sanders wrote:> > I''m trying to incorporate a "Show/Hide" link on a page that uses > Scriptaculous elements (i.e. Effect.toggle). Initially, the the link > says: "Show more" to show more text that''s hidden. > > How can I make it such that when the user clicks on that "Show More" > link, it transforms to a "Hide Text" link? > > I noticed this article by 37signals is close to two years old: > http://www.37signals.com/svn/archives2/ > implementing_stateful_links.php, > so I don''t know if there''s a more efficient way to do it. > > Any ideas? > -- > Posted via http://www.ruby-forum.com/. > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Sanders
2007-Aug-19 21:12 UTC
Re: Transforming "Show" Link to "Hide" Link When Clicked
Shai Rosenfeld wrote:> <script type="text/javascript"> > function toggle_views(id, second_id, display_mode) { > if ($(id).style.display!=''none'') { > \\ if sends here if the $id element is shown on page > $(id).style.display=''none''; > $(second_id).style.display=display_mode; > } else { > \\ else sends here if the $id element is hidden > $(id).style.display=display_mode; > $(second_id).style.display=''none''; > }} > </script> > > and then just call this function for your two elements (one hidden, one > shown); > > <%= link_to ''open'', {url}, :id => "turtle", :onclick=> > ''toogle_views(''turtle'', ''bird'', ''block'')'' %> > <%= link_to ''close'', {url}, :id => "bird", :style =>''display:none;'' %> > > ...this could fit your needs i suppose, but if u want a cleaner way, i''m > sure it will come down the thread by the other suitable people on board:Hi Shai, Thank you so much for that. I tried this, but I can''t seem to figure out what I''m doing wrong: <script type="text/javascript"> function toggle_views(id, second_id, display_mode) { if ($(id).style.display!=''none'') { $(id).style.display=''none''; $(second_id).style.display=display_mode; } else { $(id).style.display=display_mode; $(second_id).style.display=''none''; }} </script> <a href="#" id="turtle" onclick="toogle_views(''turtle'', ''bird'', ''block'')">Edit</a> <a href="#" id="bird" style="display:none">Close</a> ========== When I click on the link, it remains there without toggling. Do you know where I''m going wrong? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shai Rosenfeld
2007-Aug-20 12:26 UTC
Re: Transforming "Show" Link to "Hide" Link When Clicked
Bob Sanders wrote:> Shai Rosenfeld wrote: >> <script type="text/javascript"> >> function toggle_views(id, second_id, display_mode) { >> if ($(id).style.display!=''none'') { >> \\ if sends here if the $id element is shown on page >> $(id).style.display=''none''; >> $(second_id).style.display=display_mode; >> } else { >> \\ else sends here if the $id element is hidden >> $(id).style.display=display_mode; >> $(second_id).style.display=''none''; >> }} >> </script> >> >> and then just call this function for your two elements (one hidden, one >> shown); >> >> <%= link_to ''open'', {url}, :id => "turtle", :onclick=> >> ''toogle_views(''turtle'', ''bird'', ''block'')'' %> >> <%= link_to ''close'', {url}, :id => "bird", :style =>''display:none;'' %> >> >> ...this could fit your needs i suppose, but if u want a cleaner way, i''m >> sure it will come down the thread by the other suitable people on board: > > Hi Shai, > > Thank you so much for that. I tried this, but I can''t seem to figure out > what I''m doing wrong: > > <script type="text/javascript"> > function toggle_views(id, second_id, display_mode) { > if ($(id).style.display!=''none'') { > $(id).style.display=''none''; > $(second_id).style.display=display_mode; > } else { > $(id).style.display=display_mode; > $(second_id).style.display=''none''; > }} > </script> > > <a href="#" id="turtle" onclick="toogle_views(''turtle'', ''bird'', > ''block'')">Edit</a> > <a href="#" id="bird" style="display:none">Close</a> > > ==========> > When I click on the link, it remains there without toggling. Do you know > where I''m going wrong?yea: the function $(id) is a short notation for a function that is in the prototype js library - it''s short for getElementByID so either replace the $(id) with getEle... or add a <%= javascript_include_tag :defaults %> to the <head> of the page (which will add the prototype library to your page, along with the $(id) func.) ...good luck :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ashley Thomas
2007-Aug-20 12:34 UTC
Re: Transforming "Show" Link to "Hide" Link When Clicked
Also, ''toogle'' should be ''toggle'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bob Sanders
2007-Aug-21 00:50 UTC
Re: Transforming "Show" Link to "Hide" Link When Clicked
Shai, thank you so much for the clarification! Ashley, thanks for the note! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---