I am using the following code in an external Javascript file and it operates as it should with the specific exception that once the function does it work all of the changes are undone which really defeats the purpose of doing it in the first place. Can someone enlighten me as to why is seems to reverse the transaction after it runs. Thank you for your time. =) function ToggleViewMenu () /* Add the classes to the navView-Container and Content-Container elements to Hide or Unhide the View navigation */ { var eleViewNav = $(''navView-Container''); var Content = $(''Content-Container''); if ( eleViewNav.visible ) { eleViewNav.addClassName("Hide" ) Content.addClassName("HideView" ) $(''Hide'').firstChild.firstChild.nodeValue = "Unhide"; alert ("Hiding"); } else { eleViewNav.removeClassName("Hide"); Content.removeClassName("HideView" ) $(''Hide'').firstChild.firstChild.nodeValue = "Hide"; } return false; } function WindowLoad () /* Load all of the Javascript Event Observers when the ''window'' object loads */ { Event.observe( ''Hide'', ''click'', ToggleViewMenu) } /* Load all Event Observers after the Window has loaded */ Event.observe( window, ''load'', WindowLoad ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
BTW - after clicking on ''OK'' (which is only there just so I can see the result of the function''s operation) everything seems to get reversed. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
... if ( eleViewNav.visible() ) ... also: $(''Hide'').down().update("Hide"); // <= is whitespace-proof (comparing to firstChild) - kangax On Mar 12, 3:14 pm, FreeXenon <freexe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am using the following code in an external Javascript file and it > operates as it should with the specific exception that once the > function does it work all of the changes are undone which really > defeats the purpose of doing it in the first place. > > Can someone enlighten me as to why is seems to reverse the transaction > after it runs. > > Thank you for your time. =) > > function ToggleViewMenu () > /* Add the classes to the navView-Container and Content-Container > elements > to Hide or Unhide the View navigation */ > { > var eleViewNav = $(''navView-Container''); > var Content = $(''Content-Container''); > > if ( eleViewNav.visible ) > { > eleViewNav.addClassName("Hide" ) > Content.addClassName("HideView" ) > > $(''Hide'').firstChild.firstChild.nodeValue = "Unhide"; > > alert ("Hiding"); > } > > else > { > eleViewNav.removeClassName("Hide"); > Content.removeClassName("HideView" ) > > $(''Hide'').firstChild.firstChild.nodeValue = "Hide"; > } > > return false; > } > > function WindowLoad () > /* Load all of the Javascript Event Observers when the ''window'' > object loads */ > { > Event.observe( ''Hide'', ''click'', ToggleViewMenu) > } > > /* Load all Event Observers after the Window has loaded */ > Event.observe( window, ''load'', WindowLoad )--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
OK, I made those changes. Thanks for the tips. I am a little new working with Prototype. It still does the same thing. The Event fires when it should and runs the function as it should, but right after it finishes, the browser (FF 2.0.012 on WinXP SP2) seems to process something a little bit and then the changes are reversed - as if there were a transaction being reversed or something like that. The page validates XHTML 1.0 Strict. function ToggleViewMenu () /* Add the classes to the navView-Container and Content-Container elements to Hide or Unhide the View navigation */ { var eleViewNav = $(''navView-Container''); var Content = $(''Content-Container''); if ( eleViewNav.visible() ) { eleViewNav.addClassName("Hide" ) Content.addClassName("HideView" ) $(''Hide'').down().update("Unhide"); alert ("Hiding"); } else { eleViewNav.removeClassName("Hide"); Content.removeClassName("HideView" ) $(''Hide'').down().update("Hide") } return false; } function WindowLoad () /* Load all of the Javascript Event Observers when the ''window'' object loads */ { Event.observe( ''Hide'', ''click'', ToggleViewMenu) } /* Load all Event Observers after the Window has loaded */ Event.observe( window, ''load'', WindowLoad ) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Wed, Mar 12, 2008 at 3:13 PM, FreeXenon <freexenon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > It still does the same thing. The Event fires when it should and runs > the function as it should, but right after it finishes, the browser > (FF 2.0.012 on WinXP SP2) seems to process something a little bit and > then the changes are reversed - as if there were a transaction being > reversed or something like that. The page validates XHTML 1.0 Strict.The "transaction reversal" effect is probably just the page being reloaded, because the "return false" statement doesn''t really work in Prototype event handlers. Instead, you need to call the stop method on the event object, which is automatically passed to every event-handling function. You''ll need to rewrite your code like so: function ToggleViewMenu(event) { // the rest of the function goes here event.stop(); // instead of return false! } :Dan Dorman --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Holy Crap! I never considered that the page reloaded because the link did not go anywhere. I added : ''javascript: return false'' to the link and that stopped the reload and adjusted the detection for the if statement and it works right. I will keep in mind the Event. stop thing. Thanks a lot guys. =) On Mar 12, 4:30 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Wed, Mar 12, 2008 at 3:13 PM, FreeXenon <freexe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > The "transaction reversal" effect is probably just the page being > reloaded, because the "return false" statement doesn''t really work in > Prototype event handlers. Instead, you need to call the stop method on > the event object, which is automatically passed to every > event-handling function. > > You''ll need to rewrite your code like so: > > function ToggleViewMenu(event) > { > // the rest of the function goes here > event.stop(); // instead of return false!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Unrelated, but... You''re relying intermittently on JavaScript semicolon insertion. For example: if ( eleViewNav.visible() ) { eleViewNav.addClassName("Hide" ) // <=== Here Content.addClassName("HideView" ) // <=== And here (and why the additional indentation?) $(''Hide'').firstChild.firstChild.nodeValue = "Unhide"; alert ("Hiding"); } I''ll make you a promise that if you''re reliable about terminating your statements yourself rather than relying on automatic insertion, you WILL save yourself debugging time down-the-line. Don''t rely on semicolon insertion, it will come back to bite you. Also, if you rely on semicolon insertion, you can''t use some minifying tools, so Just Saying No is a good idea pretty much any way you slice it. FWIW... -- T.J. Crowder tj / crowder software / com On Mar 12, 10:12 pm, FreeXenon <freexe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Holy Crap! I never considered that the page reloaded because the link > did not go anywhere. > I added : ''javascript: return false'' to the link and that stopped the > reload and adjusted the detection for the if statement and it works > right. > > I will keep in mind the Event. stop thing. > > Thanks a lot guys. > > =) > > On Mar 12, 4:30 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Wed, Mar 12, 2008 at 3:13 PM, FreeXenon <freexe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > The "transaction reversal" effect is probably just the page being > > reloaded, because the "return false" statement doesn''t really work in > > Prototype event handlers. Instead, you need to call the stop method on > > the event object, which is automatically passed to every > > event-handling function. > > > You''ll need to rewrite your code like so: > > > function ToggleViewMenu(event) > > { > > // the rest of the function goes here > > event.stop(); // instead of return false!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---